fix: обновление заменяет оригинальный AppImage через detached sh-хелпер
All checks were successful
Release / release (push) Successful in 2m1s
All checks were successful
Release / release (push) Successful in 2m1s
Проблема: copyFileSync на работающий AppImage (примонтированный squashfs) либо падает с ошибкой, либо APPIMAGE env не установлена у интегрированных AppImage — в обоих случаях срабатывал fallback с новым путём → вторая иконка. Решение: spawnUpdateHelper() пишет временный sh-скрипт, запускает его detached и сразу вызывает app.exit(). Хелпер ждёт смерти родителя (kill -0 в цикле), потом cp new → old, chmod +x, exec old. Файл заменяется уже после того как процесс отпустил squashfs-маунт. realpathSync резолвит симлинки перед передачей пути в хелпер. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e76d078dd1
commit
b6062b1e2c
1 changed files with 32 additions and 10 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
import { app, BrowserWindow } from 'electron'
|
import { app, BrowserWindow } from 'electron'
|
||||||
import { createWriteStream, chmodSync, copyFileSync, mkdirSync } from 'fs'
|
import { createWriteStream, chmodSync, mkdirSync, writeFileSync, realpathSync } from 'fs'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { homedir } from 'os'
|
import { homedir, tmpdir } from 'os'
|
||||||
|
import { spawn } from 'child_process'
|
||||||
import https from 'https'
|
import https from 'https'
|
||||||
import http from 'http'
|
import http from 'http'
|
||||||
import { URL } from 'url'
|
import { URL } from 'url'
|
||||||
|
|
@ -88,6 +89,26 @@ function downloadFile(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Запускает детачнутый sh-скрипт, который ждёт смерти текущего процесса,
|
||||||
|
// затем заменяет AppImage по оригинальному пути и запускает его.
|
||||||
|
function spawnUpdateHelper(newPath: string, oldPath: string): void {
|
||||||
|
const scriptPath = join(tmpdir(), 'aero-mail-update.sh')
|
||||||
|
const script = [
|
||||||
|
'#!/bin/sh',
|
||||||
|
'PARENT="$1" NEW="$2" OLD="$3"',
|
||||||
|
'while kill -0 "$PARENT" 2>/dev/null; do sleep 0.1; done',
|
||||||
|
'cp "$NEW" "$OLD" && chmod +x "$OLD"',
|
||||||
|
'exec "$OLD"',
|
||||||
|
].join('\n')
|
||||||
|
|
||||||
|
writeFileSync(scriptPath, script, { mode: 0o755 })
|
||||||
|
|
||||||
|
spawn('/bin/sh', [scriptPath, String(process.pid), newPath, oldPath], {
|
||||||
|
detached: true,
|
||||||
|
stdio: 'ignore',
|
||||||
|
}).unref()
|
||||||
|
}
|
||||||
|
|
||||||
export class UpdaterService {
|
export class UpdaterService {
|
||||||
private downloadedPath: string | null = null
|
private downloadedPath: string | null = null
|
||||||
|
|
||||||
|
|
@ -147,16 +168,17 @@ export class UpdaterService {
|
||||||
installUpdate(): void {
|
installUpdate(): void {
|
||||||
if (!this.downloadedPath) return
|
if (!this.downloadedPath) return
|
||||||
|
|
||||||
const appImagePath = process.env['APPIMAGE']
|
// Разрешаем симлинки — APPIMAGE может указывать на symlink
|
||||||
|
let appImagePath = process.env['APPIMAGE'] ?? ''
|
||||||
if (appImagePath) {
|
if (appImagePath) {
|
||||||
try {
|
try { appImagePath = realpathSync(appImagePath) } catch (_) {}
|
||||||
copyFileSync(this.downloadedPath, appImagePath)
|
|
||||||
chmodSync(appImagePath, 0o755)
|
|
||||||
app.relaunch()
|
|
||||||
} catch {
|
|
||||||
app.relaunch({ execPath: this.downloadedPath })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (appImagePath) {
|
||||||
|
// Запускаем детачнутый хелпер: он заменит AppImage после нашей смерти
|
||||||
|
spawnUpdateHelper(this.downloadedPath, appImagePath)
|
||||||
} else {
|
} else {
|
||||||
|
// APPIMAGE не установлен — просто перезапустить из нового файла
|
||||||
app.relaunch({ execPath: this.downloadedPath })
|
app.relaunch({ execPath: this.downloadedPath })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue