Skip to content

Commit 9b24a5c

Browse files
committed
fix: remove Windows app data on uninstall
1 parent d920cdf commit 9b24a5c

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

src-tauri/tauri.conf.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@
5050
"icons/icon.ico",
5151
"icons/icon.png"
5252
],
53+
"windows": {
54+
"nsis": {
55+
"installerHooks": "windows/nsis-hooks.nsh"
56+
}
57+
},
5358
"macOS": {
5459
"entitlements": "Entitlements.plist"
5560
}

src-tauri/tests/nsis_uninstall.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std::{fs, path::Path};
2+
3+
#[test]
4+
fn nsis_hook_deletes_sessionview_data_only_when_requested() {
5+
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
6+
let config_path = manifest_dir.join("tauri.conf.json");
7+
let config: serde_json::Value =
8+
serde_json::from_str(&fs::read_to_string(&config_path).expect("read tauri.conf.json"))
9+
.expect("parse tauri.conf.json");
10+
11+
let hook_relative = config
12+
.pointer("/bundle/windows/nsis/installerHooks")
13+
.and_then(serde_json::Value::as_str)
14+
.expect("NSIS installer hook must be configured");
15+
let hook = fs::read_to_string(manifest_dir.join(hook_relative)).expect("read NSIS hook");
16+
let commands: Vec<&str> = hook
17+
.lines()
18+
.map(str::trim)
19+
.filter(|line| !line.is_empty() && !line.starts_with(';'))
20+
.collect();
21+
22+
assert_eq!(
23+
commands,
24+
[
25+
"!macro NSIS_HOOK_POSTUNINSTALL",
26+
"${If} $DeleteAppDataCheckboxState = 1",
27+
"${AndIf} $UpdateMode <> 1",
28+
"RMDir /r \"$LOCALAPPDATA\\sessionview\"",
29+
"${EndIf}",
30+
"!macroend",
31+
]
32+
);
33+
}

src-tauri/windows/nsis-hooks.nsh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; SessionView stores its database and image cache in
2+
; %LOCALAPPDATA%\sessionview instead of Tauri's bundle-identifier directory.
3+
; Match Tauri's built-in "Delete application data" behavior for that legacy
4+
; location without deleting data during updates or unconfirmed uninstalls.
5+
!macro NSIS_HOOK_POSTUNINSTALL
6+
${If} $DeleteAppDataCheckboxState = 1
7+
${AndIf} $UpdateMode <> 1
8+
RMDir /r "$LOCALAPPDATA\sessionview"
9+
${EndIf}
10+
!macroend

0 commit comments

Comments
 (0)