Skip to content

Added checkbox to clean app data on uninstall #5348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions electron-builder/base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const base = {
nsis: {
license: 'AGREEMENT',
oneClick: false,
warningsAsErrors: false,
perMachine: true,
allowToChangeInstallationDirectory: true,
include: 'installer.nsh',
Expand Down
35 changes: 32 additions & 3 deletions installer.nsh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
!include MUI2.nsh

!macro customInstall
NSISdl::download https://aka.ms/vs/17/release/vc_redist.x64.exe "$INSTDIR\vc_redist.x64.exe"
NSISdl::download https://aka.ms/vs/17/release/vc_redist.x64.exe "$INSTDIR\vc_redist.x64.exe"

${If} ${FileExists} `$INSTDIR\vc_redist.x64.exe`
ExecWait '$INSTDIR\vc_redist.x64.exe /passive /norestart' $1

${If} $1 != '0'
${If} $1 != '0'
${If} $1 != '3010'
MessageBox MB_OK|MB_ICONEXCLAMATION 'WARNING: Streamlabs was unable to install the latest Visual C++ Redistributable package from Microsoft.'
${EndIf}
Expand All @@ -22,3 +24,30 @@
FileWrite $0 $EXEFILE
FileClose $0
!macroend

; Custom uninstall welcome page
!define MUI_PAGE_CUSTOMFUNCTION_SHOW un.ModifyUnWelcome
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE un.LeaveUnWelcome
!insertmacro MUI_UNPAGE_WELCOME

Var /GLOBAL cleanupCheckbox

Function un.ModifyUnWelcome
${NSD_CreateCheckbox} 120u -18u 50% 12u "Clean application data"
Pop $cleanupCheckbox

SetCtlColors $cleanupCheckbox 0x000000 0xffffff
${NSD_Check} $cleanupCheckbox
FunctionEnd

Function un.LeaveUnWelcome
${NSD_GetState} $cleanupCheckbox $0
${If} $0 <> 0
RMDir /r "$PROFILE\\AppData\\Roaming\\slobs-client"
RMDir /r "$PROFILE\\AppData\\Roaming\\slobs-plugins"
RMDir /r "$PROFILE\\AppData\\Roaming\\streamlabs-highlighter"
; REBOOTOK flag is required, because files might get injected into a game process and system may prevent their removal
; see: https://nsis.sourceforge.io/Reference/RMDir
RMDir /r /REBOOTOK "C:\\ProgramData\\obs-studio-hook"
${EndIf}
FunctionEnd
41 changes: 41 additions & 0 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,44 @@ const antdlibSettings = JSON.parse(fs.readFileSync(antdLibSettingsPath, 'utf8'))
delete antdlibSettings.module;
antdlibSettings.main = 'dist/antd.min.js';
fs.writeFileSync(antdLibSettingsPath, JSON.stringify(antdlibSettings, null, 2));


// The code below is needed to provide a better uninstall experience.
// Here we patch assistedInstaller.nsh to avoid redundant uninstaller welcome page.
// When we upgrade electron-builder package to at least 23.0.6 we need to use the removeDefaultUninstallWelcomePage
// option and the code below can be removed.
// @see https://stackoverflow.com/questions/73454796/default-unwelcome-page-with-electron-builder-nsis-cant-be-changed-or-removed
const assistedInstallerPath = path.resolve('./node_modules/app-builder-lib/templates/nsis/assistedInstaller.nsh');

// Function to read, modify, and write without closing the file
const commentLineInFile = (assistedInstallerPath, lineToComment, commentString = ';') => {
let fd;

try {
fd = fs.openSync(assistedInstallerPath, 'r+');

const fileContent = fs.readFileSync(fd, 'utf-8');
const modifiedContent = fileContent
.split('\n')
.map((line) => {
if (line.includes(lineToComment) && !line.trim().startsWith(';')) {
return `${commentString}${line}`; // Add commentString to the target line
}
return line; // Leave all other lines unchanged
})
.join('\n'); // Rejoin the lines back together into a single string

fs.ftruncateSync(fd); // Truncate the file to ensure old content is removed
fs.writeSync(fd, modifiedContent);

console.log(`Post install. Successfully commented "${lineToComment}" in file: ${assistedInstallerPath}`);
} catch (error) {
console.error(`Post install. An error occurred while processing the file: ${error.message}`);
} finally {
if (fd !== undefined) {
fs.closeSync(fd);
}
}
};

commentLineInFile(assistedInstallerPath, '!insertmacro MUI_UNPAGE_WELCOME');
Loading