mirror of
https://github.com/viarotel-org/escrcpy.git
synced 2025-01-18 17:14:10 +01:00
fix: 🐛 修复 electron 资源路径问题
This commit is contained in:
parent
09c8deeca9
commit
955756e114
@ -1,14 +1,17 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json",
|
||||
"productName": "Escrcpy",
|
||||
"appId": "org.viarotel.escrcpy",
|
||||
"asar": true,
|
||||
"productName": "Escrcpy",
|
||||
"directories": {
|
||||
"output": "dist-release",
|
||||
"buildResources": "electron/resources/build"
|
||||
},
|
||||
"files": ["dist", "dist-electron"],
|
||||
"extraResources": ["electron/resources/extra"],
|
||||
"extraResources": {
|
||||
"from": "electron/resources/extra",
|
||||
"to": "extra"
|
||||
},
|
||||
"publish": {
|
||||
"provider": "github",
|
||||
"owner": "viarotel-org",
|
||||
@ -30,7 +33,6 @@
|
||||
},
|
||||
"win": {
|
||||
"icon": "logo.ico",
|
||||
"executableName": "escrcpy",
|
||||
"target": [
|
||||
{
|
||||
"target": "nsis",
|
||||
|
12
electron/configs/index.js
Normal file
12
electron/configs/index.js
Normal file
@ -0,0 +1,12 @@
|
||||
import { resolve } from 'node:path'
|
||||
|
||||
import { buildResolve, extraResolve } from '@electron/helpers/index.js'
|
||||
|
||||
export const devPublishPath = resolve('dev-publish.yml')
|
||||
|
||||
export const logoPath = buildResolve('logo.png')
|
||||
export const icoLogoPath = buildResolve('logo.ico')
|
||||
export const icnsLogoPath = buildResolve('logo.icns')
|
||||
|
||||
export const adbPath = extraResolve('core/adb.exe')
|
||||
export const scrcpyPath = extraResolve('core/scrcpy.exe')
|
@ -1,14 +1,13 @@
|
||||
import { app, ipcMain } from 'electron'
|
||||
import { is } from '@electron-toolkit/utils'
|
||||
import { autoUpdater } from 'electron-updater'
|
||||
import devPublishPath from '@root/dev-publish.yml?path'
|
||||
import { devPublishPath } from '@electron/configs/index.js'
|
||||
|
||||
export default (mainWindow) => {
|
||||
// dev-start, 这里是为了在本地做应用升级测试使用,正式环境请务必删除
|
||||
// if (is.dev && process.env.ELECTRON_RENDERER_URL) {
|
||||
if (is.dev && process.env.VITE_DEV_SERVER_URL) {
|
||||
const updateConfigPath = devPublishPath
|
||||
autoUpdater.updateConfigPath = updateConfigPath
|
||||
autoUpdater.updateConfigPath = devPublishPath
|
||||
Object.defineProperty(app, 'isPackaged', {
|
||||
get() {
|
||||
return true
|
||||
|
@ -4,7 +4,9 @@ import path from 'node:path'
|
||||
import fs from 'node:fs'
|
||||
import dayjs from 'dayjs'
|
||||
import { Adb } from '@devicefarmer/adbkit'
|
||||
import adbPath from '@resources/extra/core/adb.exe?path'
|
||||
import { adbPath } from '@electron/configs/index.js'
|
||||
|
||||
console.log('adbPath', adbPath)
|
||||
|
||||
const exec = util.promisify(child_process.exec)
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
import util from 'node:util'
|
||||
import child_process from 'node:child_process'
|
||||
import adbPath from '@resources/extra/core/adb.exe?path'
|
||||
import scrcpyPath from '@resources/extra/core/scrcpy.exe?path'
|
||||
import { adbPath, scrcpyPath } from '@electron/configs/index.js'
|
||||
|
||||
const exec = util.promisify(child_process.exec)
|
||||
|
||||
|
@ -1,5 +1,16 @@
|
||||
import { resolve } from 'node:path'
|
||||
import { contextBridge } from 'electron'
|
||||
|
||||
export const isPackaged = !process.resourcesPath.includes('node_modules')
|
||||
|
||||
export const extraResolve = value =>
|
||||
isPackaged
|
||||
? resolve(process.resourcesPath, `extra/${value}`)
|
||||
: resolve(`electron/resources/extra/${value}`)
|
||||
|
||||
export const buildResolve = value =>
|
||||
resolve(`electron/resources/build/${value}`)
|
||||
|
||||
export function exposeContext(key, value) {
|
||||
if (process.contextIsolated) {
|
||||
try {
|
||||
|
@ -2,9 +2,11 @@ import path from 'node:path'
|
||||
import { BrowserWindow, app, shell } from 'electron'
|
||||
import { electronApp, optimizer } from '@electron-toolkit/utils'
|
||||
|
||||
import logoPath from '@resources/build/logo.png?path'
|
||||
import icoLogoPath from '@resources/build/logo.ico?path'
|
||||
import icnsLogoPath from '@resources/build/logo.icns?path'
|
||||
import {
|
||||
icnsLogoPath,
|
||||
icoLogoPath,
|
||||
logoPath,
|
||||
} from '@electron/configs/index.js'
|
||||
|
||||
import events from './events/index.js'
|
||||
|
||||
@ -70,7 +72,6 @@ function createWindow() {
|
||||
mainWindow.loadURL(VITE_DEV_SERVER_URL)
|
||||
}
|
||||
else {
|
||||
// win.loadFile('dist/index.html')
|
||||
mainWindow.loadFile(path.join(process.env.DIST, 'index.html'))
|
||||
}
|
||||
|
||||
|
@ -4,9 +4,9 @@
|
||||
"paths": {
|
||||
"@/*": ["src/*"],
|
||||
"@root/*": ["*"],
|
||||
"@resources/*": ["electron/resources/*"]
|
||||
"@electron/*": ["electron/*"]
|
||||
}
|
||||
},
|
||||
"exclude": ["node_modules", "dist", "dist-electron", "dist-release"],
|
||||
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.vue", "electron"]
|
||||
}
|
||||
}
|
||||
|
@ -6,47 +6,47 @@ import useRenderer from 'vite-plugin-electron-renderer'
|
||||
import useVue from '@vitejs/plugin-vue'
|
||||
import useEslint from 'vite-plugin-eslint'
|
||||
import useUnoCSS from 'unocss/vite'
|
||||
import usePath from '@viarotel-org/vite-plugin-path'
|
||||
|
||||
const merge = config =>
|
||||
mergeConfig(
|
||||
{
|
||||
resolve: {
|
||||
alias: {
|
||||
'@root': resolve('./'),
|
||||
'@resources': resolve('./electron/resources'),
|
||||
'@root': resolve(),
|
||||
'@electron': resolve('electron'),
|
||||
},
|
||||
},
|
||||
plugins: [usePath()],
|
||||
plugins: [],
|
||||
},
|
||||
config,
|
||||
)
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
assetsInclude: ['**/*.exe'],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve('./src'),
|
||||
export default merge(
|
||||
defineConfig({
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve('src'),
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
useEslint(),
|
||||
useUnoCSS(),
|
||||
useVue(),
|
||||
useElectron([
|
||||
{
|
||||
entry: 'electron/main.js',
|
||||
vite: merge({}),
|
||||
},
|
||||
{
|
||||
entry: 'electron/preload.js',
|
||||
onstart(args) {
|
||||
args.reload()
|
||||
plugins: [
|
||||
useEslint(),
|
||||
useUnoCSS(),
|
||||
useVue(),
|
||||
useElectron([
|
||||
{
|
||||
entry: 'electron/main.js',
|
||||
vite: merge({}),
|
||||
},
|
||||
vite: merge({}),
|
||||
},
|
||||
]),
|
||||
useRenderer(),
|
||||
],
|
||||
})
|
||||
{
|
||||
entry: 'electron/preload.js',
|
||||
onstart(args) {
|
||||
args.reload()
|
||||
},
|
||||
vite: merge({}),
|
||||
},
|
||||
]),
|
||||
useRenderer(),
|
||||
],
|
||||
}),
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user