[170] Linux-Paket: AppImage (electron-builder), .obp-Dateizuordnung, Datei per Argument, Release-Job
Gepackt lädt Electron dist über dossier://app; einzige Instanz reicht .obp-Argumente weiter. Flatpak-Manifest unter packaging/linux (ungetestet). Doku in README, Website und TODO.
This commit is contained in:
17 files changed
+3172
-12
No files matched your search
+105
-4
@@ -4,8 +4,9 @@
|
||||
// (render2d-WASM-Engine, ?engine=wasm) zuverlässig läuft. Kein Rust-Backend
|
||||
// nötig: compute_joins hat einen TS-Fallback (src/compute/index.ts).
|
||||
|
||||
const { app, BrowserWindow, Menu, ipcMain } = require("electron");
|
||||
const { app, BrowserWindow, Menu, ipcMain, protocol, session } = require("electron");
|
||||
const path = require("node:path");
|
||||
const fs = require("node:fs");
|
||||
const { buildCsp } = require("./csp.cjs");
|
||||
|
||||
// Randloses App-Fenster wie chromium-shell.sh (--app=…): keine native
|
||||
@@ -21,10 +22,104 @@ app.commandLine.appendSwitch("enable-unsafe-webgpu");
|
||||
app.commandLine.appendSwitch("enable-features", "Vulkan,VulkanFromANGLE,DefaultANGLEVulkan");
|
||||
|
||||
const DEV_URL = "http://localhost:5187";
|
||||
const isDev = !app.isPackaged;
|
||||
const isDev = !app.isPackaged && !process.env.DOSSIER_USE_DIST; // DOSSIER_USE_DIST=1: gebautes dist ohne Paket prüfen
|
||||
|
||||
// [170] Gepackt (AppImage/Flatpak) lädt die App aus `dist` über ein eigenes, „standard“-Schema statt
|
||||
// file://: absolute Asset-Pfade (/assets/…), fetch() der WASM-Module (application/wasm), Worker und
|
||||
// localStorage brauchen einen richtigen Ursprung. Muss vor `ready` registriert werden.
|
||||
const APP_SCHEME = "dossier";
|
||||
const APP_ORIGIN = `${APP_SCHEME}://app`;
|
||||
const DIST_DIR = path.join(__dirname, "..", "dist");
|
||||
const MIME = {
|
||||
".html": "text/html; charset=utf-8",
|
||||
".js": "text/javascript; charset=utf-8",
|
||||
".mjs": "text/javascript; charset=utf-8",
|
||||
".css": "text/css; charset=utf-8",
|
||||
".json": "application/json; charset=utf-8",
|
||||
".wasm": "application/wasm",
|
||||
".svg": "image/svg+xml",
|
||||
".png": "image/png",
|
||||
".jpg": "image/jpeg",
|
||||
".webp": "image/webp",
|
||||
".woff": "font/woff",
|
||||
".woff2": "font/woff2",
|
||||
".ttf": "font/ttf",
|
||||
".txt": "text/plain; charset=utf-8",
|
||||
".map": "application/json; charset=utf-8",
|
||||
};
|
||||
protocol.registerSchemesAsPrivileged([
|
||||
{ scheme: APP_SCHEME, privileges: { standard: true, secure: true, supportFetchAPI: true, stream: true, corsEnabled: true } },
|
||||
]);
|
||||
|
||||
function serveDist(request) {
|
||||
const { pathname } = new URL(request.url);
|
||||
let rel = decodeURIComponent(pathname);
|
||||
if (rel === "/" || rel === "") rel = "/index.html";
|
||||
const file = path.normalize(path.join(DIST_DIR, rel));
|
||||
// Kein Ausbruch aus dist (../).
|
||||
if (file !== DIST_DIR && !file.startsWith(DIST_DIR + path.sep)) return new Response("Forbidden", { status: 403 });
|
||||
try {
|
||||
const body = fs.readFileSync(file);
|
||||
const type = MIME[path.extname(file).toLowerCase()] || "application/octet-stream";
|
||||
return new Response(body, { headers: { "content-type": type } });
|
||||
} catch {
|
||||
return new Response("Not found", { status: 404 });
|
||||
}
|
||||
}
|
||||
|
||||
// [170] Projektdatei per Argument (`dossier datei.obp`, Doppelklick im Dateimanager über %F im
|
||||
// Desktop-Eintrag). Erste vorhandene .obp-Datei der Argumente; relative Pfade gegen `cwd`.
|
||||
function findProjectArg(argv, cwd) {
|
||||
for (const a of argv.slice(1)) {
|
||||
if (!a || a.startsWith("-") || !/\.obp$/i.test(a)) continue;
|
||||
const full = path.resolve(cwd || process.cwd(), a);
|
||||
try {
|
||||
if (fs.statSync(full).isFile()) return full;
|
||||
} catch {
|
||||
/* nicht vorhanden: ignorieren */
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
let mainWindow = null;
|
||||
let pendingOpenFile = findProjectArg(process.argv, process.cwd());
|
||||
|
||||
function readProject(file) {
|
||||
try {
|
||||
return { name: path.basename(file), path: file, text: fs.readFileSync(file, "utf8") };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Nur eine Instanz: ein zweiter Start (`dossier b.obp`) reicht die Datei an das offene Fenster weiter.
|
||||
const gotLock = app.requestSingleInstanceLock();
|
||||
if (!gotLock) {
|
||||
app.quit();
|
||||
} else {
|
||||
app.on("second-instance", (_event, argv, cwd) => {
|
||||
const file = findProjectArg(argv, cwd);
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) mainWindow.restore();
|
||||
mainWindow.focus();
|
||||
const proj = file && readProject(file);
|
||||
if (proj) mainWindow.webContents.send("launch:open-file", proj);
|
||||
} else if (file) {
|
||||
pendingOpenFile = file;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ipcMain.handle("launch:take-open-file", () => {
|
||||
const file = pendingOpenFile;
|
||||
pendingOpenFile = null;
|
||||
return file ? readProject(file) : null;
|
||||
});
|
||||
|
||||
function createWindow() {
|
||||
const win = new BrowserWindow({
|
||||
title: "Dossier",
|
||||
width: 1600,
|
||||
height: 1000,
|
||||
frame: false,
|
||||
@@ -36,6 +131,11 @@ function createWindow() {
|
||||
},
|
||||
});
|
||||
|
||||
mainWindow = win;
|
||||
win.on("closed", () => {
|
||||
if (mainWindow === win) mainWindow = null;
|
||||
});
|
||||
|
||||
const notifyMaximized = () => {
|
||||
win.webContents.send("window:maximized-changed", win.isMaximized());
|
||||
};
|
||||
@@ -45,7 +145,7 @@ function createWindow() {
|
||||
if (isDev) {
|
||||
win.loadURL(DEV_URL);
|
||||
} else {
|
||||
win.loadFile(require("node:path").join(__dirname, "..", "dist", "index.html"));
|
||||
win.loadURL(`${APP_ORIGIN}/index.html`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,9 +168,10 @@ ipcMain.handle("window:is-maximized", (event) => {
|
||||
});
|
||||
|
||||
app.whenReady().then(() => {
|
||||
if (!gotLock) return;
|
||||
// [117] CSP als Antwort-Header — nur gepackt: der Dev-Server (Vite HMR) braucht Inline-Skripte.
|
||||
if (!isDev) {
|
||||
const { session } = require("electron");
|
||||
protocol.handle(APP_SCHEME, serveDist);
|
||||
session.defaultSession.webRequest.onHeadersReceived((details, cb) => {
|
||||
cb({ responseHeaders: { ...details.responseHeaders, "Content-Security-Policy": [buildCsp()] } });
|
||||
});
|
||||
|
||||
@@ -17,3 +17,14 @@ contextBridge.exposeInMainWorld("dossierWindow", {
|
||||
return () => ipcRenderer.removeListener("window:maximized-changed", listener);
|
||||
},
|
||||
});
|
||||
|
||||
// [170] Projektdatei, mit der die App gestartet wurde (`dossier datei.obp`), und spätere Aufrufe
|
||||
// einer zweiten Instanz. Inhalt wird im Hauptprozess gelesen: {name, path, text} oder null.
|
||||
contextBridge.exposeInMainWorld("dossierLaunch", {
|
||||
takeOpenFile: () => ipcRenderer.invoke("launch:take-open-file"),
|
||||
onOpenFile: (callback) => {
|
||||
const listener = (_event, file) => callback(file);
|
||||
ipcRenderer.on("launch:open-file", listener);
|
||||
return () => ipcRenderer.removeListener("launch:open-file", listener);
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user