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

Allow the startup to complete without taking control of the runloop. #9600

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

@Therzok Therzok Jan 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to refactor this controlMainLoop code? It might end up cleaner if we had 2 separate runloop runners (i.e. in IdeCustomizer), with different implementations and simplify all the signatures that have changed around here?

Runtime.Shutdown ();
}
}

LoggingService.Shutdown ();
Expand Down