feat(desktop): add Windows NSIS installer (#12869)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -335,6 +335,16 @@ jobs:
|
||||
Write-Output "Signature valid: $file"
|
||||
}
|
||||
|
||||
- name: Upload signed distribution
|
||||
if: ${{ inputs.windows_variant != 'cuda' }}
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: internal-windows-signed
|
||||
path: dist-windows/
|
||||
if-no-files-found: error
|
||||
retention-days: 1
|
||||
overwrite: true
|
||||
|
||||
- name: Create Windows zip package
|
||||
shell: bash
|
||||
env:
|
||||
@@ -374,3 +384,123 @@ jobs:
|
||||
path: Goose-win32-x64${{ inputs.windows_variant == 'cuda' && '-cuda' || '' }}.zip
|
||||
if-no-files-found: error
|
||||
overwrite: true
|
||||
|
||||
# Wraps the flat distribution in the NSIS installer. The uninstaller is generated during the
|
||||
# build, so a signing run signs it and the setup executable through the electron-builder hook
|
||||
# with the account the signing job used for the app executables.
|
||||
package-installer-windows:
|
||||
name: Package Installer (Windows)
|
||||
needs: [build-desktop-windows, sign-desktop-windows]
|
||||
if: ${{ !cancelled() && inputs.package_desktop && inputs.windows_variant != 'cuda' && needs.build-desktop-windows.result == 'success' && (!inputs.signing || needs.sign-desktop-windows.result == 'success') }}
|
||||
runs-on: windows-latest
|
||||
environment: ${{ inputs.signing && inputs.environment || '' }}
|
||||
permissions:
|
||||
id-token: write
|
||||
# Non-blocking until the first installer release is verified: a failure here must not
|
||||
# fail the called workflow and skip the release job, which then finds no installer to upload.
|
||||
continue-on-error: true
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
ref: ${{ inputs.ref != '' && inputs.ref || '' }}
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
||||
with:
|
||||
node-version: 24.10.0
|
||||
|
||||
- name: Update desktop version
|
||||
if: ${{ inputs.version != '' }}
|
||||
shell: bash
|
||||
env:
|
||||
VERSION: ${{ inputs.version }}
|
||||
run: |
|
||||
cd ui/desktop
|
||||
npm pkg set "version=${VERSION}"
|
||||
|
||||
- name: Install pnpm
|
||||
run: npm install -g pnpm@10.30.3
|
||||
|
||||
- name: Cache node_modules
|
||||
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
||||
with:
|
||||
path: |
|
||||
node_modules
|
||||
ui/desktop/node_modules
|
||||
.hermit/node/cache
|
||||
key: windows-pnpm-cache-v1-${{ runner.os }}-node24-${{ hashFiles('**/pnpm-lock.yaml') }}
|
||||
restore-keys: |
|
||||
windows-pnpm-cache-v1-${{ runner.os }}-node24-
|
||||
|
||||
- name: Force GitHub HTTPS for npm git dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
git config --global url."https://github.com/".insteadOf "ssh://git@github.com/"
|
||||
git config --global url."https://github.com/".insteadOf "git@github.com:"
|
||||
git config --global url."https://github.com/".insteadOf "git+ssh://git@github.com/"
|
||||
|
||||
- name: Install desktop dependencies
|
||||
shell: bash
|
||||
run: |
|
||||
cd ui/desktop
|
||||
pnpm install --frozen-lockfile
|
||||
|
||||
- name: Download distribution
|
||||
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
|
||||
with:
|
||||
name: ${{ inputs.signing && 'internal-windows-signed' || 'internal-windows-unsigned' }}
|
||||
path: dist-windows
|
||||
|
||||
- name: Build Windows installer
|
||||
if: ${{ !inputs.signing }}
|
||||
shell: bash
|
||||
run: |
|
||||
cd ui/desktop
|
||||
pnpm run make:win32-installer ../../dist-windows
|
||||
|
||||
- name: Azure login
|
||||
if: ${{ inputs.signing }}
|
||||
uses: azure/login@7ddb5af1ef8758cf1353cf3b42f940aee27ba21c # v3.0.2
|
||||
with:
|
||||
client-id: ${{ secrets.AZURE_CLIENT_ID }}
|
||||
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
|
||||
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
|
||||
|
||||
- name: Install Artifact Signing module
|
||||
if: ${{ inputs.signing }}
|
||||
shell: pwsh
|
||||
run: Install-Module -Name ArtifactSigning -RequiredVersion 0.1.8 -Force -Repository PSGallery
|
||||
|
||||
- name: Build and sign Windows installer
|
||||
if: ${{ inputs.signing }}
|
||||
shell: bash
|
||||
env:
|
||||
AZURE_SIGNING_ENDPOINT: ${{ secrets.AZURE_SIGNING_ENDPOINT }}
|
||||
AZURE_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_SIGNING_ACCOUNT_NAME }}
|
||||
AZURE_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_CERTIFICATE_PROFILE_NAME }}
|
||||
run: |
|
||||
cd ui/desktop
|
||||
pnpm run make:win32-installer ../../dist-windows -c.win.signtoolOptions.sign=./scripts/sign-windows-installer.js
|
||||
|
||||
- name: Verify signed installer and uninstaller
|
||||
if: ${{ inputs.signing }}
|
||||
shell: pwsh
|
||||
run: |
|
||||
$setup = (Resolve-Path "ui/desktop/out/make/nsis/win32/x64/Goose-win32-x64-setup.exe").Path
|
||||
Start-Process -FilePath $setup -ArgumentList "/S" -Wait
|
||||
$files = @($setup, "$env:LOCALAPPDATA\Programs\Goose\Uninstall Goose.exe")
|
||||
foreach ($file in $files) {
|
||||
Write-Output "Verifying signature: $file"
|
||||
$sig = Get-AuthenticodeSignature $file
|
||||
if ($sig.Status -ne "Valid") { throw "Signature invalid for ${file}: $($sig.Status)" }
|
||||
Write-Output "Signature valid: $file"
|
||||
}
|
||||
|
||||
- name: Upload Windows installer
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: Goose-win32-x64-setup
|
||||
path: ui/desktop/out/make/nsis/win32/x64/Goose-win32-x64-setup.exe
|
||||
if-no-files-found: error
|
||||
overwrite: true
|
||||
|
||||
@@ -133,6 +133,26 @@ jobs:
|
||||
- name: Generate macOS update manifest
|
||||
run: node ui/desktop/scripts/generate-mac-update-manifest.js --version "${GITHUB_REF_NAME}" --directory .
|
||||
|
||||
# Only copies set up by the Windows installer request installer.yml, so it needs no
|
||||
# rollout flag: ZIP copies request latest.yml, which is never published for Windows.
|
||||
# Non-blocking until the first installer release is verified: the setup EXE and
|
||||
# installer.yml are attested and uploaded by their own steps, each only after the
|
||||
# previous one succeeded.
|
||||
- name: Generate Windows update manifest
|
||||
id: windows-manifest
|
||||
continue-on-error: true
|
||||
run: node ui/desktop/scripts/generate-windows-update-manifest.js --version "${GITHUB_REF_NAME}" --directory .
|
||||
|
||||
- name: Attest Windows installer
|
||||
id: attest-windows-installer
|
||||
if: ${{ steps.windows-manifest.outcome == 'success' }}
|
||||
continue-on-error: true
|
||||
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
|
||||
with:
|
||||
subject-path: |
|
||||
Goose-win32-x64-setup.exe
|
||||
installer.yml
|
||||
|
||||
- name: Attest macOS update manifest
|
||||
if: ${{ env.ENABLE_MAC_NATIVE_AUTO_UPDATE == 'true' }}
|
||||
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
|
||||
@@ -200,3 +220,12 @@ jobs:
|
||||
run: |
|
||||
gh release upload "${GITHUB_REF_NAME}" latest-mac.yml --clobber
|
||||
gh release upload stable latest-mac.yml --clobber
|
||||
|
||||
- name: Upload Windows installer
|
||||
if: ${{ steps.attest-windows-installer.outcome == 'success' }}
|
||||
continue-on-error: true
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh release upload "${GITHUB_REF_NAME}" Goose-win32-x64-setup.exe installer.yml --clobber
|
||||
gh release upload stable Goose-win32-x64-setup.exe installer.yml --clobber
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
@@ -0,0 +1,4 @@
|
||||
# Per-user only: force the current-user mode so the wizard never offers a per-machine install.
|
||||
!macro customInstallMode
|
||||
StrCpy $isForceCurrentInstall "1"
|
||||
!macroend
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 151 KiB |
@@ -0,0 +1,41 @@
|
||||
# NSIS installer for the Windows desktop app. electron-builder wraps the directory that
|
||||
# electron-forge packaged (pnpm run make:win32-installer <dir>), so the ZIP output and the
|
||||
# swap updater that ZIP copies use are unchanged. electron-builder never packs or signs the app.
|
||||
|
||||
# Also the shortcut AppUserModelID and the registry key the install is recorded under. Matches
|
||||
# the macOS bundle identifier electron-packager derives from the product name. Updates and
|
||||
# uninstalls find the existing install through it, so it must never change.
|
||||
appId: com.electron.goose
|
||||
# Publisher shown by Apps & features, the same as the deb and rpm maintainer. Injected here so
|
||||
# package.json and the forge build stay unchanged.
|
||||
extraMetadata:
|
||||
author:
|
||||
name: AAIF (Agentic AI Foundation)
|
||||
directories:
|
||||
output: out/make/nsis/win32/x64
|
||||
# release.yml generates installer.yml from the published setup executable instead.
|
||||
publish: null
|
||||
win:
|
||||
target:
|
||||
- target: nsis
|
||||
arch:
|
||||
- x64
|
||||
icon: src/images/icon.ico
|
||||
signtoolOptions:
|
||||
# The signing job passes a sign hook on the command line. sha256 only means one call per file.
|
||||
signingHashAlgorithms:
|
||||
- sha256
|
||||
nsis:
|
||||
oneClick: false
|
||||
perMachine: false
|
||||
allowToChangeInstallationDirectory: true
|
||||
include: electron-builder.nsis.nsh
|
||||
# Both bitmaps are scaled from the docs site logo assets (documentation/static/img) on the
|
||||
# site's light background: the 164x314 welcome and finish sidebar stacks the glyph over the
|
||||
# wordmark, the 150x57 page header is the horizontal lockup.
|
||||
installerSidebar: electron-builder.nsis.sidebar.bmp
|
||||
installerHeader: electron-builder.nsis.header.bmp
|
||||
artifactName: ${productName}-win32-x64-setup.${ext}
|
||||
differentialPackage: false
|
||||
# Per-user updates never elevate, and packing the helper would write into the packaged directory.
|
||||
packElevateHelper: false
|
||||
@@ -19,6 +19,7 @@
|
||||
"start:test-error": "GOOSE_TEST_ERROR=true electron-forge start",
|
||||
"package": "pnpm run build-goose-acp-client && pnpm run i18n:compile && electron-forge package",
|
||||
"make": "pnpm run build-goose-acp-client && pnpm run i18n:compile && electron-forge make",
|
||||
"make:win32-installer": "electron-builder --win --config electron-builder.nsis.yml --publish never --prepackaged",
|
||||
"bundle:default": "node scripts/prepare-platform-binaries.js && pnpm run make && BUNDLE_NAME=\"${GOOSE_BUNDLE_NAME:-Goose}\" && APP_DIR=\"out/${BUNDLE_NAME}-darwin-arm64\" && APP_BUNDLE=\"${APP_DIR}/${BUNDLE_NAME}.app\" && (cd \"$APP_DIR\" && ditto -c -k --sequesterRsrc --keepParent \"${BUNDLE_NAME}.app\" \"${BUNDLE_NAME}.zip\")",
|
||||
"bundle:intel": "node scripts/prepare-platform-binaries.js && pnpm run make --arch=x64 && BUNDLE_NAME=\"${GOOSE_BUNDLE_NAME:-Goose}\" && APP_DIR=\"out/${BUNDLE_NAME}-darwin-x64\" && APP_BUNDLE=\"${APP_DIR}/${BUNDLE_NAME}.app\" && (cd \"$APP_DIR\" && ditto -c -k --sequesterRsrc --keepParent \"${BUNDLE_NAME}.app\" \"${BUNDLE_NAME}_intel_mac.zip\")",
|
||||
"debug": "echo 'run --remote-debugging-port=8315' && BUNDLE_NAME=\"${GOOSE_BUNDLE_NAME:-Goose}\" && lldb \"out/${BUNDLE_NAME}-darwin-arm64/${BUNDLE_NAME}.app\"",
|
||||
@@ -147,6 +148,7 @@
|
||||
"@vitest/ui": "^4.1.10",
|
||||
"autoprefixer": "^10.5.4",
|
||||
"electron": "43.4.0",
|
||||
"electron-builder": "26.15.3",
|
||||
"electron-devtools-installer": "^4.0.0",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-plugin-react": "^7.37.5",
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const crypto = require('node:crypto');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
// Copies set up by the Windows installer request this manifest (the channel set in
|
||||
// src/utils/autoUpdater.ts). ZIP copies request latest.yml, which is never published for
|
||||
// Windows, so they stay on the swap updater.
|
||||
const MANIFEST_NAME = 'installer.yml';
|
||||
const INSTALLER_NAME = 'Goose-win32-x64-setup.exe';
|
||||
|
||||
function usage() {
|
||||
console.error(
|
||||
'Usage: node scripts/generate-windows-update-manifest.js --version <version> [--directory <path>]'
|
||||
);
|
||||
}
|
||||
|
||||
function parseArgs(argv) {
|
||||
const args = {
|
||||
directory: process.cwd(),
|
||||
version: '',
|
||||
};
|
||||
|
||||
for (let i = 0; i < argv.length; i += 1) {
|
||||
const arg = argv[i];
|
||||
if (arg === '--version') {
|
||||
args.version = argv[++i] || '';
|
||||
} else if (arg === '--directory') {
|
||||
args.directory = argv[++i] || '';
|
||||
} else {
|
||||
usage();
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!args.version || !args.directory) {
|
||||
usage();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
args.version = args.version.replace(/^v/, '');
|
||||
args.directory = path.resolve(args.directory);
|
||||
return args;
|
||||
}
|
||||
|
||||
function sha512(filePath) {
|
||||
const hash = crypto.createHash('sha512');
|
||||
hash.update(fs.readFileSync(filePath));
|
||||
return hash.digest('base64');
|
||||
}
|
||||
|
||||
function yamlString(value) {
|
||||
return JSON.stringify(value);
|
||||
}
|
||||
|
||||
function writeManifest({ directory, version }) {
|
||||
const installerPath = path.join(directory, INSTALLER_NAME);
|
||||
if (!fs.existsSync(installerPath)) {
|
||||
throw new Error(`Missing required file: ${installerPath}`);
|
||||
}
|
||||
|
||||
const digest = sha512(installerPath);
|
||||
const manifest = [
|
||||
`version: ${yamlString(version)}`,
|
||||
'files:',
|
||||
` - url: ${yamlString(INSTALLER_NAME)}`,
|
||||
` sha512: ${yamlString(digest)}`,
|
||||
` size: ${fs.statSync(installerPath).size}`,
|
||||
`path: ${yamlString(INSTALLER_NAME)}`,
|
||||
`sha512: ${yamlString(digest)}`,
|
||||
`releaseDate: ${yamlString(new Date().toISOString())}`,
|
||||
'',
|
||||
].join('\n');
|
||||
|
||||
fs.writeFileSync(path.join(directory, MANIFEST_NAME), manifest);
|
||||
}
|
||||
|
||||
try {
|
||||
writeManifest(parseArgs(process.argv.slice(2)));
|
||||
} catch (error) {
|
||||
console.error(error instanceof Error ? error.message : error);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// electron-builder sign hook for the NSIS uninstaller and setup executable. The uninstaller is
|
||||
// generated mid-build, so the signing job cannot sign it with the workflow action that signs the
|
||||
// app executables. This runs the same cmdlet with the same arguments as that action, so every
|
||||
// executable the installer ships carries the same signature.
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
const settings = {
|
||||
Endpoint: 'AZURE_SIGNING_ENDPOINT',
|
||||
CodeSigningAccountName: 'AZURE_SIGNING_ACCOUNT_NAME',
|
||||
CertificateProfileName: 'AZURE_CERTIFICATE_PROFILE_NAME',
|
||||
};
|
||||
|
||||
// The credential types the action excludes by default. The job signs in through the Azure CLI.
|
||||
const excludedCredentials = [
|
||||
'WorkloadIdentity',
|
||||
'ManagedIdentity',
|
||||
'SharedTokenCache',
|
||||
'VisualStudio',
|
||||
'VisualStudioCode',
|
||||
'AzurePowerShell',
|
||||
'AzureDeveloperCli',
|
||||
'InteractiveBrowser',
|
||||
];
|
||||
|
||||
function quote(value) {
|
||||
return `'${value.replace(/'/g, "''")}'`;
|
||||
}
|
||||
|
||||
exports.default = async ({ path }) => {
|
||||
const missing = Object.values(settings).filter((name) => !process.env[name]);
|
||||
if (missing.length > 0) {
|
||||
throw new Error(`Cannot sign ${path}: ${missing.join(', ')} not set`);
|
||||
}
|
||||
|
||||
const command = [
|
||||
'Invoke-ArtifactSigning',
|
||||
...Object.entries(settings).map(([param, name]) => `-${param} ${quote(process.env[name])}`),
|
||||
`-Files ${quote(path)}`,
|
||||
'-FileDigest SHA256',
|
||||
'-TimestampRfc3161 http://timestamp.acs.microsoft.com',
|
||||
'-TimestampDigest SHA256',
|
||||
...excludedCredentials.map((name) => `-Exclude${name}Credential`),
|
||||
].join(' ');
|
||||
|
||||
const result = spawnSync('pwsh', ['-NoProfile', '-NonInteractive', '-Command', command], {
|
||||
stdio: 'inherit',
|
||||
});
|
||||
if (result.error) {
|
||||
throw result.error;
|
||||
}
|
||||
if (result.status !== 0) {
|
||||
throw new Error(`Invoke-ArtifactSigning exited with ${result.status} for ${path}`);
|
||||
}
|
||||
};
|
||||
@@ -2,3 +2,5 @@ provider: github
|
||||
owner: aaif-goose
|
||||
repo: goose
|
||||
updaterCacheDirName: goose-updater
|
||||
publisherName:
|
||||
- 'CN="LF Open Source, LLC", O="LF Open Source, LLC", L=Laguna Beach, S=California, C=US'
|
||||
|
||||
@@ -295,6 +295,12 @@ function listGitWorktreeDirs(dir: string): Promise<string[]> {
|
||||
|
||||
if (started) app.quit();
|
||||
|
||||
// The installer's shortcuts carry this AppUserModelID (electron-builder appId). The running app
|
||||
// must use the same one so Windows groups it with them on the taskbar and shows its notifications.
|
||||
if (process.platform === 'win32') {
|
||||
app.setAppUserModelId('com.electron.goose');
|
||||
}
|
||||
|
||||
// Certificate trust for active backend leases. Renderer requests and
|
||||
// main-process net.fetch both pin to the exact cert fingerprint. Each backend
|
||||
// lease owns a trust record so old windows keep working after settings change.
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs/promises';
|
||||
import log from './logger';
|
||||
import { githubUpdater } from './githubUpdater';
|
||||
import { githubUpdater, isInstallerManaged } from './githubUpdater';
|
||||
import { loadRecentDirs } from './recentDirs';
|
||||
import { errorMessage } from './conversionUtils';
|
||||
import {
|
||||
@@ -56,6 +56,18 @@ export function getAutoDownloadDisabled(): boolean {
|
||||
return autoDownloadDisabled;
|
||||
}
|
||||
|
||||
// A copy set up by the Windows installer updates by running the next installer, so it never
|
||||
// uses the GitHub fallback: the fallback's directory swap would delete the uninstaller.
|
||||
function canUseGithubFallback(error: Error): boolean {
|
||||
return (
|
||||
!isInstallerManaged(app.getPath('exe')) &&
|
||||
(error.message.includes('HttpError: 404') ||
|
||||
error.message.includes('ERR_CONNECTION_REFUSED') ||
|
||||
error.message.includes('ENOTFOUND') ||
|
||||
error.message.includes('No published versions'))
|
||||
);
|
||||
}
|
||||
|
||||
// Register IPC handlers (only once)
|
||||
export function registerUpdateIpcHandlers() {
|
||||
if (ipcUpdateHandlersRegistered) {
|
||||
@@ -121,13 +133,7 @@ export function registerUpdateIpcHandlers() {
|
||||
});
|
||||
|
||||
// If electron-updater fails, try GitHub API fallback
|
||||
if (
|
||||
error instanceof Error &&
|
||||
(error.message.includes('HttpError: 404') ||
|
||||
error.message.includes('ERR_CONNECTION_REFUSED') ||
|
||||
error.message.includes('ENOTFOUND') ||
|
||||
error.message.includes('No published versions'))
|
||||
) {
|
||||
if (error instanceof Error && canUseGithubFallback(error)) {
|
||||
log.info('Using GitHub API fallback in check-for-updates...');
|
||||
log.info('Manual fallback triggered by error:', error.message);
|
||||
isUsingGitHubFallback = true;
|
||||
@@ -341,6 +347,9 @@ export function setupAutoUpdater() {
|
||||
owner: 'aaif-goose',
|
||||
repo: 'goose',
|
||||
releaseType: 'release' as const,
|
||||
// The installer manifest has its own name (scripts/generate-windows-update-manifest.js) so
|
||||
// ZIP copies, which request latest.yml, are never moved onto the installer.
|
||||
...(isInstallerManaged(app.getPath('exe')) ? { channel: 'installer' } : {}),
|
||||
};
|
||||
|
||||
log.info('Setting feed URL with config:', feedConfig);
|
||||
@@ -443,12 +452,7 @@ export function setupAutoUpdater() {
|
||||
});
|
||||
|
||||
// If electron-updater fails, try GitHub API as fallback
|
||||
if (
|
||||
err.message.includes('HttpError: 404') ||
|
||||
err.message.includes('ERR_CONNECTION_REFUSED') ||
|
||||
err.message.includes('ENOTFOUND') ||
|
||||
err.message.includes('No published versions')
|
||||
) {
|
||||
if (canUseGithubFallback(err)) {
|
||||
log.info('Using GitHub API fallback for startup update check...');
|
||||
log.info('Fallback triggered by error containing:', err.message);
|
||||
isUsingGitHubFallback = true;
|
||||
@@ -568,12 +572,7 @@ export function setupAutoUpdater() {
|
||||
});
|
||||
|
||||
// Check if this is a 404 error (missing update files) or connection error
|
||||
if (
|
||||
err.message.includes('HttpError: 404') ||
|
||||
err.message.includes('ERR_CONNECTION_REFUSED') ||
|
||||
err.message.includes('ENOTFOUND') ||
|
||||
err.message.includes('No published versions')
|
||||
) {
|
||||
if (canUseGithubFallback(err)) {
|
||||
log.info('Falling back to GitHub API for update check...');
|
||||
log.info('Fallback triggered by error:', err.message);
|
||||
isUsingGitHubFallback = true;
|
||||
|
||||
@@ -120,4 +120,14 @@ describe('resolveInstallTarget', () => {
|
||||
/Refusing to auto-update/
|
||||
);
|
||||
});
|
||||
|
||||
it('refuses to update a copy set up by the Windows installer', async () => {
|
||||
setPlatform('win32');
|
||||
const root = await makeTempDir();
|
||||
const exePath = await makeInstallDir(root, 'Goose');
|
||||
const uninstaller = `Uninstall ${path.basename(exePath, '.exe')}.exe`;
|
||||
await fs.writeFile(path.join(path.dirname(exePath), uninstaller), 'binary');
|
||||
|
||||
await expect(resolveInstallTarget(exePath)).rejects.toThrow(/was set up by the installer/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import { compareVersions } from 'compare-versions';
|
||||
import { z } from 'zod';
|
||||
import { spawn } from 'child_process';
|
||||
import * as fs from 'fs/promises';
|
||||
import { existsSync } from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import log from './logger';
|
||||
@@ -170,6 +171,16 @@ async function pathExists(target: string): Promise<boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
// electron-builder's NSIS installer writes its uninstaller beside the executable. A copy it set
|
||||
// up updates by running the next installer; replacing its directory would delete the uninstaller.
|
||||
export function isInstallerManaged(exePath: string): boolean {
|
||||
if (process.platform !== 'win32') {
|
||||
return false;
|
||||
}
|
||||
const uninstaller = `Uninstall ${path.basename(exePath, '.exe')}.exe`;
|
||||
return existsSync(path.join(path.dirname(exePath), uninstaller));
|
||||
}
|
||||
|
||||
function isSharedDirectory(dir: string): boolean {
|
||||
if (dir === path.parse(dir).root) {
|
||||
return true;
|
||||
@@ -243,6 +254,10 @@ export async function resolveInstallTarget(exePath: string): Promise<InstallTarg
|
||||
|
||||
const installDir = path.dirname(resolvedExePath);
|
||||
|
||||
if (isInstallerManaged(resolvedExePath)) {
|
||||
throw new Error(`Refusing to auto-update: ${installDir} was set up by the installer`);
|
||||
}
|
||||
|
||||
if (!(await isPackagedAppDirectory(installDir))) {
|
||||
throw new Error(
|
||||
`Refusing to auto-update: ${installDir} does not look like an app install directory`
|
||||
|
||||
Generated
+711
-43
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user