Don't call app_main() from OSXApp

This commit is contained in:
David Capello 2016-04-11 16:19:32 -03:00
parent 4acf12a478
commit c900e4aa3c
3 changed files with 29 additions and 27 deletions

View File

@ -1,5 +1,5 @@
// SHE library // SHE library
// Copyright (C) 2012-2015 David Capello // Copyright (C) 2012-2016 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -16,15 +16,14 @@ namespace she {
class OSXApp { class OSXApp {
public: public:
static OSXApp* instance() { return g_instance; }
OSXApp(); OSXApp();
~OSXApp(); ~OSXApp();
int run(int argc, char* argv[]); bool init();
private: private:
static OSXApp* g_instance; class Impl;
Impl* m_impl;
}; };
} // namespace she } // namespace she

View File

@ -19,29 +19,36 @@ extern int app_main(int argc, char* argv[]);
namespace she { namespace she {
OSXApp* OSXApp::g_instance = nullptr; class OSXApp::Impl {
public:
bool init() {
m_app = [NSApplication sharedApplication];
m_appDelegate = [OSXAppDelegate new];
[m_app setActivationPolicy:NSApplicationActivationPolicyRegular];
[m_app setDelegate:m_appDelegate];
[m_app activateIgnoringOtherApps:YES];
return true;
}
private:
NSApplication* m_app;
id m_appDelegate;
};
OSXApp::OSXApp() OSXApp::OSXApp()
: m_impl(new Impl)
{ {
g_instance = this;
} }
OSXApp::~OSXApp() OSXApp::~OSXApp()
{ {
g_instance = nullptr;
} }
int OSXApp::run(int argc, char* argv[]) bool OSXApp::init()
{ {
NSApplication* app = [NSApplication sharedApplication]; return m_impl->init();
id appDelegate = [OSXAppDelegate new];
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
[app setDelegate:appDelegate];
[app activateIgnoringOtherApps:YES];
app_main(argc, argv);
return 0;
} }
} // namespace she } // namespace she

View File

@ -54,8 +54,7 @@ extern int app_main(int argc, char* argv[]);
#if _WIN32 #if _WIN32
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) LPSTR lpCmdLine, int nCmdShow) {
{
int argc = 0; int argc = 0;
LPWSTR* argvW = CommandLineToArgvW(GetCommandLineW(), &argc); LPWSTR* argvW = CommandLineToArgvW(GetCommandLineW(), &argc);
char** argv; char** argv;
@ -70,19 +69,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
argv[0] = base_strdup(""); argv[0] = base_strdup("");
} }
#else #else
int main(int argc, char* argv[]) int main(int argc, char* argv[]) {
{
#endif #endif
#if __APPLE__ #if __APPLE__
she::OSXApp app; she::OSXApp app;
return app.run(argc, argv); if (!app.init())
#else return 1;
#elif !defined(_WIN32)
#ifndef _WIN32
she::X11 x11; she::X11 x11;
#endif #endif
return app_main(argc, argv); return app_main(argc, argv);
#endif
} }