-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from hallipr/electron
Electron
- Loading branch information
Showing
31 changed files
with
9,945 additions
and
2,077 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json", | ||
"appId": "YourAppID", | ||
"asar": true, | ||
"productName": "YourAppName", | ||
"directories": { | ||
"output": "release/${version}" | ||
}, | ||
"files": [ | ||
"dist", | ||
"dist-electron" | ||
], | ||
"mac": { | ||
"target": [ | ||
"dmg" | ||
], | ||
"artifactName": "${productName}-Mac-${version}-Installer.${ext}" | ||
}, | ||
"win": { | ||
"target": [ | ||
{ | ||
"target": "nsis", | ||
"arch": [ | ||
"x64" | ||
] | ||
} | ||
], | ||
"artifactName": "${productName}-Windows-${version}-Setup.${ext}" | ||
}, | ||
"nsis": { | ||
"oneClick": false, | ||
"perMachine": false, | ||
"allowToChangeInstallationDirectory": true, | ||
"deleteAppDataOnUninstall": false | ||
}, | ||
"linux": { | ||
"target": [ | ||
"AppImage" | ||
], | ||
"artifactName": "${productName}-Linux-${version}.${ext}" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// <reference types="vite-plugin-electron/electron-env" /> | ||
|
||
declare namespace NodeJS { | ||
interface ProcessEnv { | ||
VSCODE_DEBUG?: 'true' | ||
/** | ||
* The built directory structure | ||
* | ||
* ```tree | ||
* ├─┬ dist-electron | ||
* │ ├─┬ main | ||
* │ │ └── index.js > Electron-Main | ||
* │ └─┬ preload | ||
* │ └── index.mjs > Preload-Scripts | ||
* ├─┬ dist | ||
* │ └── index.html > Electron-Renderer | ||
* ``` | ||
*/ | ||
APP_ROOT: string | ||
/** /dist/ or /public/ */ | ||
VITE_PUBLIC: string | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { app, BrowserWindow, shell, ipcMain } from 'electron' | ||
import { createRequire } from 'node:module' | ||
import { fileURLToPath } from 'node:url' | ||
import path from 'node:path' | ||
import os from 'node:os' | ||
|
||
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') | ||
export const RENDERER_DIST = path.join(process.env.APP_ROOT, 'dist') | ||
export const VITE_DEV_SERVER_URL = process.env.VITE_DEV_SERVER_URL | ||
|
||
process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL | ||
? path.join(process.env.APP_ROOT, 'public') | ||
: RENDERER_DIST | ||
|
||
// Disable GPU Acceleration for Windows 7 | ||
if (os.release().startsWith('6.1')) app.disableHardwareAcceleration() | ||
|
||
// Set application name for Windows 10+ notifications | ||
if (process.platform === 'win32') app.setAppUserModelId(app.getName()) | ||
|
||
if (!app.requestSingleInstanceLock()) { | ||
app.quit() | ||
process.exit(0) | ||
} | ||
|
||
let win: BrowserWindow | null = null | ||
const preload = path.join(__dirname, '../preload/index.mjs') | ||
const indexHtml = path.join(RENDERER_DIST, 'index.html') | ||
|
||
async function createWindow() { | ||
win = new BrowserWindow({ | ||
title: 'Main window', | ||
icon: path.join(process.env.VITE_PUBLIC, 'favicon.ico'), | ||
webPreferences: { | ||
preload, | ||
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production | ||
// nodeIntegration: true, | ||
|
||
// Consider using contextBridge.exposeInMainWorld | ||
// Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation | ||
// contextIsolation: false, | ||
}, | ||
}) | ||
|
||
if (VITE_DEV_SERVER_URL) { // #298 | ||
win.loadURL(VITE_DEV_SERVER_URL) | ||
// Open devTool if the app is not packaged | ||
win.webContents.openDevTools() | ||
} else { | ||
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 | ||
win.webContents.setWindowOpenHandler(({ url }) => { | ||
if (url.startsWith('https:')) shell.openExternal(url) | ||
return { action: 'deny' } | ||
}) | ||
// win.webContents.on('will-navigate', (event, url) => { }) #344 | ||
} | ||
|
||
app.whenReady().then(createWindow) | ||
|
||
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('activate', () => { | ||
const allWindows = BrowserWindow.getAllWindows() | ||
if (allWindows.length) { | ||
allWindows[0].focus() | ||
} else { | ||
createWindow() | ||
} | ||
}) | ||
|
||
// New window example arg: new windows url | ||
ipcMain.handle('open-win', (_, arg) => { | ||
const childWindow = new BrowserWindow({ | ||
webPreferences: { | ||
preload, | ||
nodeIntegration: true, | ||
contextIsolation: false, | ||
}, | ||
}) | ||
|
||
if (VITE_DEV_SERVER_URL) { | ||
childWindow.loadURL(`${VITE_DEV_SERVER_URL}#${arg}`) | ||
} else { | ||
childWindow.loadFile(indexHtml, { hash: arg }) | ||
} | ||
}) |
Oops, something went wrong.