@@ -4,27 +4,14 @@ import fs from 'fs'
4
4
import * as argon2 from '@node-rs/argon2' ;
5
5
import { createCipheriv , createDecipheriv , pbkdf2Sync , randomBytes } from 'crypto' ;
6
6
import { execSync } from 'child_process' ;
7
+ import keytar from './get-keytar' ;
7
8
8
9
let Passport : any ;
9
10
if ( process . platform === 'win32' ) {
10
11
const { Passport : WindowsPassport } = require ( 'passport-desktop' ) ;
11
12
Passport = WindowsPassport ;
12
13
}
13
14
14
- // Import keytar dynamically based on environment
15
- let keytar : typeof import ( 'keytar' ) ;
16
-
17
- try {
18
- if ( process . env . NODE_ENV === 'development' ) {
19
- keytar = require ( 'keytar' ) ;
20
- } else {
21
- const keytarPath = path . join ( __dirname , 'native_modules' , 'keytar.node' ) ;
22
- keytar = require ( keytarPath ) ;
23
- }
24
- } catch ( error ) {
25
- console . error ( 'Failed to load native modules:' , error ) ;
26
- }
27
-
28
15
const LAST_DB_PATH = path . join ( app . getPath ( 'userData' ) , 'last_database.json' ) ;
29
16
const SERVICE_NAME = 'Vigil Password Manager' ;
30
17
const SALT_PATH = path . join ( app . getPath ( 'userData' ) , '.salt' ) ;
@@ -86,6 +73,11 @@ async function loadLastDatabasePath(): Promise<string | null> {
86
73
87
74
let biometricsAvailableCache : boolean | null = null ;
88
75
async function isBiometricsAvailable ( ) : Promise < boolean > {
76
+ if ( ! keytar ) {
77
+ console . warn ( 'Keytar is not available' ) ;
78
+ return false ;
79
+ }
80
+
89
81
if ( biometricsAvailableCache !== null ) {
90
82
return biometricsAvailableCache ;
91
83
}
@@ -206,7 +198,6 @@ function createWindow() {
206
198
// Add this handler for when the window is ready
207
199
win . webContents . on ( 'did-finish-load' , ( ) => {
208
200
if ( pendingFileOpen ) {
209
- console . log ( '[Main] Sending pending file-opened event' ) ;
210
201
win . webContents . send ( 'file-opened' , pendingFileOpen ) ;
211
202
pendingFileOpen = null ;
212
203
}
@@ -239,7 +230,7 @@ function createWindow() {
239
230
ipcMain . removeHandler ( channel ) ;
240
231
} catch ( error ) {
241
232
// Handler might already be removed
242
- console . log ( `Handler ${ channel } already removed` ) ;
233
+ console . warn ( `Handler ${ channel } already removed` ) ;
243
234
}
244
235
} ;
245
236
} ) ;
@@ -395,7 +386,7 @@ ipcMain.handle('has-biometrics-enabled', async (_, dbPath: string) => {
395
386
}
396
387
397
388
const key = await generateUniqueKey ( dbPath ) ;
398
- const hasPassword = await keytar . getPassword ( SERVICE_NAME , key ) ;
389
+ const hasPassword = await keytar ? .getPassword ( SERVICE_NAME , key ) ;
399
390
return { success : true , enabled : ! ! hasPassword } ;
400
391
} catch ( error ) {
401
392
console . error ( 'Failed to check biometrics status:' , error ) ;
@@ -498,7 +489,7 @@ ipcMain.handle('enable-biometrics', async (_, dbPath: string, password: string)
498
489
499
490
const key = await generateUniqueKey ( dbPath ) ;
500
491
const encryptedPassword = await encryptPassword ( password ) ;
501
- await keytar . setPassword ( SERVICE_NAME , key , encryptedPassword ) ;
492
+ await keytar ? .setPassword ( SERVICE_NAME , key , encryptedPassword ) ;
502
493
return { success : true } ;
503
494
} catch ( error ) {
504
495
console . error ( 'Failed to enable biometrics:' , error ) ;
@@ -517,7 +508,7 @@ ipcMain.handle('get-biometric-password', async (_, dbPath: string) => {
517
508
}
518
509
519
510
const key = await generateUniqueKey ( dbPath ) ;
520
- const encryptedPassword = await keytar . getPassword ( SERVICE_NAME , key ) ;
511
+ const encryptedPassword = await keytar ? .getPassword ( SERVICE_NAME , key ) ;
521
512
if ( ! encryptedPassword ) {
522
513
return { success : false , error : 'No password found for this database' } ;
523
514
}
@@ -533,7 +524,7 @@ ipcMain.handle('get-biometric-password', async (_, dbPath: string) => {
533
524
ipcMain . handle ( 'disable-biometrics' , async ( _ , dbPath : string ) => {
534
525
try {
535
526
const key = await generateUniqueKey ( dbPath ) ;
536
- await keytar . deletePassword ( SERVICE_NAME , key ) ;
527
+ await keytar ? .deletePassword ( SERVICE_NAME , key ) ;
537
528
return { success : true } ;
538
529
} catch ( error ) {
539
530
console . error ( 'Failed to disable biometrics:' , error ) ;
@@ -555,7 +546,6 @@ ipcMain.handle('open-external', async (_, url: string) => {
555
546
await shell . openExternal ( url ) ;
556
547
} ) ;
557
548
558
- // Add platform detection handler
559
549
ipcMain . handle ( 'get-platform' , ( ) => "win32" ) ;
560
550
561
551
// Register as default handler for kdbx files
@@ -605,4 +595,4 @@ async function handleFileOpen(filePath: string) {
605
595
} catch ( error ) {
606
596
console . error ( 'Failed to open file:' , error ) ;
607
597
}
608
- }
598
+ }
0 commit comments