forked from trent_larson/crowd-funder-for-time-pwa
docs: move build instructions from README to BUILDING.md
- Move detailed setup and build instructions from README.md to BUILDING.md - Add concise reference to BUILDING.md in README.md - Keep testing and other documentation in README.md - Improve organization of documentation by separating build-specific content
This commit is contained in:
@@ -3,13 +3,13 @@ const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
// Check if running in dev mode
|
||||
const isDev = process.argv.includes('--inspect');
|
||||
const isDev = process.argv.includes("--inspect");
|
||||
|
||||
function createWindow() {
|
||||
// Add before createWindow function
|
||||
const preloadPath = path.join(__dirname, 'preload.js');
|
||||
console.log('Checking preload path:', preloadPath);
|
||||
console.log('Preload exists:', fs.existsSync(preloadPath));
|
||||
const preloadPath = path.join(__dirname, "preload.js");
|
||||
console.log("Checking preload path:", preloadPath);
|
||||
console.log("Preload exists:", fs.existsSync(preloadPath));
|
||||
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
@@ -20,7 +20,7 @@ function createWindow() {
|
||||
contextIsolation: true,
|
||||
webSecurity: true,
|
||||
allowRunningInsecureContent: false,
|
||||
preload: path.join(__dirname, 'preload.js')
|
||||
preload: path.join(__dirname, "preload.js"),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -33,30 +33,32 @@ function createWindow() {
|
||||
console.log("__dirname:", __dirname);
|
||||
console.log("process.cwd():", process.cwd());
|
||||
|
||||
const indexPath = path.join(__dirname, 'www', 'index.html');
|
||||
console.log("www path:", path.join(__dirname, 'www'));
|
||||
console.log("www assets path:", path.join(__dirname, 'www', 'assets'));
|
||||
const indexPath = path.join(__dirname, "www", "index.html");
|
||||
console.log("www path:", path.join(__dirname, "www"));
|
||||
console.log("www assets path:", path.join(__dirname, "www", "assets"));
|
||||
|
||||
if (!fs.existsSync(indexPath)) {
|
||||
console.error(`Index file not found at: ${indexPath}`);
|
||||
throw new Error('Index file not found');
|
||||
throw new Error("Index file not found");
|
||||
}
|
||||
|
||||
// Set CSP headers
|
||||
mainWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
|
||||
callback({
|
||||
responseHeaders: {
|
||||
...details.responseHeaders,
|
||||
'Content-Security-Policy': [
|
||||
"default-src 'self';" +
|
||||
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;" +
|
||||
"font-src 'self' https://fonts.gstatic.com;" +
|
||||
"script-src 'self' 'unsafe-eval' 'unsafe-inline';" +
|
||||
"img-src 'self' data: https:;"
|
||||
]
|
||||
}
|
||||
});
|
||||
});
|
||||
mainWindow.webContents.session.webRequest.onHeadersReceived(
|
||||
(details, callback) => {
|
||||
callback({
|
||||
responseHeaders: {
|
||||
...details.responseHeaders,
|
||||
"Content-Security-Policy": [
|
||||
"default-src 'self';" +
|
||||
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;" +
|
||||
"font-src 'self' https://fonts.gstatic.com;" +
|
||||
"script-src 'self' 'unsafe-eval' 'unsafe-inline';" +
|
||||
"img-src 'self' data: https:;",
|
||||
],
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
// Load the index.html
|
||||
mainWindow
|
||||
@@ -79,17 +81,23 @@ function createWindow() {
|
||||
});
|
||||
|
||||
// Add right after creating the BrowserWindow
|
||||
mainWindow.webContents.on('did-fail-load', (event, errorCode, errorDescription) => {
|
||||
console.error('Page failed to load:', errorCode, errorDescription);
|
||||
mainWindow.webContents.on(
|
||||
"did-fail-load",
|
||||
(event, errorCode, errorDescription) => {
|
||||
console.error("Page failed to load:", errorCode, errorDescription);
|
||||
},
|
||||
);
|
||||
|
||||
mainWindow.webContents.on("preload-error", (event, preloadPath, error) => {
|
||||
console.error("Preload script error:", preloadPath, error);
|
||||
});
|
||||
|
||||
mainWindow.webContents.on('preload-error', (event, preloadPath, error) => {
|
||||
console.error('Preload script error:', preloadPath, error);
|
||||
});
|
||||
|
||||
mainWindow.webContents.on('console-message', (event, level, message, line, sourceId) => {
|
||||
console.log('Renderer Console:', message);
|
||||
});
|
||||
mainWindow.webContents.on(
|
||||
"console-message",
|
||||
(event, level, message, line, sourceId) => {
|
||||
console.log("Renderer Console:", line, sourceId, message);
|
||||
},
|
||||
);
|
||||
|
||||
// Enable remote debugging when in dev mode
|
||||
if (isDev) {
|
||||
|
||||
@@ -1,39 +1,40 @@
|
||||
const { contextBridge, ipcRenderer } = require('electron');
|
||||
const { contextBridge, ipcRenderer } = require("electron");
|
||||
|
||||
// Use a more direct path resolution approach
|
||||
const getPath = (pathType) => {
|
||||
switch(pathType) {
|
||||
case 'userData':
|
||||
return process.env.APPDATA || (
|
||||
process.platform === 'darwin'
|
||||
switch (pathType) {
|
||||
case "userData":
|
||||
return (
|
||||
process.env.APPDATA ||
|
||||
(process.platform === "darwin"
|
||||
? `${process.env.HOME}/Library/Application Support`
|
||||
: `${process.env.HOME}/.local/share`
|
||||
: `${process.env.HOME}/.local/share`)
|
||||
);
|
||||
case 'home':
|
||||
case "home":
|
||||
return process.env.HOME;
|
||||
case 'appPath':
|
||||
case "appPath":
|
||||
return process.resourcesPath;
|
||||
default:
|
||||
return '';
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
console.log('Preload script starting...');
|
||||
console.log("Preload script starting...");
|
||||
|
||||
try {
|
||||
contextBridge.exposeInMainWorld('electronAPI', {
|
||||
contextBridge.exposeInMainWorld("electronAPI", {
|
||||
// Path utilities
|
||||
getPath,
|
||||
|
||||
|
||||
// IPC functions
|
||||
send: (channel, data) => {
|
||||
const validChannels = ['toMain'];
|
||||
const validChannels = ["toMain"];
|
||||
if (validChannels.includes(channel)) {
|
||||
ipcRenderer.send(channel, data);
|
||||
}
|
||||
},
|
||||
receive: (channel, func) => {
|
||||
const validChannels = ['fromMain'];
|
||||
const validChannels = ["fromMain"];
|
||||
if (validChannels.includes(channel)) {
|
||||
ipcRenderer.on(channel, (event, ...args) => func(...args));
|
||||
}
|
||||
@@ -41,15 +42,15 @@ try {
|
||||
// Environment info
|
||||
env: {
|
||||
isElectron: true,
|
||||
isDev: process.env.NODE_ENV === 'development'
|
||||
isDev: process.env.NODE_ENV === "development",
|
||||
},
|
||||
// Path utilities
|
||||
getBasePath: () => {
|
||||
return process.env.NODE_ENV === 'development' ? '/' : './';
|
||||
}
|
||||
return process.env.NODE_ENV === "development" ? "/" : "./";
|
||||
},
|
||||
});
|
||||
|
||||
console.log('Preload script completed successfully');
|
||||
console.log("Preload script completed successfully");
|
||||
} catch (error) {
|
||||
console.error('Error in preload script:', error);
|
||||
}
|
||||
console.error("Error in preload script:", error);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
import { register } from "register-service-worker";
|
||||
|
||||
// Only register service worker if explicitly enabled and in production
|
||||
if (process.env.VITE_PWA_ENABLED === 'true' && process.env.NODE_ENV === "production") {
|
||||
if (
|
||||
process.env.VITE_PWA_ENABLED === "true" &&
|
||||
process.env.NODE_ENV === "production"
|
||||
) {
|
||||
register(`${process.env.BASE_URL}sw.js`, {
|
||||
ready() {
|
||||
console.log("Service worker is active.");
|
||||
@@ -21,12 +24,16 @@ if (process.env.VITE_PWA_ENABLED === 'true' && process.env.NODE_ENV === "product
|
||||
console.log("New content is available; please refresh.");
|
||||
},
|
||||
offline() {
|
||||
console.log("No internet connection found. App is running in offline mode.");
|
||||
console.log(
|
||||
"No internet connection found. App is running in offline mode.",
|
||||
);
|
||||
},
|
||||
error(error) {
|
||||
console.error("Error during service worker registration:", error);
|
||||
}
|
||||
},
|
||||
});
|
||||
} else {
|
||||
console.log("Service worker registration skipped - not enabled or not in production");
|
||||
console.log(
|
||||
"Service worker registration skipped - not enabled or not in production",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ const routes: Array<RouteRecordRaw> = [
|
||||
|
||||
const isElectron = window.location.protocol === "file:";
|
||||
const initialPath = isElectron
|
||||
? window.location.pathname.split('/dist-electron/www/')[1] || '/'
|
||||
? window.location.pathname.split("/dist-electron/www/")[1] || "/"
|
||||
: window.location.pathname;
|
||||
|
||||
const history = isElectron
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as path from "path";
|
||||
import { promises as fs } from "fs";
|
||||
import { fileURLToPath } from 'url';
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
export async function loadAppConfig() {
|
||||
const packageJson = await loadPackageJson();
|
||||
@@ -34,15 +34,16 @@ export async function loadAppConfig() {
|
||||
sizes: "512x512",
|
||||
type: "image/png",
|
||||
purpose: "maskable",
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
aliasConfig: {
|
||||
"@": path.resolve(path.dirname(__dirname), "src"),
|
||||
buffer: path.resolve(path.dirname(__dirname), "node_modules", "buffer"),
|
||||
"dexie-export-import/dist/import": "dexie-export-import/dist/import/index.js",
|
||||
}
|
||||
"dexie-export-import/dist/import":
|
||||
"dexie-export-import/dist/import/index.js",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user