diff --git a/concord-client/.gitignore b/concord-client/.gitignore index 4108b33..27ad0b7 100644 --- a/concord-client/.gitignore +++ b/concord-client/.gitignore @@ -11,6 +11,7 @@ node_modules dist dist-ssr *.local +release/ # Editor directories and files .vscode/* diff --git a/concord-client/dist-electron/main.js b/concord-client/dist-electron/main.js index 6e55b39..597fef6 100644 --- a/concord-client/dist-electron/main.js +++ b/concord-client/dist-electron/main.js @@ -1,45 +1,30 @@ -import { app, BrowserWindow } from "electron"; -import { createRequire } from "node:module"; -import { fileURLToPath } from "node:url"; -import path from "node:path"; -createRequire(import.meta.url); -const __dirname = path.dirname(fileURLToPath(import.meta.url)); -process.env.APP_ROOT = path.join(__dirname, ".."); -const VITE_DEV_SERVER_URL = process.env["VITE_DEV_SERVER_URL"]; -const MAIN_DIST = path.join(process.env.APP_ROOT, "dist-electron"); -const RENDERER_DIST = path.join(process.env.APP_ROOT, "dist"); -process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL ? path.join(process.env.APP_ROOT, "public") : RENDERER_DIST; -let win; -function createWindow() { - win = new BrowserWindow({ - icon: path.join(process.env.VITE_PUBLIC, "electron-vite.svg"), +import { app as n, BrowserWindow as i } from "electron"; +import { fileURLToPath as c } from "node:url"; +import o from "node:path"; +const t = o.dirname(c(import.meta.url)); +process.env.APP_ROOT = o.join(t, ".."); +const s = process.env.VITE_DEV_SERVER_URL, R = o.join(process.env.APP_ROOT, "dist-electron"), r = o.join(process.env.APP_ROOT, "dist"); +process.env.VITE_PUBLIC = s ? o.join(process.env.APP_ROOT, "public") : r; +let e; +function l() { + e = new i({ + icon: o.join(process.env.VITE_PUBLIC, "electron-vite.svg"), webPreferences: { - preload: path.join(__dirname, "preload.mjs") + preload: o.join(t, "preload.mjs") } - }); - win.webContents.on("did-finish-load", () => { - win == null ? void 0 : win.webContents.send("main-process-message", (/* @__PURE__ */ new Date()).toLocaleString()); - }); - if (VITE_DEV_SERVER_URL) { - win.loadURL(VITE_DEV_SERVER_URL); - } else { - win.loadFile(path.join(RENDERER_DIST, "index.html")); - } + }), e.webContents.on("did-finish-load", () => { + e == null || e.webContents.send("main-process-message", (/* @__PURE__ */ new Date()).toLocaleString()); + }), s ? e.loadURL(s) : e.loadFile(o.join(r, "index.html")); } -app.on("window-all-closed", () => { - if (process.platform !== "darwin") { - app.quit(); - win = null; - } +n.on("window-all-closed", () => { + process.platform !== "darwin" && (n.quit(), e = null); }); -app.on("activate", () => { - if (BrowserWindow.getAllWindows().length === 0) { - createWindow(); - } +n.on("activate", () => { + i.getAllWindows().length === 0 && l(); }); -app.whenReady().then(createWindow); +n.whenReady().then(l); export { - MAIN_DIST, - RENDERER_DIST, - VITE_DEV_SERVER_URL + R as MAIN_DIST, + r as RENDERER_DIST, + s as VITE_DEV_SERVER_URL }; diff --git a/concord-client/dist-electron/preload.mjs b/concord-client/dist-electron/preload.mjs index d421640..d0e1e80 100644 --- a/concord-client/dist-electron/preload.mjs +++ b/concord-client/dist-electron/preload.mjs @@ -1,22 +1 @@ -"use strict"; -const electron = require("electron"); -electron.contextBridge.exposeInMainWorld("ipcRenderer", { - on(...args) { - const [channel, listener] = args; - return electron.ipcRenderer.on(channel, (event, ...args2) => listener(event, ...args2)); - }, - off(...args) { - const [channel, ...omit] = args; - return electron.ipcRenderer.off(channel, ...omit); - }, - send(...args) { - const [channel, ...omit] = args; - return electron.ipcRenderer.send(channel, ...omit); - }, - invoke(...args) { - const [channel, ...omit] = args; - return electron.ipcRenderer.invoke(channel, ...omit); - } - // You can expose other APTs you need here. - // ... -}); +"use strict";const o=require("electron");o.contextBridge.exposeInMainWorld("ipcRenderer",{on(...e){const[n,r]=e;return o.ipcRenderer.on(n,(t,...c)=>r(t,...c))},off(...e){const[n,...r]=e;return o.ipcRenderer.off(n,...r)},send(...e){const[n,...r]=e;return o.ipcRenderer.send(n,...r)},invoke(...e){const[n,...r]=e;return o.ipcRenderer.invoke(n,...r)}}); diff --git a/concord-client/electron/main.ts b/concord-client/electron/main.ts index be9bbf4..dd45b52 100644 --- a/concord-client/electron/main.ts +++ b/concord-client/electron/main.ts @@ -1,68 +1,70 @@ -import { app, BrowserWindow } from 'electron' -import { createRequire } from 'node:module' -import { fileURLToPath } from 'node:url' -import path from 'node:path' - -const require = createRequire(import.meta.url) -const __dirname = path.dirname(fileURLToPath(import.meta.url)) - -// The built directory structure -// -// ├─┬─┬ dist -// │ │ └── index.html -// │ │ -// │ ├─┬ dist-electron -// │ │ ├── main.js -// │ │ └── preload.mjs -// │ -process.env.APP_ROOT = path.join(__dirname, '..') - -// 🚧 Use ['ENV_NAME'] avoid vite:define plugin - Vite@2.x -export const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL'] -export const MAIN_DIST = path.join(process.env.APP_ROOT, 'dist-electron') -export const RENDERER_DIST = path.join(process.env.APP_ROOT, 'dist') - -process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL ? path.join(process.env.APP_ROOT, 'public') : RENDERER_DIST - -let win: BrowserWindow | null - -function createWindow() { - win = new BrowserWindow({ - icon: path.join(process.env.VITE_PUBLIC, 'electron-vite.svg'), - webPreferences: { - preload: path.join(__dirname, 'preload.mjs'), - }, - }) - - // Test active push message to Renderer-process. - win.webContents.on('did-finish-load', () => { - win?.webContents.send('main-process-message', (new Date).toLocaleString()) - }) - - if (VITE_DEV_SERVER_URL) { - win.loadURL(VITE_DEV_SERVER_URL) - } else { - // win.loadFile('dist/index.html') - win.loadFile(path.join(RENDERER_DIST, 'index.html')) - } -} - -// Quit when all windows are closed, except on macOS. There, it's common -// for applications and their menu bar to stay active until the user quits -// explicitly with Cmd + Q. -app.on('window-all-closed', () => { - if (process.platform !== 'darwin') { - app.quit() - win = null - } -}) - -app.on('activate', () => { - // On OS X it's common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (BrowserWindow.getAllWindows().length === 0) { - createWindow() - } -}) - -app.whenReady().then(createWindow) +import { app, BrowserWindow } from "electron"; +// import { createRequire } from 'node:module' +import { fileURLToPath } from "node:url"; +import path from "node:path"; + +// const require = createRequire(import.meta.url) +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +// The built directory structure +// +// ├─┬─┬ dist +// │ │ └── index.html +// │ │ +// │ ├─┬ dist-electron +// │ │ ├── main.js +// │ │ └── preload.mjs +// │ +process.env.APP_ROOT = path.join(__dirname, ".."); + +// 🚧 Use ['ENV_NAME'] avoid vite:define plugin - Vite@2.x +export const VITE_DEV_SERVER_URL = process.env["VITE_DEV_SERVER_URL"]; +export const MAIN_DIST = path.join(process.env.APP_ROOT, "dist-electron"); +export const RENDERER_DIST = path.join(process.env.APP_ROOT, "dist"); + +process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL + ? path.join(process.env.APP_ROOT, "public") + : RENDERER_DIST; + +let win: BrowserWindow | null; + +function createWindow() { + win = new BrowserWindow({ + icon: path.join(process.env.VITE_PUBLIC, "electron-vite.svg"), + webPreferences: { + preload: path.join(__dirname, "preload.mjs"), + }, + }); + + // Test active push message to Renderer-process. + win.webContents.on("did-finish-load", () => { + win?.webContents.send("main-process-message", new Date().toLocaleString()); + }); + + if (VITE_DEV_SERVER_URL) { + win.loadURL(VITE_DEV_SERVER_URL); + } else { + // win.loadFile('dist/index.html') + win.loadFile(path.join(RENDERER_DIST, "index.html")); + } +} + +// Quit when all windows are closed, except on macOS. There, it's common +// for applications and their menu bar to stay active until the user quits +// explicitly with Cmd + Q. +app.on("window-all-closed", () => { + if (process.platform !== "darwin") { + app.quit(); + win = null; + } +}); + +app.on("activate", () => { + // On OS X it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (BrowserWindow.getAllWindows().length === 0) { + createWindow(); + } +}); + +app.whenReady().then(createWindow); diff --git a/concord-client/package.json b/concord-client/package.json index 68a0b9c..2d3d2d0 100644 --- a/concord-client/package.json +++ b/concord-client/package.json @@ -4,10 +4,10 @@ "version": "0.0.0", "type": "module", "scripts": { - "dev": "vite", - "build": "tsc && vite build && electron-builder", + "dev": "bunx --bun vite --open", + "build": "tsc && bunx --bun vite build && electron-builder", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", - "preview": "vite preview" + "preview": "bunx --bun vite preview" }, "dependencies": { "react": "^18.2.0",