Skip to content

Commit 04edc08

Browse files
igorkorsukovdavidstephengrant
authored andcommitted
fixed show splash screen (setup step by step on event loop)
1 parent 0a0a39f commit 04edc08

File tree

6 files changed

+101
-59
lines changed

6 files changed

+101
-59
lines changed

src/app/internal/consoleapp.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ void ConsoleApp::addModule(modularity::IModuleSetup* module)
7575
m_modules.push_back(module);
7676
}
7777

78+
void ConsoleApp::showSplash()
79+
{
80+
std::cout << "================================================" << std::endl;
81+
std::cout << "The MuseScore console application is starting..." << std::endl;
82+
std::cout << "================================================" << std::endl;
83+
}
84+
7885
void ConsoleApp::setup()
7986
{
8087
const CmdOptions& options = m_options;

src/app/internal/consoleapp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class ConsoleApp : public muse::BaseApplication, public std::enable_shared_from_
6969

7070
void addModule(muse::modularity::IModuleSetup* module);
7171

72+
void showSplash() override;
7273
void setup() override;
7374
void finish() override;
7475

src/app/internal/guiapp.cpp

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,6 @@
1919
#include "muse_framework_config.h"
2020
#include "app_config.h"
2121

22-
#ifdef MUE_ENABLE_SPLASHSCREEN
23-
#include "appshell/widgets/splashscreen/splashscreen.h"
24-
#else
25-
namespace mu::appshell {
26-
class SplashScreen
27-
{
28-
public:
29-
void close() {}
30-
};
31-
}
32-
#endif
33-
3422
#ifdef QT_CONCURRENT_SUPPORTED
3523
#include <QThreadPool>
3624
#endif
@@ -55,6 +43,45 @@ void GuiApp::addModule(muse::modularity::IModuleSetup* module)
5543
m_modules.push_back(module);
5644
}
5745

46+
GuiApp::SplashConfig GuiApp::splashConfig(const CmdOptions& options) const
47+
{
48+
SplashConfig cfg;
49+
cfg.type = SplashScreen::Default;
50+
51+
if (options.startup.type.has_value()) {
52+
if (options.startup.type.value() == "start-with-new") {
53+
cfg.type = SplashScreen::ForNewInstance;
54+
cfg.forNewScore = true;
55+
} else if (options.startup.scoreUrl.has_value()) {
56+
project::ProjectFile file { options.startup.scoreUrl.value() };
57+
58+
if (options.startup.scoreDisplayNameOverride.has_value()) {
59+
file.displayNameOverride = options.startup.scoreDisplayNameOverride.value();
60+
}
61+
62+
cfg.type = SplashScreen::ForNewInstance;
63+
cfg.forNewScore = false;
64+
if (file.hasDisplayName()) {
65+
cfg.openingFileName = file.displayName(true /* includingExtension */);
66+
}
67+
} else {
68+
cfg.type = SplashScreen::Default;
69+
}
70+
}
71+
72+
return cfg;
73+
}
74+
75+
void GuiApp::showSplash()
76+
{
77+
#ifdef MUE_ENABLE_SPLASHSCREEN
78+
if (splashConfig(m_options).type == SplashScreen::Default) {
79+
m_splashScreen = new SplashScreen(SplashScreen::Default);
80+
m_splashScreen->show();
81+
}
82+
#endif
83+
}
84+
5885
void GuiApp::setup()
5986
{
6087
const CmdOptions& options = m_options;
@@ -105,38 +132,6 @@ void GuiApp::setup()
105132
m->onPreInit(runMode);
106133
}
107134

108-
// Process all pending events (see IpcSocket::onReadyRead())
109-
// so that we can use isFirstWindow() as early as possible
110-
muse::async::processMessages();
111-
112-
//! FIXME
113-
//! The launch scenario is contextual, but there is no context here.
114-
#undef MUE_ENABLE_SPLASHSCREEN
115-
116-
#ifdef MUE_ENABLE_SPLASHSCREEN
117-
if (multiwindowsProvider()->isFirstWindow()) {
118-
m_splashScreen = new SplashScreen(SplashScreen::Default);
119-
} else {
120-
auto startupScenario = muse::modularity::ioc(iocContext())->resolve<IStartupScenario>("app");
121-
const project::ProjectFile& file = startupScenario->startupScoreFile();
122-
if (file.isValid()) {
123-
if (file.hasDisplayName()) {
124-
m_splashScreen = new SplashScreen(SplashScreen::ForNewInstance, false, file.displayName(true /* includingExtension */));
125-
} else {
126-
m_splashScreen = new SplashScreen(SplashScreen::ForNewInstance, false);
127-
}
128-
} else if (startupScenario->isStartWithNewFileAsSecondaryInstance()) {
129-
m_splashScreen = new SplashScreen(SplashScreen::ForNewInstance, true);
130-
} else {
131-
m_splashScreen = new SplashScreen(SplashScreen::Default);
132-
}
133-
}
134-
135-
if (m_splashScreen) {
136-
m_splashScreen->show();
137-
}
138-
#endif
139-
140135
// ====================================================
141136
// Setup modules: onInit
142137
// ====================================================
@@ -177,11 +172,7 @@ void GuiApp::setup()
177172
m_delayedInitTimer.start();
178173

179174
// ====================================================
180-
// Run
181-
// ====================================================
182-
183-
// ====================================================
184-
// Setup Qml Engine
175+
// Setup Graphics Api check
185176
// ====================================================
186177
//! Needs to be set because we use transparent windows for PopupView.
187178
//! Needs to be called before any QQuickWindows are shown.
@@ -266,6 +257,17 @@ size_t GuiApp::contextCount() const
266257
return m_contexts.size();
267258
}
268259

