Skip to content

Commit

Permalink
Bug fixes & Import from csv (#9)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Earu and Ryan authored Jan 2, 2025
1 parent 0f76e2c commit 8aee1ca
Show file tree
Hide file tree
Showing 13 changed files with 1,399 additions and 149 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Build Electron App

on:
push:
branches: [ main ]
branches: [ main, develop ]
pull_request:
branches: [ main ]
branches: [ main, develop ]

jobs:
build:
Expand Down
15 changes: 8 additions & 7 deletions electron/copy-native-modules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ if (!fs.existsSync(destDir)) {
}

// Copy node native modules
for (const module of modulesToCopy) {
for (const moduleName of modulesToCopy) {
try {
const sourcePath = getModulePath(module);
const destPath = path.join(destDir, path.basename(sourcePath));
fs.copyFileSync(sourcePath, destPath);
console.log(`Copied ${module} native module to ${destPath}`);
} catch (err) {
console.error(`Failed to copy ${module}:`, err);
const modulePath = getModulePath(moduleName);
const fileName = path.basename(modulePath);
const targetPath = path.join(process.cwd(), 'dist-electron', fileName);
fs.copyFileSync(modulePath, targetPath);
console.log(`Copied ${fileName} to dist-electron`);
} catch (error) {
console.error(`Failed to copy ${moduleName}:`, error);
process.exit(1);
}
}
17 changes: 17 additions & 0 deletions electron/get-keytar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { join } from 'path';

// Import keytar dynamically based on environment
let keytar: typeof import('keytar') | undefined = undefined;

try {
if (process.env.NODE_ENV === 'development') {
keytar = require('keytar');
} else {
const keytarPath = join(__dirname, 'native_modules', 'keytar.node');
keytar = require(keytarPath);
}
} catch (error) {
console.error('Failed to load native modules:', error);
}

export default keytar;
34 changes: 12 additions & 22 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,14 @@ import fs from 'fs'
import * as argon2 from '@node-rs/argon2';
import { createCipheriv, createDecipheriv, pbkdf2Sync, randomBytes } from 'crypto';
import { execSync } from 'child_process';
import keytar from './get-keytar';

let Passport: any;
if (process.platform === 'win32') {
const { Passport: WindowsPassport } = require('passport-desktop');
Passport = WindowsPassport;
}

// Import keytar dynamically based on environment
let keytar: typeof import('keytar');

try {
if (process.env.NODE_ENV === 'development') {
keytar = require('keytar');
} else {
const keytarPath = path.join(__dirname, 'native_modules', 'keytar.node');
keytar = require(keytarPath);
}
} catch (error) {
console.error('Failed to load native modules:', error);
}

const LAST_DB_PATH = path.join(app.getPath('userData'), 'last_database.json');
const SERVICE_NAME = 'Vigil Password Manager';
const SALT_PATH = path.join(app.getPath('userData'), '.salt');
Expand Down Expand Up @@ -86,6 +73,11 @@ async function loadLastDatabasePath(): Promise<string | null> {

let biometricsAvailableCache: boolean | null = null;
async function isBiometricsAvailable(): Promise<boolean> {
if (!keytar) {
console.warn('Keytar is not available');
return false;
}

if (biometricsAvailableCache !== null) {
return biometricsAvailableCache;
}
Expand Down Expand Up @@ -206,7 +198,6 @@ function createWindow() {
// Add this handler for when the window is ready
win.webContents.on('did-finish-load', () => {
if (pendingFileOpen) {
console.log('[Main] Sending pending file-opened event');
win.webContents.send('file-opened', pendingFileOpen);
pendingFileOpen = null;
}
Expand Down Expand Up @@ -239,7 +230,7 @@ function createWindow() {
ipcMain.removeHandler(channel);
} catch (error) {
// Handler might already be removed
console.log(`Handler ${channel} already removed`);
console.warn(`Handler ${channel} already removed`);
}
};
});
Expand Down Expand Up @@ -395,7 +386,7 @@ ipcMain.handle('has-biometrics-enabled', async (_, dbPath: string) => {
}

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

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

const key = await generateUniqueKey(dbPath);
const encryptedPassword = await keytar.getPassword(SERVICE_NAME, key);
const encryptedPassword = await keytar?.getPassword(SERVICE_NAME, key);
if (!encryptedPassword) {
return { success: false, error: 'No password found for this database' };
}
Expand All @@ -533,7 +524,7 @@ ipcMain.handle('get-biometric-password', async (_, dbPath: string) => {
ipcMain.handle('disable-biometrics', async (_, dbPath: string) => {
try {
const key = await generateUniqueKey(dbPath);
await keytar.deletePassword(SERVICE_NAME, key);
await keytar?.deletePassword(SERVICE_NAME, key);
return { success: true };
} catch (error) {
console.error('Failed to disable biometrics:', error);
Expand All @@ -555,7 +546,6 @@ ipcMain.handle('open-external', async (_, url: string) => {
await shell.openExternal(url);
});

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

// Register as default handler for kdbx files
Expand Down Expand Up @@ -605,4 +595,4 @@ async function handleFileOpen(filePath: string) {
} catch (error) {
console.error('Failed to open file:', error);
}
}
}
Loading

0 comments on commit 8aee1ca

Please sign in to comment.