Skip to content

Commit

Permalink
feat: call "Finish" while app is exiting
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimeNull committed Mar 27, 2024
1 parent b215d4b commit b35e792
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/CurvaLauncher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ protected override void OnStartup(StartupEventArgs e)
}
}

protected override void OnExit(ExitEventArgs e)
{
_ = App.ServiceProvider
.GetRequiredService<PluginService>()
.FinishAllPlugins();

base.OnExit(e);
}

private bool EnsureAppSingleton()
{
EventWaitHandle singletonEvent =
Expand Down
12 changes: 12 additions & 0 deletions src/CurvaLauncher/Services/PluginService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,16 @@ public async Task ReloadAllPlugins()
await asyncPlugin.InitializeAsync();
}
}

[RelayCommand]
public async Task FinishAllPlugins()
{
foreach (var plugin in PluginInstances.Where(ins => ins.IsEnabled))
{
if (plugin.Plugin is ISyncPlugin syncPlugin)
syncPlugin.Finish();
else if (plugin.Plugin is IAsyncPlugin asyncPlugin)
await asyncPlugin.FinishAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,10 @@ public override IEnumerable<IQueryResult> Query(string query)
weight -= float.Epsilon;
}
}

public override void Finish()
{

}
}
}

0 comments on commit b35e792

Please sign in to comment.