Skip to content

Commit

Permalink
Fix updater migration
Browse files Browse the repository at this point in the history
  • Loading branch information
X9VoiD committed Jul 25, 2023
1 parent 77e2d74 commit 2528b6e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
6 changes: 5 additions & 1 deletion OpenTabletDriver.UX.Gtk/LinuxApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,18 @@ public override void StartDaemon()
}
}

public override void Exit(int code)
public override void StopDaemon()
{
if (_daemon != null)
{
_daemon.Exited -= HandleDaemonExited;
_daemon.Close();
}
}

public override void Exit(int code)
{
StopDaemon();
base.Exit(code);
}

Expand Down
8 changes: 6 additions & 2 deletions OpenTabletDriver.UX.MacOS/MacOSApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,18 @@ public override void StartDaemon()
}
}

public override void Exit(int code)
public override void StopDaemon()
{
if (_daemon != null)
{
_daemon.Exited -= HandleDaemonExited;
_daemon.Kill();
_daemon.Close();
}
}

public override void Exit(int code)
{
StopDaemon();
base.Exit(code);
}

Expand Down
8 changes: 6 additions & 2 deletions OpenTabletDriver.UX.Wpf/WindowsApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ public override void StartDaemon()
}
}

public override void Exit(int code)
public override void StopDaemon()
{
if (_daemon != null)
{
_daemon.Exited -= HandleDaemonExited;
_daemon.Kill();
_daemon.Close();
}
}

public override void Exit(int code)
{
StopDaemon();
base.Exit(code);
}

Expand Down
5 changes: 5 additions & 0 deletions OpenTabletDriver.UX/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ public virtual void Open(string? uri, bool isDirectory = false)
/// </summary>
public abstract void StartDaemon();

/// <summary>
/// Stops OpenTabletDriver daemon, if running.
/// </summary>
public abstract void StopDaemon();

/// <summary>
/// The event handler for all client <see cref="Log.Write(OpenTabletDriver.Logging.LogMessage)"/> calls.
/// </summary>
Expand Down
28 changes: 25 additions & 3 deletions OpenTabletDriver.UX/Windows/UpdateForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OpenTabletDriver.Desktop.Contracts;
using OpenTabletDriver.Desktop.Interop.AppInfo;
using OpenTabletDriver.Desktop.Updater;
using OpenTabletDriver.Interop;
using OpenTabletDriver.UX.Components;

namespace OpenTabletDriver.UX.Windows
Expand All @@ -12,6 +13,7 @@ public sealed class UpdateForm : DesktopForm
{
private readonly IDriverDaemon _daemon;
private readonly App _app;
private int _isUpdateRequested;

public UpdateForm(IDriverDaemon daemon, App app, SerializedUpdateInfo update)
{
Expand Down Expand Up @@ -50,11 +52,31 @@ public UpdateForm(IDriverDaemon daemon, App app, SerializedUpdateInfo update)

private async Task InstallUpdate()
{
if (Interlocked.Exchange(ref _isUpdateRequested, 1) != 0)
return;

Enabled = false;
var path = Process.GetCurrentProcess().MainModule!.FileName;

await _daemon.InstallUpdate();
Process.Start(path, _app.Arguments);
_app.Exit();

var basePath = AppDomain.CurrentDomain.BaseDirectory;
var path = Directory.EnumerateFiles(basePath, "OpenTabletDriver.UI*").FirstOrDefault(); // 0.7.x avalonia mirgration
path ??= SystemInterop.CurrentPlatform switch
{
SystemPlatform.Windows => Path.Join(basePath, "OpenTabletDriver.UX.Wpf.exe"),
SystemPlatform.MacOS => Path.Join(basePath, "OpenTabletDriver.UX.MacOS"),
_ => throw new NotSupportedException("Unsupported platform")
};

_app.StopDaemon();
Application.Instance.MainForm.Close();

Process.Start(path);

if (Application.Instance.QuitIsSupported)
Application.Instance.Quit();
else
Environment.Exit(0);
}
}
}

0 comments on commit 2528b6e

Please sign in to comment.