26 JUCEApplicationBase::CreateInstanceFunction JUCEApplicationBase::createInstance =
nullptr;
27 JUCEApplicationBase* JUCEApplicationBase::appInstance =
nullptr;
30 void* JUCEApplicationBase::iOSCustomDelegate =
nullptr;
33 JUCEApplicationBase::JUCEApplicationBase()
41 jassert (appInstance ==
this);
42 appInstance =
nullptr;
47 appReturnValue = newReturnValue;
51 void JUCEApplicationBase::appWillTerminateByForce()
56 const std::unique_ptr<JUCEApplicationBase> app (appInstance);
72 void JUCEApplicationBase::sendUnhandledException (
const std::exception*
const e,
73 const char*
const sourceFile,
84 app->unhandledException (e, sourceFile, lineNumber);
89 #if ! (JUCE_IOS || JUCE_ANDROID) 90 #define JUCE_HANDLE_MULTIPLE_INSTANCES 1 93 #if JUCE_HANDLE_MULTIPLE_INSTANCES 97 : appLock (
"juceAppLock_" + appName)
101 bool sendCommandLineToPreexistingInstance()
103 if (appLock.enter (0))
116 void actionListenerCallback (
const String& message)
override 120 auto appName = app->getApplicationName();
123 app->anotherInstanceStarted (message.
substring (appName.
length() + 1));
133 bool JUCEApplicationBase::sendCommandLineToPreexistingInstance()
135 jassert (multipleInstanceHandler ==
nullptr);
138 return multipleInstanceHandler->sendCommandLineToPreexistingInstance();
153 #if JUCE_WINDOWS && ! defined (_CONSOLE) 167 if (
auto argv = CommandLineToArgvW (GetCommandLineW(), &argc))
179 extern int juce_iOSMain (
int argc,
const char* argv[],
void* classPtr);
183 extern void initialiseNSApplication();
186 #if JUCE_LINUX && JUCE_MODULE_AVAILABLE_juce_gui_extra && (! defined(JUCE_WEB_BROWSER) || JUCE_WEB_BROWSER) 187 extern int juce_gtkWebkitMain (
int argc,
const char* argv[]);
191 const char*
const* juce_argv =
nullptr;
194 extern const char*
const* juce_argv;
195 extern int juce_argc;
202 for (
int i = 1; i < juce_argc; ++i)
204 String arg (juce_argv[i]);
209 argString << arg <<
' ';
212 return argString.
trim();
220 int JUCEApplicationBase::main (
int argc,
const char* argv[])
228 initialiseNSApplication();
231 #if JUCE_LINUX && JUCE_MODULE_AVAILABLE_juce_gui_extra && (! defined(JUCE_WEB_BROWSER) || JUCE_WEB_BROWSER) 232 if (argc >= 2 &&
String (argv[1]) ==
"--juce-gtkwebkitfork-child")
233 return juce_gtkWebkitMain (argc, argv);
237 return juce_iOSMain (argc, argv, iOSCustomDelegate);
240 return JUCEApplicationBase::main();
248 int JUCEApplicationBase::main()
251 jassert (createInstance !=
nullptr);
253 const std::unique_ptr<JUCEApplicationBase> app (createInstance());
254 jassert (app !=
nullptr);
256 if (! app->initialiseApp())
257 return app->shutdownApp();
266 return app->shutdownApp();
272 bool JUCEApplicationBase::initialiseApp()
274 #if JUCE_HANDLE_MULTIPLE_INSTANCES 277 DBG (
"Another instance is running - quitting...");
282 #if JUCE_WINDOWS && JUCE_STANDALONE_APPLICATION && (! defined (_CONSOLE)) && (! JUCE_MINGW) 283 if (AttachConsole (ATTACH_PARENT_PROCESS) != 0)
290 if (_fileno(stdout) < 0) freopen_s (&ignore,
"CONOUT$",
"w", stdout);
291 if (_fileno(stderr) < 0) freopen_s (&ignore,
"CONOUT$",
"w", stderr);
292 if (_fileno(stdin) < 0) freopen_s (&ignore,
"CONIN$",
"r", stdin);
299 stillInitialising =
false;
304 #if JUCE_HANDLE_MULTIPLE_INSTANCES 305 if (
auto* mih = multipleInstanceHandler.get())
312 int JUCEApplicationBase::shutdownApp()
316 #if JUCE_HANDLE_MULTIPLE_INSTANCES 317 if (
auto* mih = multipleInstanceHandler.get())
328 multipleInstanceHandler.reset();
Interface class for delivery of events that are sent by an ActionBroadcaster.
Acts as a critical section which processes can use to block each other.
static bool isAbsolutePath(StringRef path)
Returns true if the string seems to be a fully-specified absolute path.
static Type findEndOfToken(Type text, BreakType breakCharacters, Type quoteCharacters)
Returns a pointer to the first character in the string which is found in the breakCharacters string...
static String JUCE_CALLTYPE getCommandLineParameters()
Returns the application's command line parameters as a single string.
static JUCEApplicationBase * getInstance() noexcept
Returns the global instance of the application object that's running.
static void deleteAll()
Deletes all extant objects.
bool containsChar(juce_wchar character) const noexcept
Tests whether the string contains a particular character.
bool isQuotedString() const
Checks whether the string might be in quotation marks.
static MessageManager * getInstance()
Returns the global instance of the MessageManager.
A special array for holding a list of strings.
void stopDispatchLoop()
Sends a signal that the dispatch loop should terminate.
virtual void initialise(const String &commandLineParameters)=0
Called when the application starts.
void runDispatchLoop()
Runs the event dispatch loop until a stop message is posted.
String substring(int startIndex, int endIndex) const
Returns a subsection of the string.
virtual bool moreThanOneInstanceAllowed()=0
Checks whether multiple instances of the app are allowed.
static void quit()
Signals that the main message loop should stop and the application should terminate.
A utility object that helps you initialise and shutdown JUCE correctly using an RAII pattern...
int getApplicationReturnValue() const noexcept
Returns the value that has been set as the application's exit code.
virtual ~JUCEApplicationBase()
Destructor.
static void broadcastMessage(const String &messageText)
Sends a message to all other JUCE applications that are running.
void registerBroadcastListener(ActionListener *listener)
Registers a listener to get told about broadcast messages.
static StringArray JUCE_CALLTYPE getCommandLineParameterArray()
Returns the application's command line parameters as a set of strings.
static void deleteInstance()
Deletes the global MessageManager instance.
void setApplicationReturnValue(int newReturnValue) noexcept
Sets the value that should be returned as the application's exit code when the app quits...
virtual const String getApplicationName()=0
Returns the application's name.
Wraps a pointer to a null-terminated UTF-16 character string, and provides various methods to operate...
String trim() const
Returns a copy of this string with any whitespace characters removed from the start and end...
int length() const noexcept
Returns the number of characters in the string.
void deregisterBroadcastListener(ActionListener *listener)
Deregisters a broadcast listener.
String quoted(juce_wchar quoteCharacter='"') const
Adds quotation marks around a string.
bool startsWith(StringRef text) const noexcept
Tests whether the string begins with another string.
static bool isStandaloneApp() noexcept
Returns true if this executable is running as an app (as opposed to being a plugin or other kind of s...