:lightning: handle permission ask gracefully
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { readdir, readFile, writeFile, mkdir, unlink, rename as fsRename, rm } from 'fs/promises'
|
||||
import { existsSync } from 'fs'
|
||||
import { join, basename } from 'path'
|
||||
import { app } from 'electron'
|
||||
import { getCollectionRoot } from './globalConfig'
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
@@ -61,7 +63,9 @@ export interface TelemetrySession {
|
||||
|
||||
// ─── 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 orderFile = (): string => join(borgesDir(), 'order.json')
|
||||
const sessionFile = (): string => join(borgesDir(), 'session.json')
|
||||
@@ -72,6 +76,16 @@ const telemetryFile = (): string => join(borgesDir(), 'telemetry.json')
|
||||
|
||||
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 {
|
||||
const root = getCollectionRoot()
|
||||
const resolved = filePath.startsWith('/') ? filePath : join(root, filePath)
|
||||
|
||||
@@ -3,6 +3,7 @@ import { join } from 'path'
|
||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||
import { registerIpcHandlers } from './ipcHandlers'
|
||||
import { getCollectionRoot, readGlobalConfig } from './globalConfig'
|
||||
import { migrateAppData } from './fileSystem'
|
||||
|
||||
app.setName('Borges')
|
||||
|
||||
@@ -130,7 +131,7 @@ mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
return mainWindow
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
app.whenReady().then(async () => {
|
||||
electronApp.setAppUserModelId('com.borges.editor')
|
||||
|
||||
if (process.platform === 'darwin') {
|
||||
@@ -139,6 +140,7 @@ app.whenReady().then(() => {
|
||||
|
||||
app.on('browser-window-created', (_, window) => optimizer.watchWindowShortcuts(window))
|
||||
|
||||
await migrateAppData()
|
||||
registerIpcHandlers()
|
||||
const mainWindow = createWindow()
|
||||
buildAppMenu(mainWindow)
|
||||
|
||||
Reference in New Issue
Block a user