Skip to content

Commit d3d1c8d

Browse files
committed
feat(installer): allow deleting user data on uninstall
1 parent d4828b1 commit d3d1c8d

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

desktop/scripts/installer-custom.nsh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,78 @@ Function WDA_InstallDirPageLeave
7878
FunctionEnd
7979

8080
!endif
81+
82+
!ifdef BUILD_UNINSTALLER
83+
!include nsDialogs.nsh
84+
!include LogicLib.nsh
85+
86+
Var WDA_UninstallOptionsPage
87+
Var WDA_UninstallDeleteDataCheckbox
88+
Var /GLOBAL WDA_DeleteUserData
89+
90+
!macro customUnInit
91+
; Default: keep user data (also applies to silent uninstall / update uninstall).
92+
StrCpy $WDA_DeleteUserData "0"
93+
!macroend
94+
95+
!macro customUnWelcomePage
96+
!insertmacro MUI_UNPAGE_WELCOME
97+
; Optional page: allow user to choose whether to delete app data.
98+
UninstPage custom un.WDA_UninstallOptionsCreate un.WDA_UninstallOptionsLeave
99+
!macroend
100+
101+
Function un.WDA_UninstallOptionsCreate
102+
nsDialogs::Create 1018
103+
Pop $WDA_UninstallOptionsPage
104+
105+
${If} $WDA_UninstallOptionsPage == error
106+
Abort
107+
${EndIf}
108+
109+
${NSD_CreateLabel} 0u 0u 100% 24u "卸载选项:"
110+
Pop $0
111+
112+
${NSD_CreateCheckbox} 0u 24u 100% 12u "同时删除用户数据(导出的聊天记录、日志、配置等)"
113+
Pop $WDA_UninstallDeleteDataCheckbox
114+
; Safer default: do not delete.
115+
${NSD_Uncheck} $WDA_UninstallDeleteDataCheckbox
116+
117+
nsDialogs::Show
118+
FunctionEnd
119+
120+
Function un.WDA_UninstallOptionsLeave
121+
${NSD_GetState} $WDA_UninstallDeleteDataCheckbox $0
122+
${If} $0 == ${BST_CHECKED}
123+
StrCpy $WDA_DeleteUserData "1"
124+
${Else}
125+
StrCpy $WDA_DeleteUserData "0"
126+
${EndIf}
127+
FunctionEnd
128+
129+
!macro customUnInstall
130+
; If this is an update uninstall, never delete user data.
131+
${ifNot} ${isUpdated}
132+
${if} $WDA_DeleteUserData == "1"
133+
; Electron always stores user data per-user. If the app was installed for all users,
134+
; switch to current user context to remove the correct AppData directory.
135+
${if} $installMode == "all"
136+
SetShellVarContext current
137+
${endif}
138+
139+
RMDir /r "$APPDATA\${APP_FILENAME}"
140+
!ifdef APP_PRODUCT_FILENAME
141+
RMDir /r "$APPDATA\${APP_PRODUCT_FILENAME}"
142+
!endif
143+
; Electron may use package.json "name" for some storage (cache, indexeddb, etc.).
144+
!ifdef APP_PACKAGE_NAME
145+
RMDir /r "$APPDATA\${APP_PACKAGE_NAME}"
146+
!endif
147+
148+
${if} $installMode == "all"
149+
SetShellVarContext all
150+
${endif}
151+
${endif}
152+
${endif}
153+
!macroend
154+
155+
!endif

0 commit comments

Comments
 (0)