Skip to content

Commit 09bc2bc

Browse files
committed
Cleanup & Improve
1 parent 5b29ded commit 09bc2bc

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

Flow.Launcher/App.xaml.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
namespace Flow.Launcher
2727
{
28-
public partial class App : IAsyncDisposable, ISingleInstanceApp
28+
public partial class App : IDisposable, ISingleInstanceApp
2929
{
3030
#region Public Properties
3131

@@ -122,10 +122,9 @@ public static void Main()
122122
{
123123
if (SingleInstance<App>.InitializeAsFirstInstance())
124124
{
125-
var application = new App();
125+
using var application = new App();
126126
application.InitializeComponent();
127127
application.Run();
128-
application.DisposeAsync().AsTask().GetAwaiter().GetResult();
129128
}
130129
}
131130

@@ -240,22 +239,22 @@ private void AutoUpdates()
240239

241240
private void RegisterExitEvents()
242241
{
243-
AppDomain.CurrentDomain.ProcessExit += async (s, e) =>
242+
AppDomain.CurrentDomain.ProcessExit += (s, e) =>
244243
{
245244
Log.Info("|App.RegisterExitEvents|Process Exit");
246-
await DisposeAsync();
245+
Dispose();
247246
};
248247

249-
Current.Exit += async (s, e) =>
248+
Current.Exit += (s, e) =>
250249
{
251250
Log.Info("|App.RegisterExitEvents|Application Exit");
252-
await DisposeAsync();
251+
Dispose();
253252
};
254253

255-
Current.SessionEnding += async (s, e) =>
254+
Current.SessionEnding += (s, e) =>
256255
{
257256
Log.Info("|App.RegisterExitEvents|Session Ending");
258-
await DisposeAsync();
257+
Dispose();
259258
};
260259
}
261260

@@ -279,9 +278,9 @@ private static void RegisterAppDomainExceptions()
279278

280279
#endregion
281280

282-
#region IAsyncDisposable
281+
#region IDisposable
283282

284-
protected virtual async ValueTask DisposeAsync(bool disposing)
283+
protected virtual void Dispose(bool disposing)
285284
{
286285
// Prevent two disposes at the same time.
287286
lock (_disposingLock)
@@ -299,9 +298,7 @@ protected virtual async ValueTask DisposeAsync(bool disposing)
299298
_disposed = true;
300299
}
301300

302-
await Task.Delay(10000);
303-
304-
await Stopwatch.NormalAsync("|App.Dispose|Dispose cost", async () =>
301+
Stopwatch.Normal("|App.Dispose|Dispose cost", async () =>
305302
{
306303
Log.Info("|App.Dispose|Begin Flow Launcher dispose ----------------------------------------------------");
307304

@@ -310,19 +307,19 @@ await Stopwatch.NormalAsync("|App.Dispose|Dispose cost", async () =>
310307
API?.SaveAppAllSettings();
311308
await PluginManager.DisposePluginsAsync();
312309

313-
// Dispose needs to be called on the main Windows thread, since some resources owned by the thread need to be disposed.
314-
await _mainWindow?.Dispatcher.InvokeAsync(_mainWindow.Dispose);
310+
// Dispose needs to be called on the main Windows thread,
311+
// since some resources owned by the thread need to be disposed.
312+
_mainWindow?.Dispatcher.Invoke(_mainWindow.Dispose);
315313
_mainVM?.Dispose();
316314
}
317315

318316
Log.Info("|App.Dispose|End Flow Launcher dispose ----------------------------------------------------");
319317
});
320318
}
321319

322-
public async ValueTask DisposeAsync()
320+
public void Dispose()
323321
{
324-
// Do not change this code. Put cleanup code in 'DisposeAsync(bool disposing)' method
325-
await DisposeAsync(disposing: true);
322+
Dispose(disposing: true);
326323
GC.SuppressFinalize(this);
327324
}
328325

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public partial class MainWindow : IDisposable
4242
private readonly ContextMenu contextMenu = new();
4343
private readonly MainViewModel _viewModel;
4444

45-
// Window Event : Key Event
45+
// Window Event: Key Event
4646
private bool isArrowKeyPressed = false;
4747

4848
// Window Sound Effects
@@ -233,7 +233,6 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
233233

234234
private void OnClosing(object sender, CancelEventArgs e)
235235
{
236-
_viewModel.Save();
237236
_notifyIcon.Visible = false;
238237
Notification.Uninstall();
239238
}

0 commit comments

Comments
 (0)