Skip to content

Commit 65cf2b5

Browse files
committed
v1.2.8
- Fixed update process for portable vs WinGet installs
1 parent 9c8f73c commit 65cf2b5

6 files changed

Lines changed: 187 additions & 43 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "claude-code-usage-monitor"
3-
version = "1.2.7"
3+
version = "1.2.8"
44
edition = "2021"
55
license = "MIT"
66
description = "Windows taskbar widget for monitoring Claude Code usage and rate limits"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ What the app stores locally:
104104
- Widget position
105105
- Polling frequency
106106
- Language preference
107+
- Last update check time
107108

108109
What it does **not** do:
109110

src/native_interop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub const WINEVENT_OUTOFCONTEXT: u32 = 0x0000;
1717
pub const TIMER_POLL: usize = 1;
1818
pub const TIMER_COUNTDOWN: usize = 2;
1919
pub const TIMER_RESET_POLL: usize = 3;
20+
pub const TIMER_UPDATE_CHECK: usize = 4;
2021

2122
// Custom messages
2223
pub const WM_APP: u32 = 0x8000;

src/updater.rs

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,19 @@ pub fn check_for_updates() -> Result<UpdateCheckResult, String> {
8484
}
8585

8686
pub fn begin_winget_update() -> Result<(), String> {
87-
let command = winget_upgrade_command();
87+
let current_exe =
88+
std::env::current_exe().map_err(|e| format!("Unable to locate current executable: {e}"))?;
89+
let current_dir = current_exe
90+
.parent()
91+
.ok_or_else(|| "Unable to determine the app directory for restart.".to_string())?;
92+
let command = winget_upgrade_command(
93+
std::process::id(),
94+
&current_exe.to_string_lossy(),
95+
&current_dir.to_string_lossy(),
96+
);
97+
8898
Command::new("powershell.exe")
8999
.arg("-NoLogo")
90-
.arg("-NoExit")
91100
.arg("-Command")
92101
.arg(&command)
93102
.creation_flags(CREATE_NEW_CONSOLE)
@@ -335,8 +344,39 @@ fn updates_dir() -> Result<PathBuf, String> {
335344
.ok_or_else(|| "Unable to resolve a writable local updates directory.".to_string())
336345
}
337346

338-
fn winget_upgrade_command() -> String {
339-
format!("winget upgrade --id {WINGET_PACKAGE_ID} --exact")
347+
fn winget_upgrade_command(pid: u32, target: &str, working_dir: &str) -> String {
348+
let target = powershell_single_quoted(target);
349+
let working_dir = powershell_single_quoted(working_dir);
350+
let package_id = WINGET_PACKAGE_ID;
351+
352+
format!(
353+
concat!(
354+
"$ErrorActionPreference = 'Stop'; ",
355+
"$pidToWait = {pid}; ",
356+
"$target = '{target}'; ",
357+
"$workingDir = '{working_dir}'; ",
358+
"try {{ Wait-Process -Id $pidToWait -Timeout 30 -ErrorAction Stop }} catch {{ }}; ",
359+
"winget upgrade --id {package_id} --exact; ",
360+
"$exitCode = $LASTEXITCODE; ",
361+
"if ($exitCode -eq 0) {{ ",
362+
"Start-Sleep -Seconds 2; ",
363+
"Start-Process -FilePath $target -WorkingDirectory $workingDir; ",
364+
"exit 0 ",
365+
"}}; ",
366+
"Write-Host ''; ",
367+
"Write-Host 'WinGet update failed with exit code' $exitCode; ",
368+
"Read-Host 'Press Enter to close'; ",
369+
"exit $exitCode"
370+
),
371+
pid = pid,
372+
target = target,
373+
working_dir = working_dir,
374+
package_id = package_id,
375+
)
376+
}
377+
378+
fn powershell_single_quoted(value: &str) -> String {
379+
value.replace('\'', "''")
340380
}
341381

342382
fn backup_path_for(target: &Path) -> PathBuf {
@@ -424,10 +464,17 @@ fn winget_install_roots() -> Vec<PathBuf> {
424464
}
425465

426466
fn normalize_path(path: &Path) -> String {
427-
path.to_string_lossy()
467+
let normalized = path
468+
.to_string_lossy()
428469
.replace('/', "\\")
429470
.trim_end_matches('\\')
430-
.to_ascii_lowercase()
471+
.to_ascii_lowercase();
472+
473+
normalized
474+
.strip_prefix("\\\\?\\unc\\")
475+
.map(|rest| format!("\\\\{rest}"))
476+
.or_else(|| normalized.strip_prefix("\\\\?\\").map(str::to_owned))
477+
.unwrap_or(normalized)
431478
}
432479

433480
fn is_version_newer(candidate: &str, current: &str) -> bool {

0 commit comments

Comments
 (0)