:lightning: handle permission ask gracefully

This commit is contained in:
2026-06-14 22:09:07 +10:00
parent 01a41cf122
commit 72e6a71fa5
2 changed files with 18 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
import { readdir, readFile, writeFile, mkdir, unlink, rename as fsRename, rm } from 'fs/promises' import { readdir, readFile, writeFile, mkdir, unlink, rename as fsRename, rm } from 'fs/promises'
import { existsSync } from 'fs'
import { join, basename } from 'path' import { join, basename } from 'path'
import { app } from 'electron'
import { getCollectionRoot } from './globalConfig' import { getCollectionRoot } from './globalConfig'
// ─── Types ──────────────────────────────────────────────────────────────────── // ─── Types ────────────────────────────────────────────────────────────────────
@@ -61,7 +63,9 @@ export interface TelemetrySession {
// ─── Path helpers ───────────────────────────────────────────────────────────── // ─── Path helpers ─────────────────────────────────────────────────────────────
const borgesDir = (): string => join(getCollectionRoot(), '.borges') // App-internal data lives in userData (~/Library/Application Support/Borges),
// not in the collection (~/Documents/…), to avoid repeated macOS TCC prompts.
const borgesDir = (): string => join(app.getPath('userData'), '.borges')
const configFile = (): string => join(borgesDir(), 'config.json') const configFile = (): string => join(borgesDir(), 'config.json')
const orderFile = (): string => join(borgesDir(), 'order.json') const orderFile = (): string => join(borgesDir(), 'order.json')
const sessionFile = (): string => join(borgesDir(), 'session.json') const sessionFile = (): string => join(borgesDir(), 'session.json')
@@ -72,6 +76,16 @@ const telemetryFile = (): string => join(borgesDir(), 'telemetry.json')
const MAX_REVISIONS = 50 const MAX_REVISIONS = 50
// One-time migration: move .borges from the old collection location to userData.
export async function migrateAppData(): Promise<void> {
const oldDir = join(getCollectionRoot(), '.borges')
const newDir = borgesDir()
if (existsSync(oldDir) && !existsSync(newDir)) {
await mkdir(join(newDir, '..'), { recursive: true })
await fsRename(oldDir, newDir)
}
}
function assertInCollection(filePath: string): void { function assertInCollection(filePath: string): void {
const root = getCollectionRoot() const root = getCollectionRoot()
const resolved = filePath.startsWith('/') ? filePath : join(root, filePath) const resolved = filePath.startsWith('/') ? filePath : join(root, filePath)

View File

@@ -3,6 +3,7 @@ import { join } from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils' import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import { registerIpcHandlers } from './ipcHandlers' import { registerIpcHandlers } from './ipcHandlers'
import { getCollectionRoot, readGlobalConfig } from './globalConfig' import { getCollectionRoot, readGlobalConfig } from './globalConfig'
import { migrateAppData } from './fileSystem'
app.setName('Borges') app.setName('Borges')
@@ -130,7 +131,7 @@ mainWindow.webContents.setWindowOpenHandler((details) => {
return mainWindow return mainWindow
} }
app.whenReady().then(() => { app.whenReady().then(async () => {
electronApp.setAppUserModelId('com.borges.editor') electronApp.setAppUserModelId('com.borges.editor')
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
@@ -139,6 +140,7 @@ app.whenReady().then(() => {
app.on('browser-window-created', (_, window) => optimizer.watchWindowShortcuts(window)) app.on('browser-window-created', (_, window) => optimizer.watchWindowShortcuts(window))
await migrateAppData()
registerIpcHandlers() registerIpcHandlers()
const mainWindow = createWindow() const mainWindow = createWindow()
buildAppMenu(mainWindow) buildAppMenu(mainWindow)