From f32a6e55562785c4ac4eac2accbf4bccba42467e Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Wed, 26 Jun 2024 16:37:12 -0400 Subject: [PATCH 1/4] Update layout --- .vscode/settings.json | 5 +++-- bun.lockb | Bin 181476 -> 181476 bytes electron/main/index.ts | 36 ++++++++++++++++++------------------ src/App.tsx | 2 +- src/index.css | 6 ++++++ 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 1e3e2cde..badaac05 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,5 +9,6 @@ ], "url": "https://json.schemastore.org/electron-builder" } - ] -} + ], + "github.copilot.inlineSuggest.enable": true +} \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index f8eb17203b5ff5032c83bf6a44be8762887733ab..bb436aa37c2d419143b4580c06b7603b6ba48c93 100755 GIT binary patch delta 153 zcmaFT$^E30dxD-qWy<`npP%LA{M-2^gj-8#JYxQvx$t84(>~5s?19xEN;mplDrS_Q zte9@GIkIHSCI=tk4J-Bp9jmGOHSw3ksYh>RPukQrOnTTU`*o(bSE<~|-k)4w{jYsd z6iT1_BB=cD*%Z!(weRG&UwT}5?sLCVtIBp?bw;CuY{rIqhI$6uTVF8dY=LpU&tZD2 F4geoPNFM+I delta 153 zcmV;K0A~N>i3{Y33y>}#4#Ol^CVs^nKyNzzzvf>imj~0m4ua{buU_&+1u@wH~J9N z&$D9(A({Atf-8&MLZqx3-#y${Vbd%4w@oJjGQkEiIW93SF}H>20c^AeGC3|ZE;6_G HoC579t8+uQ diff --git a/electron/main/index.ts b/electron/main/index.ts index 54501a92..7dd17be1 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -45,7 +45,11 @@ const preload = path.join(__dirname, '../preload/index.mjs') const indexHtml = path.join(RENDERER_DIST, 'index.html') async function createWindow() { - const { width, height } = screen.getPrimaryDisplay().workAreaSize; + // Get the size of the primary display + const primaryDisplay = screen.getPrimaryDisplay(); + const { width, height } = primaryDisplay.workAreaSize; + + // Create a new browser window with dynamic sizing based on the screen win = new BrowserWindow({ title: APP_NAME, icon: path.join(process.env.VITE_PUBLIC, 'favicon.ico'), @@ -59,29 +63,25 @@ async function createWindow() { preload, webviewTag: true, }, - }) + }); + win.maximize(); - if (VITE_DEV_SERVER_URL) { // #298 - win.loadURL(VITE_DEV_SERVER_URL) - // Open devTool if the app is not packaged - win.webContents.openDevTools() + // Load URL or file based on the environment + if (VITE_DEV_SERVER_URL) { + win.loadURL(VITE_DEV_SERVER_URL); + win.webContents.openDevTools(); } else { - win.loadFile(indexHtml) + win.loadFile(indexHtml); } - // Test actively push message to the Electron-Renderer - win.webContents.on('did-finish-load', () => { - win?.webContents.send('main-process-message', new Date().toLocaleString()) - }) - - // Make all links open with the browser, not with the application + // Ensure links open externally win.webContents.setWindowOpenHandler(({ url }) => { - if (url.startsWith('https:')) shell.openExternal(url) - return { action: 'deny' } - }) + if (url.startsWith('https:')) shell.openExternal(url); + return { action: 'deny' }; + }); - // Auto update - update(win) + // Handle updates + update(win); } app.whenReady().then(createWindow) diff --git a/src/App.tsx b/src/App.tsx index 10c3a727..e71524df 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,7 +5,7 @@ import ProjectEditor from './routes/editor'; function App() { return ( -
+
diff --git a/src/index.css b/src/index.css index 1686c2b3..cfee2209 100644 --- a/src/index.css +++ b/src/index.css @@ -77,4 +77,10 @@ .appbar { -webkit-app-region: drag; +} + +body, #root { + height: 100%; + width: 100%; + overflow: hidden; } \ No newline at end of file From 11a3b9e7611a290ab3fe2414f2b67fdeee9bd7d1 Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Wed, 26 Jun 2024 16:38:20 -0400 Subject: [PATCH 2/4] Update ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c2c37f0a..f6032c7c 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ release # Editor directories and files .vscode/.debug.env +.vscode/settings.json .idea .DS_Store *.suo From f1888670eb2ba7263863df95278bbbdd7939fc9e Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Wed, 26 Jun 2024 16:51:20 -0400 Subject: [PATCH 3/4] Clean up --- .vscode/settings.json | 2 +- docs/CONTRIBUTING.md | 10 ++++ electron/main/index.ts | 103 ++++++++++++++++------------------------- 3 files changed, 51 insertions(+), 64 deletions(-) create mode 100644 docs/CONTRIBUTING.md diff --git a/.vscode/settings.json b/.vscode/settings.json index badaac05..34584f3c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,5 +10,5 @@ "url": "https://json.schemastore.org/electron-builder" } ], - "github.copilot.inlineSuggest.enable": true + "github.copilot.inlineSuggest.enable": false } \ No newline at end of file diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md new file mode 100644 index 00000000..ef1bfbb2 --- /dev/null +++ b/docs/CONTRIBUTING.md @@ -0,0 +1,10 @@ +The built directory structure +``` +├─┬ dist-electron +│ ├─┬ main +│ │ └── index.js > Electron-Main +│ └─┬ preload +│ └── index.mjs > Preload-Scripts +├─┬ dist +│ └── index.html > Electron-Renderer +``` \ No newline at end of file diff --git a/electron/main/index.ts b/electron/main/index.ts index 7dd17be1..63b638af 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -1,24 +1,13 @@ -import { BrowserWindow, app, ipcMain, screen, shell } from 'electron' +import { BrowserWindow, app, screen, shell } from 'electron' import { createRequire } from 'node:module' import os from 'node:os' import path from 'node:path' import { fileURLToPath } from 'node:url' import { APP_NAME } from '../../src/lib/constants' -import { update } from './update' const require = createRequire(import.meta.url) const __dirname = path.dirname(fileURLToPath(import.meta.url)) -// The built directory structure -// -// ├─┬ dist-electron -// │ ├─┬ main -// │ │ └── index.js > Electron-Main -// │ └─┬ preload -// │ └── index.mjs > Preload-Scripts -// ├─┬ dist -// │ └── index.html > Electron-Renderer -// process.env.APP_ROOT = path.join(__dirname, '../..') export const MAIN_DIST = path.join(process.env.APP_ROOT, 'dist-electron') @@ -44,12 +33,19 @@ let win: BrowserWindow | null = null const preload = path.join(__dirname, '../preload/index.mjs') const indexHtml = path.join(RENDERER_DIST, 'index.html') -async function createWindow() { - // Get the size of the primary display - const primaryDisplay = screen.getPrimaryDisplay(); - const { width, height } = primaryDisplay.workAreaSize; - // Create a new browser window with dynamic sizing based on the screen +function loadWindowContent(win: BrowserWindow) { + // Load URL or file based on the environment + if (VITE_DEV_SERVER_URL) { + win.loadURL(VITE_DEV_SERVER_URL); + win.webContents.openDevTools(); + } else { + win.loadFile(indexHtml); + } +} + +function createWindow() { + const { width, height } = screen.getPrimaryDisplay().workAreaSize; win = new BrowserWindow({ title: APP_NAME, icon: path.join(process.env.VITE_PUBLIC, 'favicon.ico'), @@ -64,63 +60,44 @@ async function createWindow() { webviewTag: true, }, }); - win.maximize(); + return win; +} - // Load URL or file based on the environment - if (VITE_DEV_SERVER_URL) { - win.loadURL(VITE_DEV_SERVER_URL); - win.webContents.openDevTools(); - } else { - win.loadFile(indexHtml); - } +function initMainWindow() { + const win = createWindow(); + loadWindowContent(win); // Ensure links open externally win.webContents.setWindowOpenHandler(({ url }) => { if (url.startsWith('https:')) shell.openExternal(url); return { action: 'deny' }; }); - - // Handle updates - update(win); } -app.whenReady().then(createWindow) +function setListeners() { + app.whenReady().then(initMainWindow) -app.on('window-all-closed', () => { - win = null - if (process.platform !== 'darwin') app.quit() -}) - -app.on('second-instance', () => { - if (win) { - // Focus on the main window if the user tried to open another - if (win.isMinimized()) win.restore() - win.focus() - } -}) + app.on('window-all-closed', () => { + win = null + if (process.platform !== 'darwin') app.quit() + }) -app.on('activate', () => { - const allWindows = BrowserWindow.getAllWindows() - if (allWindows.length) { - allWindows[0].focus() - } else { - createWindow() - } -}) + app.on('second-instance', () => { + if (win) { + // Focus on the main window if the user tried to open another + if (win.isMinimized()) win.restore() + win.focus() + } + }) -// New window example arg: new windows url -ipcMain.handle('open-win', (_, arg) => { - const childWindow = new BrowserWindow({ - webPreferences: { - preload, - nodeIntegration: true, - contextIsolation: false, - }, + app.on('activate', () => { + const allWindows = BrowserWindow.getAllWindows() + if (allWindows.length) { + allWindows[0].focus() + } else { + initMainWindow() + } }) +} - if (VITE_DEV_SERVER_URL) { - childWindow.loadURL(`${VITE_DEV_SERVER_URL}#${arg}`) - } else { - childWindow.loadFile(indexHtml, { hash: arg }) - } -}) +setListeners() \ No newline at end of file From 5b20ba7b5ecb5435b6bf6ff5754c0f53a45e6ef6 Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Wed, 26 Jun 2024 16:52:06 -0400 Subject: [PATCH 4/4] Clean up --- .vscode/settings.json | 2 +- electron/preload/index.ts | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 34584f3c..badaac05 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,5 +10,5 @@ "url": "https://json.schemastore.org/electron-builder" } ], - "github.copilot.inlineSuggest.enable": false + "github.copilot.inlineSuggest.enable": true } \ No newline at end of file diff --git a/electron/preload/index.ts b/electron/preload/index.ts index c74414b7..5d1f5fca 100644 --- a/electron/preload/index.ts +++ b/electron/preload/index.ts @@ -51,8 +51,6 @@ const api = { }, }; -// Expose methods to renderer process contextBridge.exposeInMainWorld('Main', api); - // WARN: Using the ipcRenderer directly in the browser through the contextBridge is insecure contextBridge.exposeInMainWorld('ipcRenderer', ipcRenderer);