Skip to content

Commit

Permalink
fix: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Pd233 committed Mar 6, 2024
1 parent 1a75c28 commit 8e5de7a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 44 deletions.
26 changes: 20 additions & 6 deletions src/AutoUpdate/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,33 @@
var logger = factory.CreateLogger("AutoUpdate");

var lipuiDirOption = new Option<string>("--lipui-dir", "LipUI directory")
{
IsRequired = true,
};
var lipuiPid = new Option<int>("--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;
}
Expand All @@ -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);
11 changes: 2 additions & 9 deletions src/LipUI/Models/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
39 changes: 15 additions & 24 deletions src/LipUI/Pages/Settings/SettingsAndAboutView.xaml.cs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
});
}
}
}
10 changes: 5 additions & 5 deletions tooth.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": [
{
Expand All @@ -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": [
{
Expand All @@ -43,7 +43,7 @@
},
"commands": {
"post-install": [
".\\LipUI.exe"
"CMD.exe /c ./LipUI.exe"
]
}
}
Expand Down

0 comments on commit 8e5de7a

Please sign in to comment.