1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
21 #include <config_emscripten.h>
22 #include <config_features.h>
24 #include <desktop/dllapi.h>
27 #include "cmdlineargs.hxx"
28 #include "cmdlinehelp.hxx"
30 // needed before sal/main.h to avoid redefinition of macros
34 #include <o3tl/test_info.hxx>
35 #include <systools/win32/test_desktop.hxx>
38 #include <rtl/bootstrap.hxx>
40 #include <tools/extendapplicationenvironment.hxx>
41 #include <vcl/svmain.hxx>
43 #if HAVE_FEATURE_BREAKPAD
44 #include <desktop/crashreport.hxx>
51 # include <android/log.h>
52 # include <salhelper/thread.hxx>
54 # define LOGTAG "LibreOffice/sofficemain"
55 # define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOGTAG, __VA_ARGS__))
58 extern "C" int DESKTOP_DLLPUBLIC
soffice_main()
61 // If this is a UI test, we may need to switch to a dedicated desktop
62 if (o3tl::IsRunningUITest())
63 sal::systools::maybeCreateTestDesktop();
66 sal_detail_initialize(sal::detail::InitializeSoffice
, nullptr);
68 #if HAVE_FEATURE_BREAKPAD
69 CrashReporter::installExceptionHandler();
74 rtl::Bootstrap::setIniFilename("file:///assets/program/lofficerc");
76 tools::extendApplicationEnvironment();
78 #if defined EMSCRIPTEN && !HAVE_EMSCRIPTEN_JSPI
79 //HACK: Qt5 QWasmEventDispatcher::processEvents
80 // (qtbase/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp) calls
81 // emscripten_set_main_loop_arg with simulateInfiniteLoop == true, and as we use
82 // -fwasm-exceptions (cf. solenv/gbuild/platform/EMSCRIPTEN_INTEL_GCC.mk), aDesktop allocated on
83 // the stack would run into the issue warned about at
84 // <https://emscripten.org/docs/api_reference/emscripten.h.html#c.emscripten_set_main_loop>
85 // "Note: Currently, using the new Wasm exception handling and simulate_infinite_loop == true at
86 // the same time does not work yet in C++ projects that have objects with destructors on the
87 // stack at the time of the call." (Also see the mailing list thread at
88 // <https://groups.google.com/g/emscripten-discuss/c/xpWDVwyJu-M> "Implementation of
89 // -fexceptions and -fwasm-exceptions" for why such automatic variables are destroyed with
90 // -fwasm-exceptions but not with -fexceptions.) So deliberately leak the Desktop instance
92 new desktop::Desktop();
94 desktop::Desktop aDesktop
;
96 // This string is used during initialization of the Gtk+ VCL module
97 Application::SetAppName( u
"soffice"_ustr
);
99 // handle --version and --help already here, otherwise they would be handled
100 // after VCL initialization that might fail if $DISPLAY is not set
101 const desktop::CommandLineArgs
& rCmdLineArgs
= desktop::Desktop::GetCommandLineArgs();
102 const OUString
& aUnknown( rCmdLineArgs
.GetUnknown() );
103 if ( !aUnknown
.isEmpty() )
105 desktop::Desktop::InitApplicationServiceManager();
106 desktop::displayCmdlineHelp( aUnknown
);
109 if ( rCmdLineArgs
.IsHelp() )
111 desktop::Desktop::InitApplicationServiceManager();
112 desktop::displayCmdlineHelp( OUString() );
115 if ( rCmdLineArgs
.IsVersion() )
117 desktop::Desktop::InitApplicationServiceManager();
118 desktop::displayVersion();
124 } catch (const css::uno::Exception
&e
) {
125 LOGI("Unhandled UNO exception: '%s'",
126 OUStringToOString(e
.Message
, RTL_TEXTENCODING_UTF8
).getStr());
127 throw; // to get exception type printed
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */