diff --git a/src/AutoUpdate/Program.cs b/src/AutoUpdate/Program.cs index 1d28622..5b817f5 100644 --- a/src/AutoUpdate/Program.cs +++ b/src/AutoUpdate/Program.cs @@ -6,19 +6,33 @@ var logger = factory.CreateLogger("AutoUpdate"); var lipuiDirOption = new Option("--lipui-dir", "LipUI directory") +{ + IsRequired = true, +}; +var lipuiPid = new Option("--lipui-pid", "LipUI process ID") { IsRequired = true }; -RootCommand rootCommand = [lipuiDirOption]; -rootCommand.SetHandler((lipuiPath) => +RootCommand rootCommand = [lipuiDirOption, lipuiPid]; +rootCommand.SetHandler((lipuiPath, pid) => { + var lipuiProcess = Process.GetProcessById(pid); + + lipuiProcess.Kill(); + lipuiProcess.WaitForExit(); + logger.LogInformation("Waiting for lipui process {pid} to exit", pid); + + Task.Delay(TimeSpan.FromSeconds(2)).Wait(); + + var currentDir = new FileInfo(Environment.ProcessPath!).Directory ?? throw new InvalidOperationException("Current directory not found"); + var lipuiDir = new DirectoryInfo(lipuiPath); - var currentDir = new DirectoryInfo(Directory.GetCurrentDirectory()); if (lipuiDir.FullName == currentDir.FullName) { logger.LogError("LipUI directory cannot be the same as the current directory"); + logger.LogError("lipuiDir: {lipuiDir.FullName} currentDir: {currentDir.FullName}", lipuiDir.FullName, currentDir.FullName); return; } @@ -44,11 +58,11 @@ logger.LogInformation("Moved {file} to {lipuiWorkingDir}", file.Name, lipuiDir.FullName); } - Task.Delay(1000); + Task.Delay(TimeSpan.FromSeconds(2)).Wait(); - Process.Start(lipuiPath); + Process.Start(lipuiExeFile.FullName); Environment.Exit(0); -}, lipuiDirOption); +}, lipuiDirOption, lipuiPid); rootCommand.Invoke(args); \ No newline at end of file diff --git a/src/LipUI/Models/Main.cs b/src/LipUI/Models/Main.cs index 7b73016..ddaf115 100644 --- a/src/LipUI/Models/Main.cs +++ b/src/LipUI/Models/Main.cs @@ -56,15 +56,8 @@ private static void AutoUpdate() return; } - var process = new Process() - { - StartInfo = new(Path.Combine(autoupdateDir.FullName, "AutoUpdate.exe")) - { - Arguments = $"--lipui-dir {ProgramDirectory}" - } - }; - process.Start(); - Application.Current.Exit(); + SaveConfig(); + Process.Start("CMD.exe", $"/c {Path.Combine(autoupdateDir.FullName, "AutoUpdate.exe")} --lipui-dir {ProgramDirectory} --lipui-pid {Environment.ProcessId}"); } [MemberNotNull(nameof(WorkingDirectory), nameof(ProgramDirectory))] diff --git a/src/LipUI/Pages/Settings/SettingsAndAboutView.xaml.cs b/src/LipUI/Pages/Settings/SettingsAndAboutView.xaml.cs index 6946e39..d6befe8 100644 --- a/src/LipUI/Pages/Settings/SettingsAndAboutView.xaml.cs +++ b/src/LipUI/Pages/Settings/SettingsAndAboutView.xaml.cs @@ -1,20 +1,7 @@ using LipUI.Models; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; -using Microsoft.UI.Xaml.Controls.Primitives; -using Microsoft.UI.Xaml.Data; -using Microsoft.UI.Xaml.Input; -using Microsoft.UI.Xaml.Media; -using Microsoft.UI.Xaml.Navigation; -using System; -using System.Collections.Generic; using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.Foundation; -using Windows.Foundation.Collections; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. @@ -52,18 +39,22 @@ await InternalServices.ShowInfoBarAsync( InternalServices.ShowInfoBar( interval: TimeSpan.FromSeconds(3), - message: $"Running {args}"); - - var process = new Process() - { - StartInfo = new(path) + message: $"Running {args}", + completed: () => { - WorkingDirectory = Main.ProgramDirectory, - Arguments = args, - } - }; - process.Start(); - Application.Current.Exit(); + var process = new Process() + { + StartInfo = new(path) + { + WorkingDirectory = Main.ProgramDirectory, + Arguments = args, + } + }; + + Main.SaveConfig(); + process.Start(); + Environment.Exit(0); + }); } } } diff --git a/tooth.json b/tooth.json index 054b535..2127314 100644 --- a/tooth.json +++ b/tooth.json @@ -1,7 +1,7 @@ { "format_version": 2, "tooth": "github.com/lippkg/LipUI", - "version": "0.4.9", + "version": "0.5.0", "info": { "name": "LipUI", "description": "A GUI client for lip", @@ -14,7 +14,7 @@ { "goos": "windows", "goarch": "amd64", - "asset_url": "https://github.com/lippkg/LipUI/releases/download/v0.4.9/LipUI-win-x64.zip", + "asset_url": "https://github.com/lippkg/LipUI/releases/download/v0.5.0/LipUI-win-x64.zip", "files": { "place": [ { @@ -25,14 +25,14 @@ }, "commands": { "post-install": [ - ".\\LipUI.exe" + "CMD.exe /c ./LipUI.exe" ] } }, { "goos": "windows", "goarch": "arm64", - "asset_url": "https://github.com/lippkg/LipUI/releases/download/v0.4.9/LipUI-win-arm64.zip", + "asset_url": "https://github.com/lippkg/LipUI/releases/download/v0.5.0/LipUI-win-arm64.zip", "files": { "place": [ { @@ -43,7 +43,7 @@ }, "commands": { "post-install": [ - ".\\LipUI.exe" + "CMD.exe /c ./LipUI.exe" ] } }