Skip to content

Commit 8aee1ca

Browse files
EaruRyan
and
Ryan
authored
Bug fixes & Import from csv (#9)
* develop branch, start working on browser imports * chromium browser imports * UI to let user select browsers to import * add vivaldi, opera and chromium to browser imports * add firefox password importing * style tweaks for the browser selection modal * maybe fix pyinstaller in CI * dont forget submodules * remove unnecessary function * im not even sure why i didnt do this from the start * fix an oversight --------- Co-authored-by: Ryan <ryan.rbsr@gmail.com>
1 parent 0f76e2c commit 8aee1ca

13 files changed

+1399
-149
lines changed

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Build Electron App
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [ main, develop ]
66
pull_request:
7-
branches: [ main ]
7+
branches: [ main, develop ]
88

99
jobs:
1010
build:

electron/copy-native-modules.mjs

+8-7
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ if (!fs.existsSync(destDir)) {
5757
}
5858

5959
// Copy node native modules
60-
for (const module of modulesToCopy) {
60+
for (const moduleName of modulesToCopy) {
6161
try {
62-
const sourcePath = getModulePath(module);
63-
const destPath = path.join(destDir, path.basename(sourcePath));
64-
fs.copyFileSync(sourcePath, destPath);
65-
console.log(`Copied ${module} native module to ${destPath}`);
66-
} catch (err) {
67-
console.error(`Failed to copy ${module}:`, err);
62+
const modulePath = getModulePath(moduleName);
63+
const fileName = path.basename(modulePath);
64+
const targetPath = path.join(process.cwd(), 'dist-electron', fileName);
65+
fs.copyFileSync(modulePath, targetPath);
66+
console.log(`Copied ${fileName} to dist-electron`);
67+
} catch (error) {
68+
console.error(`Failed to copy ${moduleName}:`, error);
6869
process.exit(1);
6970
}
7071
}

electron/get-keytar.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { join } from 'path';
2+
3+
// Import keytar dynamically based on environment
4+
let keytar: typeof import('keytar') | undefined = undefined;
5+
6+
try {
7+
if (process.env.NODE_ENV === 'development') {
8+
keytar = require('keytar');
9+
} else {
10+
const keytarPath = join(__dirname, 'native_modules', 'keytar.node');
11+
keytar = require(keytarPath);
12+
}
13+
} catch (error) {
14+
console.error('Failed to load native modules:', error);
15+
}
16+
17+
export default keytar;

electron/main.ts

+12-22
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,14 @@ import fs from 'fs'
44
import * as argon2 from '@node-rs/argon2';
55
import { createCipheriv, createDecipheriv, pbkdf2Sync, randomBytes } from 'crypto';
66
import { execSync } from 'child_process';
7+
import keytar from './get-keytar';
78

89
let Passport: any;
910
if (process.platform === 'win32') {
1011
const { Passport: WindowsPassport } = require('passport-desktop');
1112
Passport = WindowsPassport;
1213
}
1314

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-
2815
const LAST_DB_PATH = path.join(app.getPath('userData'), 'last_database.json');
2916
const SERVICE_NAME = 'Vigil Password Manager';
3017
const SALT_PATH = path.join(app.getPath('userData'), '.salt');
@@ -86,6 +73,11 @@ async function loadLastDatabasePath(): Promise<string | null> {
8673

8774
let biometricsAvailableCache: boolean | null = null;
8875
async function isBiometricsAvailable(): Promise<boolean> {
76+
if (!keytar) {
77+
console.warn('Keytar is not available');
78+
return false;
79+
}
80+
8981
if (biometricsAvailableCache !== null) {
9082
return biometricsAvailableCache;
9183
}
@@ -206,7 +198,6 @@ function createWindow() {
206198
// Add this handler for when the window is ready
207199
win.webContents.on('did-finish-load', () => {
208200
if (pendingFileOpen) {
209-
console.log('[Main] Sending pending file-opened event');
210201
win.webContents.send('file-opened', pendingFileOpen);
211202
pendingFileOpen = null;
212203
}
@@ -239,7 +230,7 @@ function createWindow() {
239230
ipcMain.removeHandler(channel);
240231
} catch (error) {
241232
// Handler might already be removed
242-
console.log(`Handler ${channel} already removed`);
233+
console.warn(`Handler ${channel} already removed`);
243234
}
244235
};
245236
});
@@ -395,7 +386,7 @@ ipcMain.handle('has-biometrics-enabled', async (_, dbPath: string) => {
395386
}
396387

397388
const key = await generateUniqueKey(dbPath);
398-
const hasPassword = await keytar.getPassword(SERVICE_NAME, key);
389+
const hasPassword = await keytar?.getPassword(SERVICE_NAME, key);
399390
return { success: true, enabled: !!hasPassword };
400391
} catch (error) {
401392
console.error('Failed to check biometrics status:', error);
@@ -498,7 +489,7 @@ ipcMain.handle('enable-biometrics', async (_, dbPath: string, password: string)
498489

499490
const key = await generateUniqueKey(dbPath);
500491
const encryptedPassword = await encryptPassword(password);
501-
await keytar.setPassword(SERVICE_NAME, key, encryptedPassword);
492+
await keytar?.setPassword(SERVICE_NAME, key, encryptedPassword);
502493
return { success: true };
503494
} catch (error) {
504495
console.error('Failed to enable biometrics:', error);
@@ -517,7 +508,7 @@ ipcMain.handle('get-biometric-password', async (_, dbPath: string) => {
517508
}
518509

519510
const key = await generateUniqueKey(dbPath);
520-
const encryptedPassword = await keytar.getPassword(SERVICE_NAME, key);
511+
const encryptedPassword = await keytar?.getPassword(SERVICE_NAME, key);
521512
if (!encryptedPassword) {
522513
return { success: false, error: 'No password found for this database' };
523514
}
@@ -533,7 +524,7 @@ ipcMain.handle('get-biometric-password', async (_, dbPath: string) => {
533524
ipcMain.handle('disable-biometrics', async (_, dbPath: string) => {
534525
try {
535526
const key = await generateUniqueKey(dbPath);
536-
await keytar.deletePassword(SERVICE_NAME, key);
527+
await keytar?.deletePassword(SERVICE_NAME, key);
537528
return { success: true };
538529
} catch (error) {
539530
console.error('Failed to disable biometrics:', error);
@@ -555,7 +546,6 @@ ipcMain.handle('open-external', async (_, url: string) => {
555546
await shell.openExternal(url);
556547
});
557548

558-
// Add platform detection handler
559549
ipcMain.handle('get-platform', () => "win32");
560550

561551
// Register as default handler for kdbx files
@@ -605,4 +595,4 @@ async function handleFileOpen(filePath: string) {
605595
} catch (error) {
606596
console.error('Failed to open file:', error);
607597
}
608-
}
598+
}

0 commit comments

Comments
 (0)