Sync snapshot (2026-08-06) (#38)
- Movable, resizable floating objects and a shared 104-preset shape gallery across Docs, Sheets, and Slides - Sheets Insert menu: screenshot capture, recommended charts, and an icon library - Slides: Home slideshow module and slideshow-exit fixes - Docs: track-changes fixes (IME input, tracked-deletion re-deletion) and Word-parity font handling - Redact secret-looking tokens from outgoing AI messages (community contribution from PR #32, hardened with narrower patterns and tests) - Linux packaging: AppImage and deb download instructions Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
This commit is contained in:
co-authored by
GenOffice
parent
c3911b02b6
commit
df358f2775
@@ -0,0 +1,70 @@
|
||||
/// Electron 43 pins file dialogs without an explicit `defaultPath` to the
|
||||
/// user's Downloads folder and no longer lets the OS restore the last-used
|
||||
/// directory between invocations (electron/electron#49868). These wrappers
|
||||
/// restore the pre-43 behavior the way the Electron breaking-changes guide
|
||||
/// recommends: remember the directory of the last confirmed pick and thread
|
||||
/// it into the next dialog's `defaultPath`.
|
||||
import { basename, dirname, join } from 'node:path'
|
||||
|
||||
import type {
|
||||
BrowserWindow,
|
||||
Dialog,
|
||||
OpenDialogOptions,
|
||||
OpenDialogReturnValue,
|
||||
SaveDialogOptions,
|
||||
SaveDialogReturnValue,
|
||||
} from 'electron'
|
||||
|
||||
// Keyed by the dialog module so tests with fake dialogs stay isolated. Each
|
||||
// app bundles its own copy of this module, so the memory is scoped per
|
||||
// editor — close enough to the per-app directory tracking the OS did before.
|
||||
const lastUsedDirectoryByDialog = new WeakMap<Dialog, string>()
|
||||
|
||||
function withRememberedDirectory<T extends OpenDialogOptions | SaveDialogOptions>(
|
||||
dialog: Dialog,
|
||||
options: T,
|
||||
): T {
|
||||
const lastDir = lastUsedDirectoryByDialog.get(dialog)
|
||||
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
|
||||
// directory instead of letting Electron relocate it to Downloads.
|
||||
if (basename(options.defaultPath) === options.defaultPath) {
|
||||
return { ...options, defaultPath: join(lastDir, options.defaultPath) }
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
export async function showOpenDialogWithMemory(
|
||||
dialog: Dialog,
|
||||
parent: BrowserWindow | null | undefined,
|
||||
options: OpenDialogOptions,
|
||||
): Promise<OpenDialogReturnValue> {
|
||||
const withDir = withRememberedDirectory(dialog, options)
|
||||
const result = parent
|
||||
? await dialog.showOpenDialog(parent, withDir)
|
||||
: await dialog.showOpenDialog(withDir)
|
||||
const picked = result.filePaths[0]
|
||||
if (!result.canceled && picked) {
|
||||
lastUsedDirectoryByDialog.set(
|
||||
dialog,
|
||||
options.properties?.includes('openDirectory') ? picked : dirname(picked),
|
||||
)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export async function showSaveDialogWithMemory(
|
||||
dialog: Dialog,
|
||||
parent: BrowserWindow | null | undefined,
|
||||
options: SaveDialogOptions,
|
||||
): Promise<SaveDialogReturnValue> {
|
||||
const withDir = withRememberedDirectory(dialog, options)
|
||||
const result = parent
|
||||
? await dialog.showSaveDialog(parent, withDir)
|
||||
: await dialog.showSaveDialog(withDir)
|
||||
if (!result.canceled && result.filePath) {
|
||||
lastUsedDirectoryByDialog.set(dialog, dirname(result.filePath))
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -12,6 +12,7 @@ export {
|
||||
windowMenuTemplate,
|
||||
type AppMenuLabels,
|
||||
} from './app-menu'
|
||||
export { showOpenDialogWithMemory, showSaveDialogWithMemory } from './dialog-memory'
|
||||
export { installNavigationGuard } from './navigation-guard'
|
||||
export { safeExternalUrl, type SafeExternalUrlOptions } from './safe-external-url'
|
||||
export {
|
||||
|
||||
Reference in New Issue
Block a user