From 8b0805bebfa753d3f3e1d1b347d6446b1f74ad1e Mon Sep 17 00:00:00 2001 From: xue jiahao Date: Thu, 12 Mar 2026 11:03:50 +0800 Subject: [PATCH] fix(main): add safeStorage API compatibility check - Check if getSelectedStorageBackend exists before calling (Electron 30+) - Fallback to isEncryptionAvailable() for older Electron versions - Add try-catch to prevent unhandled promise rejection --- src/main/storage.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/storage.ts b/src/main/storage.ts index feeb9ce..d56fd6d 100644 --- a/src/main/storage.ts +++ b/src/main/storage.ts @@ -81,15 +81,31 @@ function writeJsonFile(filePath: string, data: T): void { * On Linux, this may return 'basic_text' if no keyring is available */ export function isSecureStorageAvailable(): boolean { - const backend = safeStorage.getSelectedStorageBackend(); - return backend !== "basic_text"; + try { + // Check if the method exists (added in Electron 30+) + if (typeof safeStorage.getSelectedStorageBackend === 'function') { + const backend = safeStorage.getSelectedStorageBackend() + return backend !== 'basic_text' + } + // Fallback: check if encryption is available + return safeStorage.isEncryptionAvailable() + } catch { + return false + } } /** * Get the current storage backend name */ export function getStorageBackend(): string { - return safeStorage.getSelectedStorageBackend(); + try { + if (typeof safeStorage.getSelectedStorageBackend === 'function') { + return safeStorage.getSelectedStorageBackend() + } + return 'unknown' + } catch { + return 'unknown' + } } /**