mirror of
https://github.com/electron-vite/electron-vite-vue
synced 2025-02-26 04:40:10 +08:00
Merge branch 'main' into dev
This commit is contained in:
commit
899d20c70c
@ -11,7 +11,7 @@
|
|||||||
## Features
|
## Features
|
||||||
|
|
||||||
📦 Out of the box
|
📦 Out of the box
|
||||||
🎯 Based on [vue-ts](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-vue-ts) template, less invasive
|
🎯 Based on the official [vue-ts](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-vue-ts) template, less invasive
|
||||||
🌱 Extensible, really simple directory structure
|
🌱 Extensible, really simple directory structure
|
||||||
💪 Support using Node.js API in Electron-Renderer
|
💪 Support using Node.js API in Electron-Renderer
|
||||||
🔩 Support C/C++ native addons
|
🔩 Support C/C++ native addons
|
||||||
|
@ -12,8 +12,16 @@ if (!app.requestSingleInstanceLock()) {
|
|||||||
app.quit()
|
app.quit()
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
|
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'
|
||||||
|
|
||||||
|
export const ROOT_PATH = {
|
||||||
|
// /dist
|
||||||
|
dist: join(__dirname, '../..'),
|
||||||
|
// /dist or /public
|
||||||
|
public: join(__dirname, app.isPackaged ? '../..' : '../../../public'),
|
||||||
|
}
|
||||||
|
|
||||||
let win: BrowserWindow | null = null
|
let win: BrowserWindow | null = null
|
||||||
// Here, you can also use other preload
|
// Here, you can also use other preload
|
||||||
const preload = join(__dirname, '../preload/index.js')
|
const preload = join(__dirname, '../preload/index.js')
|
||||||
@ -22,6 +30,7 @@ const url = `http://${process.env.VITE_DEV_SERVER_HOST}:${process.env.VITE_DEV_S
|
|||||||
async function createWindow() {
|
async function createWindow() {
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
title: 'Main window',
|
title: 'Main window',
|
||||||
|
icon: join(ROOT_PATH.public, 'favicon.ico'),
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload,
|
preload,
|
||||||
nodeIntegration: true,
|
nodeIntegration: true,
|
||||||
@ -30,13 +39,13 @@ async function createWindow() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (app.isPackaged) {
|
if (app.isPackaged) {
|
||||||
win.loadFile(join(__dirname, '../../index.html'))
|
win.loadFile(indexHtml)
|
||||||
} else {
|
} else {
|
||||||
win.loadURL(url)
|
win.loadURL(url)
|
||||||
// win.webContents.openDevTools()
|
// win.webContents.openDevTools()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test active push message to Renderer-process
|
// Test actively push message to the Electron-Renderer
|
||||||
win.webContents.on('did-finish-load', () => {
|
win.webContents.on('did-finish-load', () => {
|
||||||
win?.webContents.send('main-process-message', new Date().toLocaleString())
|
win?.webContents.send('main-process-message', new Date().toLocaleString())
|
||||||
})
|
})
|
||||||
@ -73,7 +82,7 @@ app.on('activate', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// new window example arg: new windows url
|
// new window example arg: new windows url
|
||||||
ipcMain.handle("open-win", (event, arg) => {
|
ipcMain.handle('open-win', (event, arg) => {
|
||||||
const childWindow = new BrowserWindow({
|
const childWindow = new BrowserWindow({
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload,
|
preload,
|
||||||
@ -81,9 +90,7 @@ ipcMain.handle("open-win", (event, arg) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (app.isPackaged) {
|
if (app.isPackaged) {
|
||||||
childWindow.loadFile(join(__dirname, `../renderer/index.html`), {
|
childWindow.loadFile(indexHtml, { hash: arg })
|
||||||
hash: `${arg}`,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
childWindow.loadURL(`${url}/#${arg}`)
|
childWindow.loadURL(`${url}/#${arg}`)
|
||||||
// childWindow.webContents.openDevTools({ mode: "undocked", activate: true })
|
// childWindow.webContents.openDevTools({ mode: "undocked", activate: true })
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {
|
function domReady(condition: DocumentReadyState[] = ['complete', 'interactive']) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
if (condition.includes(document.readyState)) {
|
if (condition.includes(document.readyState)) {
|
||||||
@ -84,5 +83,10 @@ function useLoading() {
|
|||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
const { appendLoading, removeLoading } = useLoading()
|
const { appendLoading, removeLoading } = useLoading()
|
||||||
window.removeLoading = removeLoading
|
|
||||||
domReady().then(appendLoading)
|
domReady().then(appendLoading)
|
||||||
|
|
||||||
|
window.onmessage = ev => {
|
||||||
|
ev.data.payload === 'removeLoading' && removeLoading()
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(removeLoading, 4999)
|
||||||
|
9
src/global.d.ts
vendored
9
src/global.d.ts
vendored
@ -1,9 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
export { }
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface Window {
|
|
||||||
removeLoading: () => void
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,9 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import './samples/node-api'
|
// import './samples/node-api'
|
||||||
|
|
||||||
createApp(App)
|
createApp(App)
|
||||||
.mount('#app')
|
.mount('#app')
|
||||||
.$nextTick(window.removeLoading)
|
.$nextTick(() => {
|
||||||
|
postMessage({ payload: 'removeLoading' }, '*')
|
||||||
|
})
|
||||||
|
@ -2,7 +2,6 @@ import { lstat } from 'fs/promises'
|
|||||||
import { cwd } from 'process'
|
import { cwd } from 'process'
|
||||||
import { ipcRenderer } from 'electron'
|
import { ipcRenderer } from 'electron'
|
||||||
|
|
||||||
// Usage of ipcRenderer.on
|
|
||||||
ipcRenderer.on('main-process-message', (_event, ...args) => {
|
ipcRenderer.on('main-process-message', (_event, ...args) => {
|
||||||
console.log('[Receive Main-process message]:', ...args)
|
console.log('[Receive Main-process message]:', ...args)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user