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

Commit

Permalink
Allow the startup to complete without taking control of the runloop.
Browse files Browse the repository at this point in the history
Separate the initialization/shutdown sequence into separate methods just on the
offchance that a separate runloop might be used.
  • Loading branch information
iain holmes committed Jan 27, 2020
1 parent 96b42aa commit 6c6a281
Showing 1 changed file with 49 additions and 23 deletions.
72 changes: 49 additions & 23 deletions main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,27 +242,6 @@ int Run (MonoDevelopOptions options)
var desktopService = Runtime.GetService<DesktopService> ().Result;
desktopService.SetGlobalMenu (commandService, DefaultWorkbench.MainMenuPath, DefaultWorkbench.AppMenuPath);

// Run the main loop
Gtk.Application.Invoke ((s, e) => {
MainLoop (options, startupInfo).Ignore ();
});
Gtk.Application.Run ();

IdeApp.IsRunning = false;

IdeApp.Customizer.OnIdeShutdown ();

instanceConnection.Dispose ();

lockupCheckRunning = false;
Runtime.Shutdown ();

IdeApp.Customizer.OnCoreShutdown ();

InstrumentationService.Stop ();

MonoDevelop.Components.GtkWorkarounds.Terminate ();

return 0;
}

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

int Run (MonoDevelopOptions options, bool controlMainLoop)
{
var ret = Run (options);
if (ret != 0) {
return ret;
}

if (controlMainLoop) {
// Run the main loop
Gtk.Application.Invoke ((s, e) => {
MainLoop (options, startupInfo).Ignore ();
});
Gtk.Application.Run ();

Shutdown ();
return 0;
} else {
MainLoop (options, startupInfo).Ignore ();
return 0;
}
}

internal void Shutdown ()
{
IdeApp.IsRunning = false;

IdeApp.Customizer.OnIdeShutdown ();

instanceConnection.Dispose ();

lockupCheckRunning = false;
Runtime.Shutdown ();

IdeApp.Customizer.OnCoreShutdown ();

InstrumentationService.Stop ();

GtkWorkarounds.Terminate ();
}

void RegisterServices ()
{
Runtime.RegisterServiceType<ProgressMonitorManager, IdeProgressMonitorManager> ();
Expand Down Expand Up @@ -722,6 +741,11 @@ static void HandleException (Exception ex, bool willShutdown)
}

public static int Main (string[] args, IdeCustomizer customizer = null)
{
return Main (args, true, customizer);
}

public static int Main (string[] args, bool controlMainLoop, IdeCustomizer customizer)
{

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

var app = new IdeStartup ();
ret = app.Run (options);
ret = app.Run (options, controlMainLoop);
} catch (Exception ex) {
LoggingService.LogFatalError (
string.Format (
Expand All @@ -761,7 +785,9 @@ public static int Main (string[] args, IdeCustomizer customizer = null)
BrandingService.ApplicationName
), ex);
} finally {
Runtime.Shutdown ();
if (controlMainLoop) {
Runtime.Shutdown ();
}
}

LoggingService.Shutdown ();
Expand Down

0 comments on commit 6c6a281

Please sign in to comment.