Sync snapshot (2026-08-10) (#80)

- Improve DOCX rendering fidelity, pagination, image handling, and Markdown paste
- Expand PDF text editing with paragraph reflow, style preservation, and more reliable text matching
- Harden XLSX sheet deletion, localized date formats, multi-row autofit, charts, and system font support
- Add inline AI turn rollback and sent-attachment visibility across editors
- Add Office-style ScreenTips and refine ribbons, dialogs, menus, and themes
- Improve Slides cropping, rotate and flip tools, printing, animations, and editing workflows
- Add shell settings, configurable save locations, account credits, and update recovery guidance
- Add Intel macOS and RPM download support and refresh public documentation

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
This commit is contained in:
merrick-2002
2026-08-10 23:17:11 +08:00
committed by GitHub
co-authored by GenOffice
parent fd33934dab
commit 7023e635bd
168 changed files with 9855 additions and 2799 deletions
+31 -2
View File
@@ -1,7 +1,7 @@
/// Localized replacements for Electron role menus, whose built-in labels are
/// English-only and (for role:'windowMenu' on Windows/Linux) follow macOS
/// conventions (Zoom, Ctrl+M minimize, Bring All to Front).
import type { MenuItemConstructorOptions } from 'electron'
import type { MenuItemConstructorOptions, WebContents } from 'electron'
import { contextMenuLabels, type ContextMenuLabels } from './context-menu'
export interface AppMenuLabels extends ContextMenuLabels {
@@ -399,6 +399,35 @@ export function editMenuTemplate(
}
}
let lastDetachedDevToolsTarget: WebContents | undefined
/** role:'toggleDevTools' docks DevTools into the window, where the shell's
* WebContentsView tabs are stacked above it and occlude it — open detached
* instead, keeping the role's accelerator and toggle semantics. */
export function toggleDevToolsItem(labels: AppMenuLabels): MenuItemConstructorOptions {
return {
label: labels.toggleDevTools,
accelerator: process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I',
click: async () => {
const { webContents } = await import('electron')
const focused = webContents.getFocusedWebContents()
const previous =
lastDetachedDevToolsTarget && !lastDetachedDevToolsTarget.isDestroyed()
? lastDetachedDevToolsTarget
: undefined
const wc = !focused || focused === previous?.devToolsWebContents ? previous : focused
if (!wc) return
if (wc.isDevToolsOpened()) {
wc.closeDevTools()
if (wc === lastDetachedDevToolsTarget) lastDetachedDevToolsTarget = undefined
} else {
wc.openDevTools({ mode: 'detach' })
lastDetachedDevToolsTarget = wc
}
},
}
}
/** role:'viewMenu' expands identically on every platform, so no branch. */
export function viewMenuTemplate(labels: AppMenuLabels): MenuItemConstructorOptions {
return {
@@ -406,7 +435,7 @@ export function viewMenuTemplate(labels: AppMenuLabels): MenuItemConstructorOpti
submenu: [
{ role: 'reload', label: labels.reload },
{ role: 'forceReload', label: labels.forceReload },
{ role: 'toggleDevTools', label: labels.toggleDevTools },
toggleDevToolsItem(labels),
{ type: 'separator' },
{ role: 'resetZoom', label: labels.actualSize },
{ role: 'zoomIn', label: labels.zoomIn },
@@ -0,0 +1,57 @@
/// The default folder where new/untitled files land on their first (silent)
/// save and where AI-generated drafts go. Historically hardcoded to
/// <Documents>/GenOffice; now user-configurable via the `defaultSaveDir` key
/// in userData/app-settings.json (set from the home screen's account menu).
/// Every editor main module resolves through here so they all honor the same
/// setting.
import { accessSync, constants, mkdirSync, readFileSync } from 'node:fs'
import { isAbsolute, join } from 'node:path'
/** the subset of Electron's `app` needed here (kept structural: this package has no Electron dependency) */
export interface PathProvider {
getPath(name: 'userData' | 'documents'): string
}
export const DEFAULT_SAVE_DIR_KEY = 'defaultSaveDir'
/** the configured folder from app-settings.json, or null when unset/unreadable */
export function readDefaultSaveDirSetting(settingsPath: string): string | null {
try {
const raw: unknown = JSON.parse(readFileSync(settingsPath, 'utf8'))
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null
const value = (raw as Record<string, unknown>)[DEFAULT_SAVE_DIR_KEY]
return typeof value === 'string' && isAbsolute(value) ? value : null
} catch {
return null
}
}
/** true when the directory exists (or could be created) and is writable */
export function isUsableSaveDir(dir: string): boolean {
try {
mkdirSync(dir, { recursive: true })
accessSync(dir, constants.W_OK)
return true
} catch {
return false
}
}
/**
* Pick the effective default save folder: the configured one when it is
* usable, otherwise the fallback (created on demand). A configured folder on
* an unplugged drive or with revoked permissions degrades to the fallback
* instead of breaking silent saves.
*/
export function resolveDefaultSaveDir(configured: string | null, fallbackDir: string): string {
if (configured && isUsableSaveDir(configured)) return configured
mkdirSync(fallbackDir, { recursive: true })
return fallbackDir
}
/** convenience for the Electron mains: settings lookup + fallback in one call */
export function configuredDefaultSaveDir(app: PathProvider): string {
const settingsPath = join(app.getPath('userData'), 'app-settings.json')
const fallback = join(app.getPath('documents'), 'GenOffice')
return resolveDefaultSaveDir(readDefaultSaveDirSetting(settingsPath), fallback)
}
+8 -3
View File
@@ -23,8 +23,11 @@ const lastUsedDirectoryByDialog = new WeakMap<Dialog, string>()
function withRememberedDirectory<T extends OpenDialogOptions | SaveDialogOptions>(
dialog: Dialog,
options: T,
fallbackDir?: string,
): T {
const lastDir = lastUsedDirectoryByDialog.get(dialog)
// No pick confirmed yet this session: anchor in the caller's fallback (the
// configurable default save folder) instead of Electron's Downloads pin.
const lastDir = lastUsedDirectoryByDialog.get(dialog) ?? fallbackDir
if (!lastDir) return options
if (options.defaultPath === undefined) return { ...options, defaultPath: lastDir }
// A bare file name is a Save As suggestion: anchor it in the remembered
@@ -39,8 +42,9 @@ export async function showOpenDialogWithMemory(
dialog: Dialog,
parent: BrowserWindow | null | undefined,
options: OpenDialogOptions,
fallbackDir?: string,
): Promise<OpenDialogReturnValue> {
const withDir = withRememberedDirectory(dialog, options)
const withDir = withRememberedDirectory(dialog, options, fallbackDir)
const result = parent
? await dialog.showOpenDialog(parent, withDir)
: await dialog.showOpenDialog(withDir)
@@ -58,8 +62,9 @@ export async function showSaveDialogWithMemory(
dialog: Dialog,
parent: BrowserWindow | null | undefined,
options: SaveDialogOptions,
fallbackDir?: string,
): Promise<SaveDialogReturnValue> {
const withDir = withRememberedDirectory(dialog, options)
const withDir = withRememberedDirectory(dialog, options, fallbackDir)
const result = parent
? await dialog.showSaveDialog(parent, withDir)
: await dialog.showSaveDialog(withDir)
+9
View File
@@ -8,11 +8,20 @@ export {
export {
appMenuLabels,
editMenuTemplate,
toggleDevToolsItem,
viewMenuTemplate,
windowMenuTemplate,
type AppMenuLabels,
} from './app-menu'
export { showOpenDialogWithMemory, showSaveDialogWithMemory } from './dialog-memory'
export {
DEFAULT_SAVE_DIR_KEY,
configuredDefaultSaveDir,
isUsableSaveDir,
readDefaultSaveDirSetting,
resolveDefaultSaveDir,
type PathProvider,
} from './default-save-dir'
export { installNavigationGuard } from './navigation-guard'
export { safeExternalUrl, type SafeExternalUrlOptions } from './safe-external-url'
export {
+44 -3
View File
@@ -1,4 +1,14 @@
import { describe, expect, it } from 'vitest'
import { beforeEach, describe, expect, it, vi } from 'vitest'
const electronMock = vi.hoisted(() => ({
getFocusedWebContents: vi.fn(),
}))
vi.mock('electron', () => ({
webContents: {
getFocusedWebContents: electronMock.getFocusedWebContents,
},
}))
import {
appMenuLabels,
@@ -35,6 +45,10 @@ const en = appMenuLabels('en')
type Item = { role?: string; type?: string; label?: string; accelerator?: string }
const submenuOf = (tpl: { submenu?: unknown }): Item[] => tpl.submenu as Item[]
beforeEach(() => {
vi.clearAllMocks()
})
describe('appMenuLabels', () => {
it('covers all 19 languages with every key non-empty', () => {
const keys = Object.keys(en) as (keyof AppMenuLabels)[]
@@ -108,10 +122,10 @@ describe('viewMenuTemplate', () => {
it('mirrors the viewMenu role expansion with labeled roles', () => {
const tpl = viewMenuTemplate(en)
expect(tpl.label).toBe('View')
expect(submenuOf(tpl).map((i) => i.role ?? i.type)).toEqual([
expect(submenuOf(tpl).map((i) => i.role ?? i.type ?? i.label)).toEqual([
'reload',
'forceReload',
'toggleDevTools',
'Developer Tools',
'separator',
'resetZoom',
'zoomIn',
@@ -121,4 +135,31 @@ describe('viewMenuTemplate', () => {
])
for (const item of submenuOf(tpl)) if (item.role) expect(item.label).toBeTruthy()
})
it('opens DevTools via an explicit click item, not the docking role', () => {
const item = submenuOf(viewMenuTemplate(en))[2] as Item & { click?: unknown }
expect(item.role).toBeUndefined()
expect(typeof item.click).toBe('function')
expect(item.accelerator).toBe(process.platform === 'darwin' ? 'Alt+Command+I' : 'Ctrl+Shift+I')
})
it('closes detached DevTools when they have focus', async () => {
const target = {
devToolsWebContents: {},
isDestroyed: vi.fn(() => false),
isDevToolsOpened: vi.fn().mockReturnValueOnce(false).mockReturnValueOnce(true),
openDevTools: vi.fn(),
closeDevTools: vi.fn(),
}
electronMock.getFocusedWebContents.mockReturnValueOnce(target).mockReturnValueOnce(null)
const item = submenuOf(viewMenuTemplate(en))[2] as Item & {
click: () => Promise<void>
}
await item.click()
await item.click()
expect(target.openDevTools).toHaveBeenCalledWith({ mode: 'detach' })
expect(target.closeDevTools).toHaveBeenCalledOnce()
})
})
@@ -0,0 +1,97 @@
import { chmodSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import {
configuredDefaultSaveDir,
readDefaultSaveDirSetting,
resolveDefaultSaveDir,
} from '../src/index'
let root: string
beforeEach(() => {
root = mkdtempSync(join(tmpdir(), 'genoffice-save-dir-'))
})
afterEach(() => {
rmSync(root, { recursive: true, force: true })
})
describe('readDefaultSaveDirSetting', () => {
const settingsPath = () => join(root, 'app-settings.json')
it('returns the configured absolute path', () => {
writeFileSync(settingsPath(), JSON.stringify({ defaultSaveDir: '/some/where' }))
expect(readDefaultSaveDirSetting(settingsPath())).toBe('/some/where')
})
it('returns null when the file is missing, corrupt, or the key is absent', () => {
expect(readDefaultSaveDirSetting(settingsPath())).toBeNull()
writeFileSync(settingsPath(), 'not json')
expect(readDefaultSaveDirSetting(settingsPath())).toBeNull()
writeFileSync(settingsPath(), JSON.stringify({ language: 'en' }))
expect(readDefaultSaveDirSetting(settingsPath())).toBeNull()
})
it('rejects non-string and relative values', () => {
writeFileSync(settingsPath(), JSON.stringify({ defaultSaveDir: 42 }))
expect(readDefaultSaveDirSetting(settingsPath())).toBeNull()
writeFileSync(settingsPath(), JSON.stringify({ defaultSaveDir: 'relative/dir' }))
expect(readDefaultSaveDirSetting(settingsPath())).toBeNull()
})
})
describe('resolveDefaultSaveDir', () => {
it('uses the configured folder when it is usable (creating it on demand)', () => {
const configured = join(root, 'custom', 'nested')
const resolved = resolveDefaultSaveDir(configured, join(root, 'fallback'))
expect(resolved).toBe(configured)
expect(existsSync(configured)).toBe(true)
})
it('creates and returns the fallback when nothing is configured', () => {
const fallback = join(root, 'Documents', 'GenOffice')
expect(resolveDefaultSaveDir(null, fallback)).toBe(fallback)
expect(existsSync(fallback)).toBe(true)
})
it('degrades to the fallback when the configured folder is not writable', () => {
const readOnly = join(root, 'read-only')
mkdirSync(readOnly)
chmodSync(readOnly, 0o500)
const fallback = join(root, 'fallback')
try {
expect(resolveDefaultSaveDir(readOnly, fallback)).toBe(fallback)
} finally {
chmodSync(readOnly, 0o700)
}
})
})
describe('configuredDefaultSaveDir', () => {
it('reads the setting from userData/app-settings.json and honors it', () => {
const userData = join(root, 'userData')
const documents = join(root, 'Documents')
mkdirSync(userData, { recursive: true })
const custom = join(root, 'my-files')
writeFileSync(join(userData, 'app-settings.json'), JSON.stringify({ defaultSaveDir: custom }))
const app = {
getPath: (name: 'userData' | 'documents') => (name === 'userData' ? userData : documents),
}
expect(configuredDefaultSaveDir(app)).toBe(custom)
})
it('falls back to <Documents>/GenOffice without a setting', () => {
const userData = join(root, 'userData')
const documents = join(root, 'Documents')
mkdirSync(userData, { recursive: true })
const app = {
getPath: (name: 'userData' | 'documents') => (name === 'userData' ? userData : documents),
}
expect(configuredDefaultSaveDir(app)).toBe(join(documents, 'GenOffice'))
expect(existsSync(join(documents, 'GenOffice'))).toBe(true)
})
})
@@ -91,4 +91,27 @@ describe('showSaveDialogWithMemory', () => {
await showOpenDialogWithMemory(second, undefined, {})
expect(second.showOpenDialog).toHaveBeenCalledWith({})
})
it('anchors a bare file-name suggestion in the fallback dir when nothing is remembered', async () => {
const dialog = fakeDialog()
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: 'deck.pptx' }, '/default/save')
expect(dialog.showSaveDialog).toHaveBeenCalledWith({
defaultPath: join('/default/save', 'deck.pptx'),
})
})
it('prefers the remembered directory over the fallback dir', async () => {
const dialog = fakeDialog({ showSaveDialog: pickedSave(join('/work', 'deck.pptx')) })
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: 'deck.pptx' })
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: 'b.pptx' }, '/default/save')
expect(dialog.showSaveDialog).toHaveBeenLastCalledWith({
defaultPath: join('/work', 'b.pptx'),
})
})
it('keeps an explicit absolute defaultPath untouched even with a fallback dir', async () => {
const dialog = fakeDialog()
await showSaveDialogWithMemory(dialog, undefined, { defaultPath: '/docs/tab.pdf' }, '/default')
expect(dialog.showSaveDialog).toHaveBeenCalledWith({ defaultPath: '/docs/tab.pdf' })
})
})