Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 6c6a281

Browse files
author
iain holmes
committed
Allow the startup to complete without taking control of the runloop.
Separate the initialization/shutdown sequence into separate methods just on the offchance that a separate runloop might be used.
1 parent 96b42aa commit 6c6a281

File tree

1 file changed

+49
-23
lines changed

1 file changed

+49
-23
lines changed

main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -242,27 +242,6 @@ int Run (MonoDevelopOptions options)
242242
var desktopService = Runtime.GetService<DesktopService> ().Result;
243243
desktopService.SetGlobalMenu (commandService, DefaultWorkbench.MainMenuPath, DefaultWorkbench.AppMenuPath);
244244

245-
// Run the main loop
246-
Gtk.Application.Invoke ((s, e) => {
247-
MainLoop (options, startupInfo).Ignore ();
248-
});
249-
Gtk.Application.Run ();
250-
251-
IdeApp.IsRunning = false;
252-
253-
IdeApp.Customizer.OnIdeShutdown ();
254-
255-
instanceConnection.Dispose ();
256-
257-
lockupCheckRunning = false;
258-
Runtime.Shutdown ();
259-
260-
IdeApp.Customizer.OnCoreShutdown ();
261-
262-
InstrumentationService.Stop ();
263-
264-
MonoDevelop.Components.GtkWorkarounds.Terminate ();
265-
266245
return 0;
267246
}
268247

@@ -403,6 +382,46 @@ async Task<int> MainLoop (MonoDevelopOptions options, StartupInfo startupInfo)
403382
return 0;
404383
}
405384

385+
int Run (MonoDevelopOptions options, bool controlMainLoop)
386+
{
387+
var ret = Run (options);
388+
if (ret != 0) {
389+
return ret;
390+
}
391+
392+
if (controlMainLoop) {
393+
// Run the main loop
394+
Gtk.Application.Invoke ((s, e) => {
395+
MainLoop (options, startupInfo).Ignore ();
396+
});
397+
Gtk.Application.Run ();
398+
399+
Shutdown ();
400+
return 0;
401+
} else {
402+
MainLoop (options, startupInfo).Ignore ();
403+
return 0;
404+
}
405+
}
406+
407+
internal void Shutdown ()
408+
{
409+
IdeApp.IsRunning = false;
410+
411+
IdeApp.Customizer.OnIdeShutdown ();
412+
413+
instanceConnection.Dispose ();
414+
415+
lockupCheckRunning = false;
416+
Runtime.Shutdown ();
417+
418+
IdeApp.Customizer.OnCoreShutdown ();
419+
420+
InstrumentationService.Stop ();
421+
422+
GtkWorkarounds.Terminate ();
423+
}
424+
406425
void RegisterServices ()
407426
{
408427
Runtime.RegisterServiceType<ProgressMonitorManager, IdeProgressMonitorManager> ();
@@ -722,6 +741,11 @@ static void HandleException (Exception ex, bool willShutdown)
722741
}
723742

724743
public static int Main (string[] args, IdeCustomizer customizer = null)
744+
{
745+
return Main (args, true, customizer);
746+
}
747+
748+
public static int Main (string[] args, bool controlMainLoop, IdeCustomizer customizer)
725749
{
726750

727751
IdeStartupTracker.StartupTracker.Start ();
@@ -752,7 +776,7 @@ public static int Main (string[] args, IdeCustomizer customizer = null)
752776
IdeStartupTracker.StartupTracker.MarkSection ("mainInitialization");
753777

754778
var app = new IdeStartup ();
755-
ret = app.Run (options);
779+
ret = app.Run (options, controlMainLoop);
756780
} catch (Exception ex) {
757781
LoggingService.LogFatalError (
758782
string.Format (
@@ -761,7 +785,9 @@ public static int Main (string[] args, IdeCustomizer customizer = null)
761785
BrandingService.ApplicationName
762786
), ex);
763787
} finally {
764-
Runtime.Shutdown ();
788+
if (controlMainLoop) {
789+
Runtime.Shutdown ();
790+
}
765791
}
766792

767793
LoggingService.Shutdown ();

0 commit comments

Comments
 (0)