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
This commit is contained in:
@@ -81,15 +81,31 @@ function writeJsonFile<T>(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'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user