Skip to content

Commit 25d4724

Browse files
committed
-Add Sound api
-Cleanup
1 parent 15be26b commit 25d4724

File tree

8 files changed

+77
-10
lines changed

8 files changed

+77
-10
lines changed

MG.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
2237E67E192B0186001E1393 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2237E67D192B0186001E1393 /* WebKit.framework */; };
1212
2237E680192B018D001E1393 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2237E67F192B018D001E1393 /* JavaScriptCore.framework */; };
1313
2237E6EF192BAF85001E1393 /* public in Resources */ = {isa = PBXBuildFile; fileRef = 2237E6EE192BAF85001E1393 /* public */; };
14+
226AE65D193AA8FC00B15FB7 /* Sound.m in Sources */ = {isa = PBXBuildFile; fileRef = 226AE65C193AA8FC00B15FB7 /* Sound.m */; };
1415
22B1CF2B1937734B00D2C294 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 22B1CEF51937734B00D2C294 /* AppDelegate.m */; };
1516
22B1CF2C1937734B00D2C294 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 22B1CEF61937734B00D2C294 /* MainMenu.xib */; };
1617
22B1CF2D1937734B00D2C294 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 22B1CEF81937734B00D2C294 /* MainWindow.xib */; };
@@ -49,6 +50,8 @@
4950
2237E67D192B0186001E1393 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
5051
2237E67F192B018D001E1393 /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
5152
2237E6EE192BAF85001E1393 /* public */ = {isa = PBXFileReference; lastKnownFileType = folder; path = public; sourceTree = "<group>"; };
53+
226AE65B193AA8FC00B15FB7 /* Sound.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Sound.h; sourceTree = "<group>"; };
54+
226AE65C193AA8FC00B15FB7 /* Sound.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Sound.m; sourceTree = "<group>"; };
5255
22B1CEF41937734B00D2C294 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
5356
22B1CEF51937734B00D2C294 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
5457
22B1CEF71937734B00D2C294 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
@@ -222,6 +225,8 @@
222225
22B1CF191937734B00D2C294 /* Task.m */,
223226
22B1CF1A1937734B00D2C294 /* Window.h */,
224227
22B1CF1B1937734B00D2C294 /* Window.m */,
228+
226AE65B193AA8FC00B15FB7 /* Sound.h */,
229+
226AE65C193AA8FC00B15FB7 /* Sound.m */,
225230
);
226231
path = Commands;
227232
sourceTree = "<group>";
@@ -331,6 +336,7 @@
331336
22B1CF2F1937734B00D2C294 /* NSData+Base64.m in Sources */,
332337
22B1CF431937734B00D2C294 /* main.m in Sources */,
333338
22B1CF321937734B00D2C294 /* Command.m in Sources */,
339+
226AE65D193AA8FC00B15FB7 /* Sound.m in Sources */,
334340
22B1CF331937734B00D2C294 /* Dialog.m in Sources */,
335341
22B1CF361937734B00D2C294 /* Fonts.m in Sources */,
336342
22B1CF2B1937734B00D2C294 /* AppDelegate.m in Sources */,

