Browse Source

commit working index.html

Matthew Raymer 1 week ago
parent
commit
47a28ff7ad
  1. 3
      .gitignore
  2. 171
      package-lock.json
  3. 15
      package.json
  4. 28
      scripts/build-electron.js
  5. 85
      src/electron/main.js
  6. 10
      vite.config.mjs

3
.gitignore

@ -1,3 +1,6 @@
squashfs-root
dist-electron
dist-electon-build
.DS_Store .DS_Store
node_modules node_modules
/dist /dist

171
package-lock.json

@ -97,6 +97,7 @@
"eslint-config-prettier": "^9.1.0", "eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1", "eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-vue": "^9.32.0", "eslint-plugin-vue": "^9.32.0",
"fs-extra": "^11.3.0",
"npm-check-updates": "^17.1.13", "npm-check-updates": "^17.1.13",
"postcss": "^8.4.38", "postcss": "^8.4.38",
"prettier": "^3.2.5", "prettier": "^3.2.5",
@ -3755,6 +3756,22 @@
"node": ">= 10.0.0" "node": ">= 10.0.0"
} }
}, },
"node_modules/@electron/notarize/node_modules/fs-extra": {
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
"integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"at-least-node": "^1.0.0",
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@electron/osx-sign": { "node_modules/@electron/osx-sign": {
"version": "1.3.1", "version": "1.3.1",
"resolved": "https://registry.npmjs.org/@electron/osx-sign/-/osx-sign-1.3.1.tgz", "resolved": "https://registry.npmjs.org/@electron/osx-sign/-/osx-sign-1.3.1.tgz",
@ -3868,21 +3885,6 @@
"node": ">=16.4" "node": ">=16.4"
} }
}, },
"node_modules/@electron/universal/node_modules/fs-extra": {
"version": "11.3.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.0.tgz",
"integrity": "sha512-Z4XaCL6dUDHfP/jT25jJKMmtxvuwbkrD1vNSMFlo9lNLY2c5FHYSQgHPRZUjAB26TpDEoW9HCOgplrdbaPV/ew==",
"dev": true,
"license": "MIT",
"dependencies": {
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=14.14"
}
},
"node_modules/@esbuild/aix-ppc64": { "node_modules/@esbuild/aix-ppc64": {
"version": "0.21.5", "version": "0.21.5",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz",
@ -5780,6 +5782,23 @@
"resolve-from": "^5.0.0" "resolve-from": "^5.0.0"
} }
}, },
"node_modules/@expo/metro-config/node_modules/fs-extra": {
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
"integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==",
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"at-least-node": "^1.0.0",
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@expo/metro-config/node_modules/glob": { "node_modules/@expo/metro-config/node_modules/glob": {
"version": "10.4.5", "version": "10.4.5",
"resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz", "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz",
@ -6224,6 +6243,23 @@
"xml2js": "0.6.0" "xml2js": "0.6.0"
} }
}, },
"node_modules/@expo/prebuild-config/node_modules/fs-extra": {
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
"integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==",
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"at-least-node": "^1.0.0",
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@expo/prebuild-config/node_modules/resolve-from": { "node_modules/@expo/prebuild-config/node_modules/resolve-from": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz",
@ -6523,6 +6559,21 @@
"node": ">=16.0.0" "node": ">=16.0.0"
} }
}, },
"node_modules/@ionic/utils-fs/node_modules/fs-extra": {
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
"integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==",
"license": "MIT",
"dependencies": {
"at-least-node": "^1.0.0",
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@ionic/utils-object": { "node_modules/@ionic/utils-object": {
"version": "2.1.5", "version": "2.1.5",
"resolved": "https://registry.npmjs.org/@ionic/utils-object/-/utils-object-2.1.5.tgz", "resolved": "https://registry.npmjs.org/@ionic/utils-object/-/utils-object-2.1.5.tgz",
@ -6640,6 +6691,21 @@
"node": ">=10.3.0" "node": ">=10.3.0"
} }
}, },
"node_modules/@ionic/utils-subprocess/node_modules/fs-extra": {
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
"integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==",
"license": "MIT",
"dependencies": {
"at-least-node": "^1.0.0",
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@ionic/utils-terminal": { "node_modules/@ionic/utils-terminal": {
"version": "2.3.5", "version": "2.3.5",
"resolved": "https://registry.npmjs.org/@ionic/utils-terminal/-/utils-terminal-2.3.5.tgz", "resolved": "https://registry.npmjs.org/@ionic/utils-terminal/-/utils-terminal-2.3.5.tgz",
@ -7154,6 +7220,22 @@
"node": ">= 10.0.0" "node": ">= 10.0.0"
} }
}, },
"node_modules/@malept/flatpak-bundler/node_modules/fs-extra": {
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
"integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"at-least-node": "^1.0.0",
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@multiformats/base-x": { "node_modules/@multiformats/base-x": {
"version": "4.0.1", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/@multiformats/base-x/-/base-x-4.0.1.tgz", "resolved": "https://registry.npmjs.org/@multiformats/base-x/-/base-x-4.0.1.tgz",
@ -15374,6 +15456,22 @@
"node": ">= 10" "node": ">= 10"
} }
}, },
"node_modules/expo-modules-autolinking/node_modules/fs-extra": {
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
"integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==",
"license": "MIT",
"optional": true,
"dependencies": {
"at-least-node": "^1.0.0",
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/expo-modules-core": { "node_modules/expo-modules-core": {
"version": "0.4.10", "version": "0.4.10",
"resolved": "https://registry.npmjs.org/expo-modules-core/-/expo-modules-core-0.4.10.tgz", "resolved": "https://registry.npmjs.org/expo-modules-core/-/expo-modules-core-0.4.10.tgz",
@ -15442,6 +15540,23 @@
"invariant": "^2.2.4" "invariant": "^2.2.4"
} }
}, },
"node_modules/expo/node_modules/fs-extra": {
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
"integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==",
"license": "MIT",
"optional": true,
"peer": true,
"dependencies": {
"at-least-node": "^1.0.0",
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/expo/node_modules/resolve-from": { "node_modules/expo/node_modules/resolve-from": {
"version": "5.0.0", "version": "5.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz",
@ -16031,18 +16146,18 @@
"peer": true "peer": true
}, },
"node_modules/fs-extra": { "node_modules/fs-extra": {
"version": "9.1.0", "version": "11.3.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.0.tgz",
"integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", "integrity": "sha512-Z4XaCL6dUDHfP/jT25jJKMmtxvuwbkrD1vNSMFlo9lNLY2c5FHYSQgHPRZUjAB26TpDEoW9HCOgplrdbaPV/ew==",
"dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"at-least-node": "^1.0.0",
"graceful-fs": "^4.2.0", "graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1", "jsonfile": "^6.0.1",
"universalify": "^2.0.0" "universalify": "^2.0.0"
}, },
"engines": { "engines": {
"node": ">=10" "node": ">=14.14"
} }
}, },
"node_modules/fs-minipass": { "node_modules/fs-minipass": {
@ -26813,6 +26928,22 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/workbox-build/node_modules/fs-extra": {
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
"integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"at-least-node": "^1.0.0",
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/workbox-build/node_modules/is-stream": { "node_modules/workbox-build/node_modules/is-stream": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz",

15
package.json

@ -112,6 +112,7 @@
"eslint-config-prettier": "^9.1.0", "eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1", "eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-vue": "^9.32.0", "eslint-plugin-vue": "^9.32.0",
"fs-extra": "^11.3.0",
"npm-check-updates": "^17.1.13", "npm-check-updates": "^17.1.13",
"postcss": "^8.4.38", "postcss": "^8.4.38",
"prettier": "^3.2.5", "prettier": "^3.2.5",
@ -121,7 +122,7 @@
"vite": "^5.2.0", "vite": "^5.2.0",
"vite-plugin-pwa": "^0.19.8" "vite-plugin-pwa": "^0.19.8"
}, },
"main": "main.js", "main": "./dist-electron/main.js",
"build": { "build": {
"appId": "app.timesafari.app", "appId": "app.timesafari.app",
"productName": "TimeSafari", "productName": "TimeSafari",
@ -129,14 +130,18 @@
"output": "dist-electron-build" "output": "dist-electron-build"
}, },
"files": [ "files": [
"dist-electron/**/*"
],
"extraResources": [
{ {
"from": "dist-electron", "from": "dist-electron/www",
"to": ".", "to": "www"
"filter": ["**/*"]
} }
], ],
"linux": { "linux": {
"target": ["AppImage"], "target": [
"AppImage"
],
"category": "Utility", "category": "Utility",
"icon": "build/icons" "icon": "build/icons"
}, },

