diff --git a/electron-builder/base.config.js b/electron-builder/base.config.js index f0d9cbbcaf70..78336c5d548a 100644 --- a/electron-builder/base.config.js +++ b/electron-builder/base.config.js @@ -30,6 +30,7 @@ const base = { nsis: { license: 'AGREEMENT', oneClick: false, + warningsAsErrors: false, perMachine: true, allowToChangeInstallationDirectory: true, include: 'installer.nsh', diff --git a/installer.nsh b/installer.nsh index d5ba1a8307ee..c22bbb6553ec 100644 --- a/installer.nsh +++ b/installer.nsh @@ -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} @@ -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 \ No newline at end of file diff --git a/scripts/postinstall.js b/scripts/postinstall.js index 90427af85d0d..0da89786d915 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -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'); \ No newline at end of file