Browse Source

chore: linting

pull/134/head
Matthew Raymer 1 week ago
parent
commit
55cc08d675
  1. 3
      src/App.vue
  2. 83
      src/electron/main.ts
  3. 10
      src/main.electron.ts
  4. 2
      src/services/platforms/ElectronPlatformService.ts
  5. 7
      vite.config.electron.mts

3
src/App.vue

@ -459,7 +459,8 @@ export default class App extends Vue {
return true; return true;
} }
const serverSubscription = typeof subscription === "object" && subscription !== null const serverSubscription =
typeof subscription === "object" && subscription !== null
? { ...subscription } ? { ...subscription }
: {}; : {};
if (!allGoingOff) { if (!allGoingOff) {

83
src/electron/main.ts

@ -1,35 +1,59 @@
import { app, BrowserWindow, ipcMain } from "electron"; import { app, BrowserWindow, ipcMain } from "electron";
import path from "path"; import path from "path";
import fs from "fs"; import fs from "fs";
import { CapacitorSQLiteElectron } from '@capacitor-community/sqlite/electron/dist/plugin'; import { CapacitorSQLiteElectron } from "@capacitor-community/sqlite/electron/dist/plugin";
// Initialize SQLite plugin for Electron
const sqlitePlugin = new CapacitorSQLiteElectron();
// Set up IPC handler for SQLite
ipcMain.handle('capacitor-sqlite', async (_event, ...args) => {
return sqlitePlugin.handle(_event, ...args);
});
// Initialize SQLite when app is ready
app.whenReady().then(() => {
createWindow();
});
// Simple logger implementation // Simple logger implementation
const logger = { const logger = {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
log: (...args: unknown[]) => console.log(...args), log: (...args: unknown[]) => console.log("[Main]", ...args),
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
error: (...args: unknown[]) => console.error(...args), error: (...args: unknown[]) => console.error("[Main]", ...args),
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
info: (...args: unknown[]) => console.info(...args), info: (...args: unknown[]) => console.info("[Main]", ...args),
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
warn: (...args: unknown[]) => console.warn(...args), warn: (...args: unknown[]) => console.warn("[Main]", ...args),
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
debug: (...args: unknown[]) => console.debug(...args), debug: (...args: unknown[]) => console.debug("[Main]", ...args),
}; };
// Initialize SQLite plugin for Electron
let sqlitePlugin: CapacitorSQLiteElectron | null = null;
try {
logger.info("Initializing SQLite plugin...");
sqlitePlugin = new CapacitorSQLiteElectron();
logger.info("SQLite plugin initialized successfully");
} catch (error) {
logger.error("Failed to initialize SQLite plugin:", error);
throw error;
}
// Set up IPC handler for SQLite
ipcMain.handle("capacitor-sqlite", async (_event, ...args) => {
if (!sqlitePlugin) {
const error = new Error("SQLite plugin not initialized");
logger.error(error);
throw error;
}
try {
logger.debug("Handling SQLite request:", args);
const result = await sqlitePlugin.handle(_event, ...args);
logger.debug("SQLite request completed successfully");
return result;
} catch (error) {
logger.error("SQLite request failed:", error);
throw error;
}
});
// Initialize app when ready
app.whenReady().then(() => {
logger.info("App is ready, creating window...");
createWindow();
});
// Check if running in dev mode // Check if running in dev mode
const isDev = process.argv.includes("--inspect"); const isDev = process.argv.includes("--inspect");
@ -133,11 +157,15 @@ function createWindow(): void {
if (app.isPackaged) { if (app.isPackaged) {
// In production, files are inside the asar archive or extraResources // In production, files are inside the asar archive or extraResources
indexPath = path.join(process.resourcesPath, "www", "index.html"); indexPath = path.join(process.resourcesPath, "www", "index.html");
logger.info("[Electron] App is packaged. Using process.resourcesPath for index.html"); logger.info(
"[Electron] App is packaged. Using process.resourcesPath for index.html",
);
} else { } else {
// In dev, use the local path // In dev, use the local path
indexPath = path.resolve(__dirname, "www", "index.html"); indexPath = path.resolve(__dirname, "www", "index.html");
logger.info("[Electron] App is not packaged. Using __dirname for index.html"); logger.info(
"[Electron] App is not packaged. Using __dirname for index.html",
);
} }
logger.info("[Electron] Resolved index.html path:", indexPath); logger.info("[Electron] Resolved index.html path:", indexPath);
@ -150,7 +178,9 @@ function createWindow(): void {
// Removed fs.existsSync check to allow Electron to attempt loading regardless // Removed fs.existsSync check to allow Electron to attempt loading regardless
logger.info("[Electron] Attempting to load index.html via mainWindow.loadFile"); logger.info(
"[Electron] Attempting to load index.html via mainWindow.loadFile",
);
mainWindow mainWindow
.loadFile(indexPath) .loadFile(indexPath)
.then(() => { .then(() => {
@ -165,9 +195,14 @@ function createWindow(): void {
logger.error("[Electron] Attempted path:", indexPath); logger.error("[Electron] Attempted path:", indexPath);
try { try {
const exists = fs.existsSync(indexPath); const exists = fs.existsSync(indexPath);
logger.error(`[Electron] fs.existsSync after loadFile error: ${exists}`); logger.error(
`[Electron] fs.existsSync after loadFile error: ${exists}`,
);
} catch (e) { } catch (e) {
logger.error("[Electron] Error checking fs.existsSync after loadFile error:", e); logger.error(
"[Electron] Error checking fs.existsSync after loadFile error:",
e,
);
} }
}); });

10
src/main.electron.ts

@ -1,16 +1,16 @@
import { initializeApp } from "./main.common"; import { initializeApp } from "./main.common";
import { logger } from "./utils/logger"; import { logger } from "./utils/logger";
import { Capacitor } from '@capacitor/core'; import { Capacitor } from "@capacitor/core";
import { CapacitorSQLite } from '@capacitor-community/sqlite'; import { CapacitorSQLite } from "@capacitor-community/sqlite";
// Initialize Capacitor for Electron // Initialize Capacitor for Electron
Object.defineProperty(Capacitor, 'isNativePlatform', { Object.defineProperty(Capacitor, "isNativePlatform", {
get: () => true, get: () => true,
configurable: true configurable: true,
}); });
// Initialize SQLite plugin for Electron // Initialize SQLite plugin for Electron
if (typeof window !== 'undefined') { if (typeof window !== "undefined") {
// Register the plugin globally // Register the plugin globally
window.CapacitorSQLite = CapacitorSQLite; window.CapacitorSQLite = CapacitorSQLite;
logger.info("[Electron] SQLite plugin initialized in native mode"); logger.info("[Electron] SQLite plugin initialized in native mode");

2
src/services/platforms/ElectronPlatformService.ts

@ -51,7 +51,7 @@ export class ElectronPlatformService implements PlatformService {
false, false,
"no-encryption", "no-encryption",
1, 1,
true // Use native implementation true, // Use native implementation
); );
await this.db.open(); await this.db.open();

7
vite.config.electron.mts

@ -24,7 +24,12 @@ export default defineConfig(async ({ mode }) => {
main: path.resolve(__dirname, 'src/electron/main.ts'), main: path.resolve(__dirname, 'src/electron/main.ts'),
preload: path.resolve(__dirname, 'src/electron/preload.js'), preload: path.resolve(__dirname, 'src/electron/preload.js'),
}, },
external: ['electron'], external: [
'electron',
'@capacitor-community/sqlite',
'@capacitor-community/sqlite/electron',
'better-sqlite3-multiple-ciphers'
],
output: { output: {
format: 'cjs', format: 'cjs',
entryFileNames: '[name].js', entryFileNames: '[name].js',

Loading…
Cancel
Save