26JUCEApplicationBase::CreateInstanceFunction JUCEApplicationBase::createInstance =
nullptr;
27JUCEApplicationBase* JUCEApplicationBase::appInstance =
nullptr;
30void* JUCEApplicationBase::iOSCustomDelegate =
nullptr;
33JUCEApplicationBase::JUCEApplicationBase()
41 jassert (appInstance ==
this);
42 appInstance =
nullptr;
51void JUCEApplicationBase::appWillTerminateByForce()
56 const std::unique_ptr<JUCEApplicationBase>
app (appInstance);
72void JUCEApplicationBase::sendUnhandledException (
const std::exception*
const e,
89#if ! (JUCE_IOS || JUCE_ANDROID)
90 #define JUCE_HANDLE_MULTIPLE_INSTANCES 1
93#if JUCE_HANDLE_MULTIPLE_INSTANCES
94struct JUCEApplicationBase::MultipleInstanceHandler final :
public ActionListener
96 MultipleInstanceHandler (
const String& appName)
97 : appLock (
"juceAppLock_" + appName)
101 bool sendCommandLineToPreexistingInstance()
103 if (appLock.enter (0))
116 void actionListenerCallback (
const String& message)
override
120 auto appName = app->getApplicationName();
122 if (message.startsWith (appName +
"/"))
123 app->anotherInstanceStarted (message.substring (appName.length() + 1));
128 InterProcessLock appLock;
130 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MultipleInstanceHandler)
133bool JUCEApplicationBase::sendCommandLineToPreexistingInstance()
135 jassert (multipleInstanceHandler ==
nullptr);
138 return multipleInstanceHandler->sendCommandLineToPreexistingInstance();
142struct JUCEApplicationBase::MultipleInstanceHandler {};
153#if JUCE_WINDOWS && ! defined (_CONSOLE)
158 CharPointer_UTF16 (L
" "),
159 CharPointer_UTF16 (L
"\"")).findEndOfWhitespace();
167 if (
auto argv = CommandLineToArgvW (GetCommandLineW(), &argc))
169 s = StringArray (argv + 1, argc - 1);
178#if JUCE_IOS && JUCE_MODULE_AVAILABLE_juce_gui_basics
179 extern int juce_iOSMain (
int argc,
const char* argv[],
void* classPtr);
183 extern void initialiseNSApplication();
186#if (JUCE_LINUX || JUCE_BSD) && JUCE_MODULE_AVAILABLE_juce_gui_extra && (! defined (JUCE_WEB_BROWSER) || JUCE_WEB_BROWSER)
187 extern "C" int juce_gtkWebkitMain (
int argc,
const char*
const* argv);
191 const char*
const* juce_argv =
nullptr;
194 extern const char*
const* juce_argv;
195 extern int juce_argc;
217 for (
int i = 1; i < juce_argc; ++i)
223int JUCEApplicationBase::main (
int argc,
const char*
argv[])
234 #if (JUCE_LINUX || JUCE_BSD) && JUCE_MODULE_AVAILABLE_juce_gui_extra && (! defined (JUCE_WEB_BROWSER) || JUCE_WEB_BROWSER)
235 if (
argc >= 2 &&
String (
argv[1]) ==
"--juce-gtkwebkitfork-child")
239 #if JUCE_IOS && JUCE_MODULE_AVAILABLE_juce_gui_basics
243 return JUCEApplicationBase::main();
251int JUCEApplicationBase::main()
253 ScopedJuceInitialiser_GUI libraryInitialiser;
254 jassert (createInstance !=
nullptr);
256 const std::unique_ptr<JUCEApplicationBase> app (createInstance());
257 jassert (app !=
nullptr);
259 if (! app->initialiseApp())
260 return app->shutdownApp();
269 return app->shutdownApp();
275bool JUCEApplicationBase::initialiseApp()
277 #if JUCE_HANDLE_MULTIPLE_INSTANCES
280 DBG (
"Another instance is running - quitting...");
285 #if JUCE_WINDOWS && (! defined (_CONSOLE)) && (! JUCE_MINGW)
293 if (_fileno (stdout) < 0) freopen_s (&ignore,
"CONOUT$",
"w", stdout);
294 if (_fileno (stderr) < 0) freopen_s (&ignore,
"CONOUT$",
"w", stderr);
295 if (_fileno (stdin) < 0) freopen_s (&ignore,
"CONIN$",
"r", stdin);
302 stillInitialising =
false;
307 #if JUCE_HANDLE_MULTIPLE_INSTANCES
308 if (
auto* mih = multipleInstanceHandler.get())
315int JUCEApplicationBase::shutdownApp()
319 #if JUCE_HANDLE_MULTIPLE_INSTANCES
320 if (
auto* mih = multipleInstanceHandler.get())
331 multipleInstanceHandler.reset();
static Type findEndOfToken(Type text, BreakType breakCharacters, Type quoteCharacters)
static bool isAbsolutePath(StringRef path)
virtual ~JUCEApplicationBase()
virtual void initialise(const String &commandLineParameters)=0
virtual const String getApplicationName()=0
static String JUCE_CALLTYPE getCommandLineParameters()
static StringArray JUCE_CALLTYPE getCommandLineParameterArray()
void setApplicationReturnValue(int newReturnValue) noexcept
static JUCEApplicationBase * getInstance() noexcept
static bool isStandaloneApp() noexcept
virtual bool moreThanOneInstanceAllowed()=0
int getApplicationReturnValue() const noexcept
static void broadcastMessage(const String &messageText)
static void deleteInstance()
static MessageManager * getInstance()
void add(String stringToAdd)