MacGap/Classes/Commands/App.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ JSExportAs(setUserAgent, - (void) setCustomUserAgent:(NSString *)userAgentString
3131

3232
@interface App : Command <AppExports>
3333

34-
@property (nonatomic, retain) WebView* webView;
3534
- (id) initWithWebView:(WebView *)view;
3635
@end

MacGap/Classes/Commands/MacGap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
#import <JavaScriptCore/JavaScriptCore.h>
11+
#import "WindowController.h"
1112
#import "WebViewDelegate.h"
1213
#import "Command.h"
1314
#import "App.h"
@@ -19,6 +20,7 @@
1920
#import "Task.h"
2021
#import "Notify.h"
2122
#import "Fonts.h"
23+
#import "StatusItem.h"
2224

2325
#import "NSData+Base64.h"
2426
#import "JSON.h"

MacGap/Classes/Commands/Sound.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// Sound.h
3+
// MG
4+
//
5+
// Created by Tim Debo on 5/31/14.
6+
//
7+
//
8+
9+
#import "Command.h"
10+
11+
@protocol SoundExports <JSExport>
12+
JSExportAs(play, - (void) play:(NSString*)file onComplete:(JSValue*)callback);
13+
JSExportAs(playSystem, - (void) playSystem:(NSString*)name onComplete:(JSValue*)callback);
14+
@property (retain) JSValue* cb;
15+
@end
16+
17+
@interface Sound : Command <SoundExports, NSSoundDelegate>
18+
19+
@end

MacGap/Classes/Commands/Sound.m

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// Sound.m
3+
// MG
4+
//
5+
// Created by Tim Debo on 5/31/14.
6+
//
7+
//
8+
9+
#import "Sound.h"
10+
@interface Sound ()
11+
@property (readwrite) JSContext* context;
12+
@end
13+
14+
@implementation Sound
15+
@synthesize cb, context;
16+
17+
- (void) playSound:(NSSound*)sound onComplete:(JSValue*)callback {
18+
if (callback && ![callback isKindOfClass:[NSNull class]]) {
19+
cb = callback;
20+
context = [JSContext currentContext];
21+
[sound setDelegate:self];
22+
}
23+
[sound play];
24+
}
25+
26+
- (void) play:(NSString*)file onComplete:(JSValue*)callback {
27+
NSURL* fileUrl = [NSURL fileURLWithPath:pathForResource(file)];
28+
DebugNSLog(@"Sound file:%@", [fileUrl description]);
29+
30+
NSSound* sound = [[NSSound alloc] initWithContentsOfURL:fileUrl byReference:YES];
31+
[self playSound:sound onComplete:callback];
32+
}
33+
34+
- (void) playSystem:(NSString*)name onComplete:(JSValue*)callback {
35+
NSSound *systemSound = [NSSound soundNamed:name];
36+
[self playSound:systemSound onComplete:callback];
37+
}
38+
39+
- (void)sound:(NSSound *)aSound didFinishPlaying:(BOOL)finishedPlaying {
40+
[cb callWithArguments:@[aSound.name]];
41+
cb = nil;
42+
}
43+
44+
@end

MacGap/Classes/WebViewDelegate.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,18 @@
99
#import <Foundation/Foundation.h>
1010
#import <WebKit/WebKit.h>
1111

12-
@class WindowController, Window, Dock, Menu, Dialog, App;
12+
@class WindowController, Window, Menu, App;
1313

1414
@interface WebViewDelegate : NSObject {
1515
NSMenu *mainMenu;
1616
Window* window;
17-
Dock* dock;
1817
Menu* menu;
19-
Dialog* dialog;
2018
App* app;
2119
}
2220

2321
@property (nonatomic, retain) WindowController *windowController;
2422
@property (nonatomic, retain) Window* window;
25-
@property (nonatomic, retain) Dock* dock;
2623
@property (nonatomic, retain) Menu* menu;
27-
@property (nonatomic, retain) Dialog* dialog;
2824
@property (nonatomic, retain) App* app;
2925
- (id) initWithMenu:(NSMenu*)menu;
3026

MacGap/Classes/WebViewDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
@implementation WebViewDelegate
1515

16-
@synthesize windowController, window;
16+
@synthesize windowController;
1717

1818
- (id) initWithMenu:(NSMenu*)aMenu
1919
{

public/config.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
"Dialog":"Dialog",
99
"Fonts" : "Fonts",
1010
"Notify" : "Notify",
11-
"Clipboard":"Clipboard",
12-
"StatusItem":"StatusItem",
13-
"Task" : "Task"
11+
"Clipboard":"Clipboard",
12+
"StatusItem":"StatusItem",
13+
"Task" : "Task",
14+
"Sound" : "Sound"
1415
},
1516
"window" : {
1617
"title" : "MacGap",

0 commit comments

Comments
 (0)