28
scripts/build-electron.js

@ -22,13 +22,27 @@ async function main() {
// Copy web files to www directory // Copy web files to www directory
const wwwDir = path.join(distElectronDir, 'www'); const wwwDir = path.join(distElectronDir, 'www');
await fs.copy(webDist, wwwDir); await fs.copy(webDist, wwwDir);
console.log('Copied web files to:', wwwDir);
// Copy and process main.js // Fix paths in index.html
const mainJsSrc = path.resolve(__dirname, '../src/electron/main.js'); const indexPath = path.join(wwwDir, 'index.html');
const mainJsDest = path.join(distElectronDir, 'main.js'); let indexContent = await fs.readFile(indexPath, 'utf8');
await fs.copy(mainJsSrc, mainJsDest); indexContent = indexContent.replace(/src="\//g, 'src="./');
console.log('Copied main.js to:', mainJsDest); indexContent = indexContent.replace(/href="\//g, 'href="./');
indexContent = indexContent.replace(/\/assets\//g, './assets/'); // Fix asset paths with explicit relative path
indexContent = indexContent.replace(/\.\/\.\/assets\//g, './assets/'); // Clean up any double dots
await fs.writeFile(indexPath, indexContent);
console.log('Copied and fixed web files in:', wwwDir);
// Copy main process files
const mainProcessFiles = [
'src/electron/main.js',
];
for (const file of mainProcessFiles) {
const destPath = path.join(distElectronDir, path.basename(file));
await fs.copy(file, destPath);
}
// Create the production package.json // Create the production package.json
const devPackageJson = require('../package.json'); const devPackageJson = require('../package.json');
@ -38,7 +52,7 @@ async function main() {
description: devPackageJson.description, description: devPackageJson.description,
author: devPackageJson.author, author: devPackageJson.author,
main: 'main.js', main: 'main.js',
private: true private: true,
}; };
await fs.writeJson( await fs.writeJson(

85
src/electron/main.js

@ -1,5 +1,6 @@
const { app, BrowserWindow } = require("electron"); const { app, BrowserWindow } = require("electron");
const path = require("path"); const path = require("path");
const fs = require("fs");
function createWindow() { function createWindow() {
// Create the browser window. // Create the browser window.
@ -9,29 +10,82 @@ function createWindow() {
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
contextIsolation: false, contextIsolation: false,
webSecurity: true,
allowRunningInsecureContent: false,
}, },
}); });
// Log the paths we're trying to load from // Disable service worker in Electron
const appPath = app.getAppPath(); mainWindow.webContents.session.setPermissionRequestHandler(
const indexPath = path.join(appPath, "www", "index.html"); (webContents, permission, callback) => {
if (permission === "serviceWorker") {
return callback(false);
}
callback(true);
},
);
// Get the correct app path for packaged and development environments
const appPath = app.isPackaged ? process.resourcesPath : app.getAppPath();
// Add debug logging for paths
console.log("Debug Info:");
console.log("App is packaged:", app.isPackaged);
console.log("Process resource path:", process.resourcesPath);
console.log("App path:", appPath); console.log("App path:", appPath);
console.log("Trying to load from:", indexPath); console.log("__dirname:", __dirname);
console.log("process.cwd():", process.cwd());
// Load the index.html file console.log("www path:", path.join(process.resourcesPath, "www"));
mainWindow.loadFile(indexPath).catch((err) => { console.log(
console.error("Failed to load index.html:", err); "www assets path:",
// Try to list directory contents to debug path.join(process.resourcesPath, "www", "assets"),
const fs = require("fs"); );
console.log("Directory contents:", fs.readdirSync(appPath));
}); // Try both possible www locations
const possiblePaths = [
path.join(appPath, "www", "index.html"),
path.join(appPath, "..", "www", "index.html"),
path.join(process.resourcesPath, "www", "index.html"),
];
// Open the DevTools in development let indexPath;
if (process.env.NODE_ENV === "development") { for (const testPath of possiblePaths) {
mainWindow.webContents.openDevTools(); console.log("Testing path:", testPath);
if (fs.existsSync(testPath)) {
indexPath = testPath;
console.log("Found valid path:", indexPath);
break;
}
} }
// Load the index.html
mainWindow
.loadFile(indexPath)
.then(() => {
console.log("Successfully loaded index.html");
// Always open DevTools in packaged app for debugging
mainWindow.webContents.openDevTools();
})
.catch((err) => {
console.error("Failed to load index.html:", err);
console.error("Attempted path:", indexPath);
});
// Listen for page errors
mainWindow.webContents.on(
"did-fail-load",
(event, errorCode, errorDescription) => {
console.error("Page failed to load:", errorCode, errorDescription);
},
);
// Listen for console messages from the renderer
mainWindow.webContents.on("console-message", (_event, level, message) => {
console.log("Renderer Console:", message);
});
} }
// Handle app ready
app.whenReady().then(() => { app.whenReady().then(() => {
createWindow(); createWindow();
@ -42,6 +96,7 @@ app.whenReady().then(() => {
}); });
}); });
// Handle all windows closed
app.on("window-all-closed", () => { app.on("window-all-closed", () => {
if (process.platform !== "darwin") { if (process.platform !== "darwin") {
app.quit(); app.quit();

10
vite.config.mjs

@ -17,7 +17,7 @@ export default defineConfig(({ mode }) => {
// Set output directory based on build mode // Set output directory based on build mode
const outDir = isElectron const outDir = isElectron
? "dist-electron" ? "dist-electron/www"
: isCapacitor : isCapacitor
? "dist-capacitor" ? "dist-capacitor"
: "dist"; : "dist";
@ -32,13 +32,14 @@ export default defineConfig(({ mode }) => {
rollupOptions: { rollupOptions: {
...(isElectron && { ...(isElectron && {
input: { input: {
main: path.resolve(__dirname, 'src/electron/main.js'),
index: path.resolve(__dirname, 'index.html') index: path.resolve(__dirname, 'index.html')
}, },
output: { output: {
dir: outDir, dir: outDir,
format: 'cjs', format: 'cjs',
entryFileNames: '[name].js' entryFileNames: 'assets/[name].[hash].js',
chunkFileNames: 'assets/[name].[hash].js',
assetFileNames: 'assets/[name].[hash][extname]'
} }
}) })
} }
@ -46,10 +47,11 @@ export default defineConfig(({ mode }) => {
plugins: [ plugins: [
vue(), vue(),
...(isElectron ...(isElectron
? [] // Skip PWA for Electron builds ? []
: [ : [
VitePWA({ VitePWA({
...appConfig.pwaConfig, ...appConfig.pwaConfig,
disable: isElectron
}), }),
]), ]),
], ],

Loading…
Cancel
Save