fix(updater): make update prompts and installation opt-in (#493)
* fix(updater): make update prompts and installation opt-in * fix(html2docx): narrow page background screenshot IDs * test(e2e): wait for native spelling markers to recover --------- Co-authored-by: merrick-2002 <merrick@mainfunc.ai>
This commit is contained in:
@@ -11,12 +11,7 @@ import type {
|
||||
UpdateUiState,
|
||||
UpdateUiStrings,
|
||||
} from '../shared/update-api'
|
||||
import {
|
||||
closeUpdateWindow,
|
||||
isUpdateWindowOpen,
|
||||
pushUpdateState,
|
||||
showUpdateWindow,
|
||||
} from './update-window'
|
||||
import { closeUpdateWindow, pushUpdateState, showUpdateWindow } from './update-window'
|
||||
|
||||
/**
|
||||
* Full-package auto-update over the generic provider (Azure CDN).
|
||||
@@ -450,8 +445,6 @@ function manualDownloadUrlFor(info: UpdateInfo): string | null {
|
||||
}
|
||||
|
||||
let started = false
|
||||
// version the user declined this session — don't nag again until next launch
|
||||
let dismissedVersion: string | null = null
|
||||
// re-shows the GENOFFICE_FAKE_UPDATE window so the manual check is
|
||||
// exercisable in dev runs too
|
||||
let fakeShowAgain: (() => void) | null = null
|
||||
@@ -536,10 +529,10 @@ export async function checkForUpdatesNow(): Promise<void> {
|
||||
if (response === 1) void shell.openExternal(DOWNLOAD_PAGE_URL)
|
||||
return
|
||||
}
|
||||
dismissedVersion = null
|
||||
let result
|
||||
try {
|
||||
result = await autoUpdater.checkForUpdates()
|
||||
if (result === null) throw new Error('Update check was skipped')
|
||||
} catch (err) {
|
||||
log('manual check failed:', (err as Error)?.message ?? err)
|
||||
await dialog.showMessageBox({
|
||||
@@ -554,7 +547,7 @@ export async function checkForUpdatesNow(): Promise<void> {
|
||||
}
|
||||
// an available update already opened the update window via the
|
||||
// 'update-available' handler; only "nothing new" needs a dialog here
|
||||
if (result?.isUpdateAvailable) return
|
||||
if (result.isUpdateAvailable) return
|
||||
await dialog.showMessageBox({
|
||||
type: 'info',
|
||||
title: tUpd(lang, 'updTitle'),
|
||||
@@ -597,8 +590,8 @@ export function initAutoUpdater(
|
||||
// back off since a beta user switching to stable must not downgrade
|
||||
autoUpdater.allowDowngrade = false
|
||||
autoUpdater.autoDownload = false
|
||||
// if the user picked "later" after download, install on normal quit
|
||||
autoUpdater.autoInstallOnAppQuit = true
|
||||
// Downloading is not consent to install: "later" must also survive app quit.
|
||||
autoUpdater.autoInstallOnAppQuit = false
|
||||
// full-package policy: never attempt blockmap differential downloads
|
||||
// (CI does not publish .blockmap files)
|
||||
autoUpdater.disableDifferentialDownload = true
|
||||
@@ -648,7 +641,6 @@ export function initAutoUpdater(
|
||||
setImmediate(() => autoUpdater.quitAndInstall(true, true))
|
||||
},
|
||||
onLater: () => {
|
||||
dismissedVersion = latestSeenVersion
|
||||
closeUpdateWindow()
|
||||
},
|
||||
onOpenDownload: () => {
|
||||
@@ -664,20 +656,17 @@ export function initAutoUpdater(
|
||||
})
|
||||
|
||||
autoUpdater.on('update-available', (info: UpdateInfo) => {
|
||||
if (info.version === dismissedVersion) return
|
||||
// Only an explicit check may interrupt the user with an update offer.
|
||||
// Background checks must not open or change the active update window.
|
||||
if (!manualCheckInFlight) return
|
||||
const sameVersionRecheck = info.version === latestSeenVersion
|
||||
// progress/downloaded/error events carry no version, so a newer release
|
||||
// landing while the previous one is downloading or already downloaded
|
||||
// stays out until that flow ends (it installs on quit and the next launch
|
||||
// picks up the newer one); it must not hijack the open window
|
||||
// stays out until the user installs it; it must not hijack the open window
|
||||
if (!sameVersionRecheck && (downloadInFlight || phase === 'downloaded')) {
|
||||
log('update available:', info.version, 'ignored while', latestSeenVersion, 'is', phase)
|
||||
// an explicit check still owes feedback: bring back the flow in progress
|
||||
// (a background recheck stays quiet)
|
||||
if (manualCheckInFlight && !isUpdateWindowOpen()) {
|
||||
const version = latestSeenVersion ?? info.version
|
||||
showUpdateWindow(getWindow(), { ...initialState(version), phase, percent }, actions)
|
||||
}
|
||||
const version = latestSeenVersion ?? info.version
|
||||
showUpdateWindow(getWindow(), { ...initialState(version), phase, percent }, actions)
|
||||
return
|
||||
}
|
||||
if (!sameVersionRecheck) {
|
||||
@@ -688,11 +677,7 @@ export function initAutoUpdater(
|
||||
latestSeenVersion = info.version
|
||||
manualDownloadUrl = manualDownloadUrlFor(info)
|
||||
log('update available:', info.version)
|
||||
// a periodic recheck resolving to the version the open dialog already
|
||||
// shows must not reset its phase to 'available' — that would wipe an
|
||||
// in-progress download or a terminal 'manual' fallback back to the
|
||||
// "Update Now" offer
|
||||
if (sameVersionRecheck && isUpdateWindowOpen()) return
|
||||
// Reuse and focus the existing window, preserving progress and retry state.
|
||||
showUpdateWindow(getWindow(), { ...initialState(info.version), phase, percent }, actions)
|
||||
})
|
||||
|
||||
|
||||
@@ -99,7 +99,6 @@ vi.mock('../src/main/update-window', () => ({
|
||||
showUpdateWindow: (...args: [unknown, UpdateUiState, UpdateActions]) => showUpdateWindow(...args),
|
||||
pushUpdateState: (patch: Partial<UpdateUiState>) => pushUpdateState(patch),
|
||||
closeUpdateWindow: () => closeUpdateWindow(),
|
||||
isUpdateWindowOpen: () => false,
|
||||
}))
|
||||
|
||||
const FIRST_CHECK_DELAY_MS = 15_000
|
||||
@@ -119,6 +118,15 @@ async function loadUpdater() {
|
||||
return import('../src/main/updater')
|
||||
}
|
||||
|
||||
async function offerUpdate(info: { version: string; files?: { url: string }[] }): Promise<void> {
|
||||
const { checkForUpdatesNow } = await loadUpdater()
|
||||
checkForUpdates.mockImplementationOnce(() => {
|
||||
updaterState.listeners.get('update-available')!(info)
|
||||
return Promise.resolve({ isUpdateAvailable: true } as never)
|
||||
})
|
||||
await checkForUpdatesNow()
|
||||
}
|
||||
|
||||
async function flushAsync(): Promise<void> {
|
||||
// drain promise chains queued by download callbacks
|
||||
for (let i = 0; i < 10; i++) await Promise.resolve()
|
||||
@@ -143,7 +151,8 @@ beforeEach(() => {
|
||||
updaterState.disableDifferentialDownload = false
|
||||
updaterState.channel = null
|
||||
updaterState.allowDowngrade = false
|
||||
checkForUpdates.mockClear()
|
||||
checkForUpdates.mockReset()
|
||||
checkForUpdates.mockResolvedValue(null)
|
||||
downloadUpdate.mockReset()
|
||||
downloadUpdate.mockImplementation(() => Promise.resolve([]))
|
||||
quitAndInstall.mockClear()
|
||||
@@ -192,7 +201,7 @@ describe('initAutoUpdater', () => {
|
||||
const { initAutoUpdater } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
expect(updaterState.autoDownload).toBe(false)
|
||||
expect(updaterState.autoInstallOnAppQuit).toBe(true)
|
||||
expect(updaterState.autoInstallOnAppQuit).toBe(false)
|
||||
expect(updaterState.disableDifferentialDownload).toBe(true)
|
||||
expect(checkForUpdates).not.toHaveBeenCalled()
|
||||
vi.advanceTimersByTime(FIRST_CHECK_DELAY_MS)
|
||||
@@ -216,10 +225,44 @@ describe('initAutoUpdater', () => {
|
||||
expect(checkForUpdates).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('keeps launch, periodic and channel checks silent when updates exist', async () => {
|
||||
const { initAutoUpdater, applyUpdateChannel } = await loadUpdater()
|
||||
checkForUpdates.mockImplementation(() => {
|
||||
updaterState.listeners.get('update-available')!({ version: '0.2.0' })
|
||||
return Promise.resolve({ isUpdateAvailable: true } as never)
|
||||
})
|
||||
initAutoUpdater(() => null)
|
||||
vi.advanceTimersByTime(FIRST_CHECK_DELAY_MS)
|
||||
vi.advanceTimersByTime(RECHECK_INTERVAL_MS)
|
||||
applyUpdateChannel('beta')
|
||||
await flushAsync()
|
||||
|
||||
expect(checkForUpdates).toHaveBeenCalledTimes(3)
|
||||
expect(showUpdateWindow).not.toHaveBeenCalled()
|
||||
expect(showMessageBox).not.toHaveBeenCalled()
|
||||
expect(downloadUpdate).not.toHaveBeenCalled()
|
||||
expect(quitAndInstall).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('lets users decline a downloaded update without installing on quit', async () => {
|
||||
const { initAutoUpdater } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
await offerUpdate({ version: '0.2.0' })
|
||||
expect(downloadUpdate).not.toHaveBeenCalled()
|
||||
lastShownActions().onDownload()
|
||||
updaterState.listeners.get('update-downloaded')!({ version: '0.2.0' })
|
||||
lastShownActions().onLater()
|
||||
vi.advanceTimersByTime(0)
|
||||
|
||||
expect(closeUpdateWindow).toHaveBeenCalledTimes(1)
|
||||
expect(updaterState.autoInstallOnAppQuit).toBe(false)
|
||||
expect(quitAndInstall).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('opens the update window with the available state when an update is found', async () => {
|
||||
const { initAutoUpdater } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
updaterState.listeners.get('update-available')!({ version: '0.2.0' })
|
||||
await offerUpdate({ version: '0.2.0' })
|
||||
expect(showUpdateWindow).toHaveBeenCalledTimes(1)
|
||||
const state = lastShownState()
|
||||
expect(state.phase).toBe('available')
|
||||
@@ -234,7 +277,7 @@ describe('initAutoUpdater', () => {
|
||||
it('starts the download and pushes progress when the user clicks download', async () => {
|
||||
const { initAutoUpdater } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
updaterState.listeners.get('update-available')!({ version: '0.2.0' })
|
||||
await offerUpdate({ version: '0.2.0' })
|
||||
lastShownActions().onDownload()
|
||||
expect(pushUpdateState).toHaveBeenCalledWith({ phase: 'downloading', percent: 0 })
|
||||
expect(downloadUpdate).toHaveBeenCalledTimes(1)
|
||||
@@ -250,7 +293,7 @@ describe('initAutoUpdater', () => {
|
||||
downloadUpdate.mockImplementation(() => Promise.reject(new Error('offline')))
|
||||
const { initAutoUpdater } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
updaterState.listeners.get('update-available')!({ version: '0.2.0' })
|
||||
await offerUpdate({ version: '0.2.0' })
|
||||
lastShownActions().onDownload()
|
||||
await flushAsync()
|
||||
expect(pushUpdateState).toHaveBeenCalledWith({ phase: 'error' })
|
||||
@@ -259,7 +302,7 @@ describe('initAutoUpdater', () => {
|
||||
it('closes the window and installs on restart when the user confirms', async () => {
|
||||
const { initAutoUpdater } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
updaterState.listeners.get('update-available')!({ version: '0.2.0' })
|
||||
await offerUpdate({ version: '0.2.0' })
|
||||
lastShownActions().onInstall()
|
||||
expect(closeUpdateWindow).toHaveBeenCalledTimes(1)
|
||||
// quitAndInstall is deferred so the window can finish closing first
|
||||
@@ -272,7 +315,7 @@ describe('initAutoUpdater', () => {
|
||||
const { initAutoUpdater } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
const available = updaterState.listeners.get('update-available')!
|
||||
available({ version: '0.2.0' })
|
||||
await offerUpdate({ version: '0.2.0' })
|
||||
expect(showUpdateWindow).toHaveBeenCalledTimes(1)
|
||||
lastShownActions().onLater()
|
||||
expect(closeUpdateWindow).toHaveBeenCalledTimes(1)
|
||||
@@ -280,9 +323,11 @@ describe('initAutoUpdater', () => {
|
||||
available({ version: '0.2.0' })
|
||||
expect(showUpdateWindow).toHaveBeenCalledTimes(1)
|
||||
|
||||
// a newer version prompts again
|
||||
// Even a newer release stays silent until the user checks again.
|
||||
available({ version: '0.3.0' })
|
||||
expect(showUpdateWindow).toHaveBeenCalledTimes(2)
|
||||
expect(showUpdateWindow).toHaveBeenCalledTimes(1)
|
||||
expect(downloadUpdate).not.toHaveBeenCalled()
|
||||
expect(quitAndInstall).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('swallows background check failures', async () => {
|
||||
@@ -354,7 +399,7 @@ describe('manual download fallback', () => {
|
||||
downloadUpdate.mockImplementation(() => Promise.reject(new Error('team id changed')))
|
||||
const { initAutoUpdater } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
updaterState.listeners.get('update-available')!({ version: '0.2.0', files })
|
||||
await offerUpdate({ version: '0.2.0', files })
|
||||
const actions = lastShownActions()
|
||||
actions.onDownload()
|
||||
await flushAsync()
|
||||
@@ -561,10 +606,75 @@ describe('checkForUpdatesNow (r148 manual check)', () => {
|
||||
expect(showUpdateWindow).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not report up-to-date when the updater skips the check', async () => {
|
||||
const { initAutoUpdater, checkForUpdatesNow } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
checkForUpdates.mockResolvedValue(null)
|
||||
|
||||
await checkForUpdatesNow()
|
||||
|
||||
expect(lastDialogOpts().type).toBe('warning')
|
||||
expect(showUpdateWindow).not.toHaveBeenCalled()
|
||||
expect(downloadUpdate).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('ignores duplicate clicks while checking and allows a retry afterwards', async () => {
|
||||
const { initAutoUpdater, checkForUpdatesNow } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
let resolveCheck!: (value: null) => void
|
||||
checkForUpdates.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise((resolve) => {
|
||||
resolveCheck = resolve
|
||||
}),
|
||||
)
|
||||
|
||||
const pending = checkForUpdatesNow()
|
||||
await checkForUpdatesNow()
|
||||
expect(checkForUpdates).toHaveBeenCalledTimes(1)
|
||||
expect(showMessageBox).not.toHaveBeenCalled()
|
||||
resolveCheck(null)
|
||||
await pending
|
||||
await checkForUpdatesNow()
|
||||
expect(checkForUpdates).toHaveBeenCalledTimes(2)
|
||||
expect(downloadUpdate).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it.each(['0.2.0', '0.3.0'])(
|
||||
'focuses the existing download on a manual check finding %s',
|
||||
async (version) => {
|
||||
downloadUpdate.mockImplementation(() => new Promise(() => {}))
|
||||
const { initAutoUpdater, checkForUpdatesNow } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
const available = updaterState.listeners.get('update-available')!
|
||||
await offerUpdate({ version: '0.2.0' })
|
||||
lastShownActions().onDownload()
|
||||
updaterState.listeners.get('download-progress')!({ percent: 37 })
|
||||
|
||||
// Background checks must not steal focus from the user's document.
|
||||
available({ version })
|
||||
expect(showUpdateWindow).toHaveBeenCalledTimes(1)
|
||||
checkForUpdates.mockImplementation(() => {
|
||||
available({ version })
|
||||
return Promise.resolve({ isUpdateAvailable: true } as never)
|
||||
})
|
||||
await checkForUpdatesNow()
|
||||
|
||||
expect(showUpdateWindow).toHaveBeenCalledTimes(2)
|
||||
expect(lastShownState()).toMatchObject({
|
||||
version: '0.2.0',
|
||||
phase: 'downloading',
|
||||
percent: 37,
|
||||
})
|
||||
expect(showMessageBox).not.toHaveBeenCalled()
|
||||
expect(downloadUpdate).toHaveBeenCalledTimes(1)
|
||||
},
|
||||
)
|
||||
|
||||
it('re-offers a version the user dismissed with "later" this session', async () => {
|
||||
const { initAutoUpdater, checkForUpdatesNow } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
updaterState.listeners.get('update-available')!({ version: '0.2.0' })
|
||||
await offerUpdate({ version: '0.2.0' })
|
||||
expect(showUpdateWindow).toHaveBeenCalledTimes(1)
|
||||
lastShownActions().onLater()
|
||||
// background recheck stays quiet for the dismissed version…
|
||||
@@ -586,7 +696,7 @@ describe('checkForUpdatesNow (r148 manual check)', () => {
|
||||
const { initAutoUpdater, checkForUpdatesNow } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
const available = updaterState.listeners.get('update-available')!
|
||||
available({ version: '0.2.0' })
|
||||
await offerUpdate({ version: '0.2.0' })
|
||||
lastShownActions().onDownload()
|
||||
updaterState.listeners.get('update-downloaded')!({ version: '0.2.0' })
|
||||
lastShownActions().onLater()
|
||||
@@ -609,7 +719,7 @@ describe('checkForUpdatesNow (r148 manual check)', () => {
|
||||
const { initAutoUpdater, checkForUpdatesNow } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
const available = updaterState.listeners.get('update-available')!
|
||||
available({ version: '0.2.0' })
|
||||
await offerUpdate({ version: '0.2.0' })
|
||||
lastShownActions().onDownload()
|
||||
updaterState.listeners.get('download-progress')!({ percent: 37 })
|
||||
lastShownActions().onLater()
|
||||
@@ -631,7 +741,7 @@ describe('checkForUpdatesNow (r148 manual check)', () => {
|
||||
const { initAutoUpdater } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
const available = updaterState.listeners.get('update-available')!
|
||||
available({ version: '0.2.0' })
|
||||
await offerUpdate({ version: '0.2.0' })
|
||||
lastShownActions().onDownload()
|
||||
available({ version: '0.3.0' })
|
||||
expect(showUpdateWindow).toHaveBeenCalledTimes(1)
|
||||
@@ -647,7 +757,7 @@ describe('checkForUpdatesNow (r148 manual check)', () => {
|
||||
const { initAutoUpdater, checkForUpdatesNow } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
const available = updaterState.listeners.get('update-available')!
|
||||
available({ version: '0.2.0' })
|
||||
await offerUpdate({ version: '0.2.0' })
|
||||
lastShownActions().onDownload()
|
||||
updaterState.listeners.get('download-progress')!({ percent: 58 })
|
||||
lastShownActions().onLater()
|
||||
@@ -673,12 +783,11 @@ describe('checkForUpdatesNow (r148 manual check)', () => {
|
||||
downloadUpdate.mockImplementation(() => Promise.reject(new Error('offline')))
|
||||
const { initAutoUpdater } = await loadUpdater()
|
||||
initAutoUpdater(() => null)
|
||||
const available = updaterState.listeners.get('update-available')!
|
||||
available({ version: '0.2.0' })
|
||||
await offerUpdate({ version: '0.2.0' })
|
||||
lastShownActions().onDownload()
|
||||
await flushAsync()
|
||||
expect(pushUpdateState).toHaveBeenCalledWith({ phase: 'error' })
|
||||
available({ version: '0.3.0' })
|
||||
await offerUpdate({ version: '0.3.0' })
|
||||
expect(showUpdateWindow).toHaveBeenCalledTimes(2)
|
||||
expect(lastShownState().version).toBe('0.3.0')
|
||||
expect(lastShownState().phase).toBe('available')
|
||||
|
||||
@@ -57,15 +57,21 @@ test('re-enabling spellcheck respells existing text without user input', async (
|
||||
|
||||
// re-enable via the ribbon only — no click into the text, no typing
|
||||
await spelling.click()
|
||||
await wait(3500)
|
||||
const on = await redCount(editor)
|
||||
// Native spellchecking and painting complete asynchronously, especially
|
||||
// on shared CI runners. Wait for the original visual requirements rather
|
||||
// than sampling once after a fixed delay; missing markers still fail.
|
||||
await expect
|
||||
.poll(() => redCount(editor), {
|
||||
message: 'existing text regains its spelling markers after re-enabling',
|
||||
timeout: 15_000,
|
||||
intervals: [250, 500, 1000],
|
||||
})
|
||||
.toBeGreaterThanOrEqual(Math.max(off + 101, Math.floor(baseline * 0.8)))
|
||||
|
||||
const textAfter = await editor.evaluate(
|
||||
() => document.querySelector('.doc-page')?.textContent ?? '',
|
||||
)
|
||||
|
||||
expect(on).toBeGreaterThan(off + 100) // squiggles came back…
|
||||
expect(on).toBeGreaterThanOrEqual(Math.floor(baseline * 0.8)) // …on the existing lines
|
||||
expect(textAfter).toBe(textBefore) // and the respell kick left no trace
|
||||
expect(textAfter).not.toContain('')
|
||||
expect(textAfter).not.toContain(' ')
|
||||
|
||||
@@ -314,10 +314,7 @@ export async function convertHtmlToDocx(
|
||||
const shotIds: string[] = []
|
||||
const shotNodes = new Map<string, any>()
|
||||
const pageBgShotIds = new Set<string>(
|
||||
ir
|
||||
.filter((node) => node.type === 'pagebg')
|
||||
.map((node) => node.shotId)
|
||||
.filter((shotId): shotId is string => Boolean(shotId)),
|
||||
ir.flatMap((node) => (node.type === 'pagebg' && node.shotId ? [node.shotId] : [])),
|
||||
)
|
||||
const collectRunShots = (runs: any[] | undefined) => {
|
||||
for (const run of runs || []) {
|
||||
|
||||
Reference in New Issue
Block a user