WIP: Fix Electron build issues and migrate to @nostr/tools

- Fix TypeScript compilation errors in platform services
- Add missing rotateCamera method and isNativeApp property
- Fix index.html path resolution for packaged Electron apps
- Create separate Vite config for Electron renderer process
- Migrate from nostr-tools to @nostr/tools via JSR for ESM compatibility
- Update all Vite configs to handle mixed npm/JSR package management
- Add comprehensive documentation in BUILDING.md
- Fix preload script path resolution in packaged builds

Resolves build failures with deep imports and missing UI in AppImage.
This commit is contained in:
Matthew Raymer
2025-06-25 08:53:21 +00:00
parent 94ac7d648d
commit fe55d0b431
18 changed files with 305 additions and 167 deletions

View File

@@ -21,7 +21,9 @@ const isDev = process.argv.includes("--inspect");
function createWindow(): void {
// Add before createWindow function
const preloadPath = path.join(__dirname, "preload.js");
const preloadPath = app.isPackaged
? path.join(app.getAppPath(), "dist-electron", "preload.js")
: path.join(__dirname, "preload.js");
logger.log("Checking preload path:", preloadPath);
logger.log("Preload exists:", fs.existsSync(preloadPath));
@@ -53,7 +55,7 @@ function createWindow(): void {
contextIsolation: true,
webSecurity: true,
allowRunningInsecureContent: false,
preload: path.join(__dirname, "preload.js"),
preload: preloadPath,
},
});
@@ -107,15 +109,27 @@ function createWindow(): void {
logger.log("process.cwd():", process.cwd());
}
let indexPath = path.resolve(__dirname, "dist-electron", "www", "index.html");
if (!fs.existsSync(indexPath)) {
// Fallback for dev mode
let indexPath: string;
if (app.isPackaged) {
indexPath = path.join(
app.getAppPath(),
"dist-electron",
"www",
"index.html",
);
logger.log("[main.ts] Using packaged indexPath:", indexPath);
} else {
indexPath = path.resolve(
process.cwd(),
"dist-electron",
"www",
"index.html",
);
logger.log("[main.ts] Using dev indexPath:", indexPath);
if (!fs.existsSync(indexPath)) {
logger.error("[main.ts] Dev index.html not found:", indexPath);
throw new Error("Index file not found");
}
}
if (isDev) {
@@ -124,11 +138,6 @@ function createWindow(): void {
logger.log("www assets path:", path.join(__dirname, "www", "assets"));
}
if (!fs.existsSync(indexPath)) {
logger.error(`Index file not found at: ${indexPath}`);
throw new Error("Index file not found");
}
// Add CSP headers to allow API connections
mainWindow.webContents.session.webRequest.onHeadersReceived(
(details, callback) => {

View File

@@ -4,7 +4,7 @@ export interface GenericVerifiableCredential {
"@type": string;
name?: string;
description?: string;
agent?: string;
agent?: string | { identifier: string };
[key: string]: unknown;
}

View File

@@ -205,6 +205,7 @@ export class ElectronPlatformService implements PlatformService {
isIOS: false,
hasFileDownload: false, // Not implemented yet
needsFileHandlingInstructions: false,
isNativeApp: true, // Electron is a native app
};
}
@@ -345,4 +346,13 @@ export class ElectronPlatformService implements PlatformService {
);
}
}
/**
* Rotates the camera between front and back cameras.
* @returns Promise that resolves when the camera is rotated
* @throws Error indicating camera rotation is not implemented in Electron
*/
async rotateCamera(): Promise<void> {
throw new Error("Camera rotation not implemented in Electron platform");
}
}

View File

@@ -33,6 +33,7 @@ export class WebPlatformService implements PlatformService {
isIOS: /iPad|iPhone|iPod/.test(navigator.userAgent),
hasFileDownload: true,
needsFileHandlingInstructions: false,
isNativeApp: false, // Web is not a native app
};
}
@@ -382,4 +383,13 @@ export class WebPlatformService implements PlatformService {
.query(sql, params)
.then((result: QueryExecResult[]) => result[0]?.values[0]);
}
/**
* Rotates the camera between front and back cameras.
* @returns Promise that resolves when the camera is rotated
* @throws Error indicating camera rotation is not implemented in web platform
*/
async rotateCamera(): Promise<void> {
throw new Error("Camera rotation not implemented in web platform");
}
}

View File

@@ -4,6 +4,7 @@ import * as databaseUtil from "../db/databaseUtil";
import { SERVICE_ID } from "../libs/endorserServer";
import { deriveAddress, newIdentifier } from "../libs/crypto";
import { logger } from "../utils/logger";
import { AppString } from "../constants/app";
/**
* Get User #0 to sign & submit a RegisterAction for the user's activeDid.
*/

View File

@@ -345,7 +345,6 @@ import { logger } from "../utils/logger";
import { GiveRecordWithContactInfo } from "../interfaces/give";
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
import * as Package from "../../package.json";
import { id_ce_authorityKeyIdentifier } from "node_modules/@simplewebauthn/server/esm/deps";
interface Claim {
claim?: Claim; // For nested claims in Verifiable Credentials

View File

@@ -217,11 +217,11 @@
import "leaflet/dist/leaflet.css";
import { AxiosError, AxiosRequestHeaders } from "axios";
import { DateTime } from "luxon";
import { finalizeEvent } from "nostr-tools/lib/esm/index.js";
import { finalizeEvent } from "@nostr/tools";
import {
accountFromExtendedKey,
extendedKeysFromSeedWords,
} from "nostr-tools/lib/esm/nip06.js";
} from "@nostr/tools/nip06";
import { Component, Vue } from "vue-facing-decorator";
import { LMap, LMarker, LTileLayer } from "@vue-leaflet/vue-leaflet";
import { RouteLocationNormalizedLoaded, Router } from "vue-router";
@@ -244,12 +244,14 @@ import {
retrieveAccountCount,
retrieveFullyDecryptedAccount,
} from "../libs/util";
import {
EventTemplate,
UnsignedEvent,
VerifiedEvent,
} from "nostr-tools/lib/esm/index.js";
import { serializeEvent } from "nostr-tools/lib/esm/index.js";
serializeEvent,
} from "@nostr/tools";
// @ts-ignore
import { logger } from "../utils/logger";
@Component({
components: { ImageMethodDialog, LMap, LMarker, LTileLayer, QuickNav },