260+
void GuiApp::showContextSplash()
261+
{
262+
#ifdef MUE_ENABLE_SPLASHSCREEN
263+
SplashConfig cfg = splashConfig(m_options);
264+
if (cfg.type == SplashScreen::ForNewInstance) {
265+
m_splashScreen = new SplashScreen(cfg.type, cfg.forNewScore, cfg.openingFileName);
266+
m_splashScreen->show();
267+
}
268+
#endif
269+
}
270+
269271
muse::modularity::ContextPtr GuiApp::setupNewContext(const StringList& args)
270272
{
271273
#ifndef MUSE_MODULE_MULTIWINDOWS_SINGLEPROC_MODE
@@ -397,11 +399,13 @@ muse::modularity::ContextPtr GuiApp::setupNewContext(const StringList& args)
397399
startupScenario->runOnSplashScreen();
398400

399401
QMetaObject::invokeMethod(qApp, [this, ctxId, obj, startupScenario]() {
402+
#ifdef MUE_ENABLE_SPLASHSCREEN
400403
if (m_splashScreen) {
401404
m_splashScreen->close();
402405
delete m_splashScreen;
403406
m_splashScreen = nullptr;
404407
}
408+
#endif
405409

406410
// The main window must be shown at this point so KDDockWidgets can read its size correctly
407411
// and scale all sizes properly. https://github.com/musescore/MuseScore/issues/21148

src/app/internal/guiapp.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
#include "appshell/iappshellconfiguration.h"
1818
#include "importexport/guitarpro/iguitarproconfiguration.h"
1919

20-
class QQuickWindow;
20+
#include "appshell/widgets/splashscreen/splashscreen.h"
2121

22-
namespace mu::appshell {
23-
class SplashScreen;
24-
}
22+
class QQuickWindow;
2523

2624
namespace mu::app {
2725
class GuiApp : public muse::BaseApplication, public std::enable_shared_from_this<GuiApp>
@@ -35,15 +33,26 @@ class GuiApp : public muse::BaseApplication, public std::enable_shared_from_this
3533

3634
void addModule(muse::modularity::IModuleSetup* module);
3735

36+
void showSplash() override;
3837
void setup() override;
3938
void finish() override;
4039

40+
void showContextSplash() override;
4141
muse::modularity::ContextPtr setupNewContext(const muse::StringList& args = {}) override;
4242
void destroyContext(const muse::modularity::ContextPtr& ctx) override;
4343
size_t contextCount() const override;
4444
std::vector<muse::modularity::ContextPtr> contexts() const override;
4545

4646
private:
47+
48+
struct SplashConfig {
49+
appshell::SplashScreen::SplashScreenType type = appshell::SplashScreen::SplashScreenType::Default;
50+
bool forNewScore = false;
51+
QString openingFileName;
52+
};
53+
54+
SplashConfig splashConfig(const CmdOptions& options) const;
55+
4756
void applyCommandLineOptions(const CmdOptions& options);
4857

4958
struct Context {

src/app/main.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,29 @@ int main(int argc, char** argv)
158158
opt.runMode = IApplication::RunMode::GuiApp;
159159
#endif
160160

161-
AppFactory f;
162-
std::shared_ptr<muse::IApplication> app = f.newApp(opt);
163-
164-
app->setup();
161+
// ====================================================
162+
// Setup application
163+
// ====================================================
165164

166-
app->setupNewContext();
165+
//! NOTE: We immediately launch the application's event loop
166+
// to be able to show a splash screen (on Linux, splash screen won't show without event loop).
167+
// All subsequent initialization steps will be executed as events in the event loop.
168+
169+
std::shared_ptr<muse::IApplication> app;
170+
QMetaObject::invokeMethod(qapp, [qapp, &app, &opt]() {
171+
AppFactory f;
172+
app = f.newApp(opt);
173+
app->showSplash();
174+
QMetaObject::invokeMethod(qapp, [qapp, &app]() {
175+
app->setup();
176+
QMetaObject::invokeMethod(qapp, [qapp, &app]() {
177+
app->showContextSplash();
178+
QMetaObject::invokeMethod(qapp, [&app]() {
179+
app->setupNewContext();
180+
}, Qt::QueuedConnection);
181+
}, Qt::QueuedConnection);
182+
}, Qt::QueuedConnection);
183+
}, Qt::QueuedConnection);
167184

168185
// ====================================================
169186
// Run main loop
@@ -174,7 +191,9 @@ int main(int argc, char** argv)
174191
// Quit
175192
// ====================================================
176193

177-
app->finish();
194+
if (app) {
195+
app->finish();
196+
}
178197

179198
delete qapp;
180199

src/framework/global/iapplication.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ class IApplication : MODULE_GLOBAL_INTERFACE
6464
virtual RunMode runMode() const = 0;
6565
virtual bool noGui() const = 0;
6666

67+
virtual void showSplash() {}
6768
virtual void setup() = 0;
6869
virtual void finish() = 0;
6970
virtual void restart() = 0;
7071

72+
virtual void showContextSplash() {}
7173
virtual modularity::ContextPtr setupNewContext(const StringList& args = {}) = 0;
7274
virtual void destroyContext(const modularity::ContextPtr& ctx) = 0;
7375
virtual size_t contextCount() const = 0;

0 commit comments

Comments
 (0)