mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-01 09:31:20 +08:00
[osx] Allow the user to configure a NSApplication subclass and use that instead.
Fixes http://hipbyte.myjetbrains.com/youtrack/issue/RM-539
This commit is contained in:
@@ -230,20 +230,36 @@ EOS
|
||||
end
|
||||
main_txt << <<EOS
|
||||
RubyMotionInit(argc, argv);
|
||||
NSApplication *app = [NSApplication sharedApplication];
|
||||
NSApplication *app = [NSClassFromString(@"#{info_plist['NSPrincipalClass']}") sharedApplication];
|
||||
[app setDelegate:[NSClassFromString(@"#{delegate_class}") new]];
|
||||
EOS
|
||||
if spec_mode
|
||||
main_txt << "SpecLauncher *specLauncher = [[SpecLauncher alloc] init];\n"
|
||||
main_txt << "[[NSNotificationCenter defaultCenter] addObserver:specLauncher selector:@selector(appLaunched:) name:NSApplicationDidFinishLaunchingNotification object:nil];\n"
|
||||
end
|
||||
if use_application_main_function?
|
||||
main_txt << "NSApplicationMain(argc, (const char **)argv);\n"
|
||||
else
|
||||
main_txt << "[app run];\n"
|
||||
end
|
||||
main_txt << <<EOS
|
||||
NSApplicationMain(argc, (const char **)argv);
|
||||
[pool release];
|
||||
rb_exit(0);
|
||||
return 0;
|
||||
}
|
||||
EOS
|
||||
end
|
||||
|
||||
# If the user specifies a custom principal class the NSApplicationMain()
|
||||
# function will only work if they have also specified a nib or storyboard.
|
||||
def use_application_main_function?
|
||||
info = info_plist
|
||||
if info['NSPrincipalClass'] == 'NSApplication'
|
||||
true
|
||||
else
|
||||
files = info.values_at('NSMainNibFile', 'NSMainStoryboardFile').compact
|
||||
files.any? { |file| !file.strip.empty? }
|
||||
end
|
||||
end
|
||||
end
|
||||
end; end
|
||||
|
||||
@@ -255,7 +255,7 @@ describe "NSNotFound" do
|
||||
end
|
||||
|
||||
describe "Application singleton subclassing" do
|
||||
xit "registers the principal class" do
|
||||
it "registers the principal class" do
|
||||
app = (ios? ? UIApplication : NSApplication).sharedApplication
|
||||
app.class.should == ApplicationSubclass
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user