Compare commits

..

No commits in common. "7d5708d600203f3c566539ffe1f823f54ed1c8dc" and "a085952032a36ddf03c7c46c4f6074d7f18bfee1" have entirely different histories.

4 changed files with 30 additions and 37 deletions

View File

@ -1,4 +1,6 @@
// @see https://www.electron.build/configuration/configuration /**
* @see https://www.electron.build/configuration/configuration
*/
{ {
"$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json", "$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json",
"appId": "YourAppID", "appId": "YourAppID",

View File

@ -3,20 +3,8 @@
declare namespace NodeJS { declare namespace NodeJS {
interface ProcessEnv { interface ProcessEnv {
VSCODE_DEBUG?: 'true' VSCODE_DEBUG?: 'true'
/** DIST_ELECTRON: string
* The built directory structure DIST: string
*
* ```tree
* dist-electron
* main
* index.js > Electron-Main
* preload
* index.mjs > Preload-Scripts
* dist
* index.html > Electron-Renderer
* ```
*/
APP_ROOT: string
/** /dist/ or /public/ */ /** /dist/ or /public/ */
VITE_PUBLIC: string VITE_PUBLIC: string
} }

View File

@ -1,10 +1,10 @@
import { app, BrowserWindow, shell, ipcMain } from 'electron' import { app, BrowserWindow, shell, ipcMain } from 'electron'
import { release } from 'node:os'
import { join, dirname } from 'node:path'
import { fileURLToPath } from 'node:url' import { fileURLToPath } from 'node:url'
import path from 'node:path'
import os from 'node:os'
globalThis.__filename = fileURLToPath(import.meta.url) globalThis.__filename = fileURLToPath(import.meta.url)
globalThis.__dirname = path.dirname(__filename) globalThis.__dirname = dirname(__filename)
// The built directory structure // The built directory structure
// //
@ -16,18 +16,14 @@ globalThis.__dirname = path.dirname(__filename)
// ├─┬ dist // ├─┬ dist
// │ └── index.html > Electron-Renderer // │ └── index.html > Electron-Renderer
// //
process.env.APP_ROOT = path.join(__dirname, '../..') process.env.DIST_ELECTRON = join(__dirname, '..')
process.env.DIST = join(process.env.DIST_ELECTRON, '../dist')
export const MAIN_DIST = path.join(process.env.APP_ROOT, 'dist-electron') process.env.VITE_PUBLIC = process.env.VITE_DEV_SERVER_URL
export const RENDERER_DIST = path.join(process.env.APP_ROOT, 'dist') ? join(process.env.DIST_ELECTRON, '../public')
export const VITE_DEV_SERVER_URL = process.env.VITE_DEV_SERVER_URL : process.env.DIST
process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL
? path.join(process.env.APP_ROOT, 'public')
: RENDERER_DIST
// Disable GPU Acceleration for Windows 7 // Disable GPU Acceleration for Windows 7
if (os.release().startsWith('6.1')) app.disableHardwareAcceleration() if (release().startsWith('6.1')) app.disableHardwareAcceleration()
// Set application name for Windows 10+ notifications // Set application name for Windows 10+ notifications
if (process.platform === 'win32') app.setAppUserModelId(app.getName()) if (process.platform === 'win32') app.setAppUserModelId(app.getName())
@ -37,14 +33,21 @@ if (!app.requestSingleInstanceLock()) {
process.exit(0) process.exit(0)
} }
// Remove electron security warnings
// This warning only shows in development mode
// Read more on https://www.electronjs.org/docs/latest/tutorial/security
// process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
let win: BrowserWindow | null = null let win: BrowserWindow | null = null
const preload = path.join(__dirname, '../preload/index.mjs') // Here, you can also use other preload
const indexHtml = path.join(RENDERER_DIST, 'index.html') const preload = join(__dirname, '../preload/index.mjs')
const url = process.env.VITE_DEV_SERVER_URL
const indexHtml = join(process.env.DIST, 'index.html')
async function createWindow() { async function createWindow() {
win = new BrowserWindow({ win = new BrowserWindow({
title: 'Main window', title: 'Main window',
icon: path.join(process.env.VITE_PUBLIC, 'favicon.ico'), icon: join(process.env.VITE_PUBLIC, 'favicon.ico'),
webPreferences: { webPreferences: {
preload, preload,
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production // Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
@ -56,8 +59,8 @@ async function createWindow() {
}, },
}) })
if (VITE_DEV_SERVER_URL) { // #298 if (process.env.VITE_DEV_SERVER_URL) { // electron-vite-vue#298
win.loadURL(VITE_DEV_SERVER_URL) win.loadURL(url)
// Open devTool if the app is not packaged // Open devTool if the app is not packaged
win.webContents.openDevTools() win.webContents.openDevTools()
} else { } else {
@ -111,8 +114,8 @@ ipcMain.handle('open-win', (_, arg) => {
}, },
}) })
if (VITE_DEV_SERVER_URL) { if (process.env.VITE_DEV_SERVER_URL) {
childWindow.loadURL(`${VITE_DEV_SERVER_URL}#${arg}`) childWindow.loadURL(`${url}#${arg}`)
} else { } else {
childWindow.loadFile(indexHtml, { hash: arg }) childWindow.loadFile(indexHtml, { hash: arg })
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "electron-vue-vite", "name": "electron-vue-vite",
"version": "28.1.0", "version": "28.0.0",
"main": "dist-electron/main/index.js", "main": "dist-electron/main/index.js",
"description": "Really simple Electron + Vue + Vite boilerplate.", "description": "Really simple Electron + Vue + Vite boilerplate.",
"author": "草鞋没号 <308487730@qq.com>", "author": "草鞋没号 <308487730@qq.com>",