Skip to content

Commit

Permalink
perf: 🚀 采用新的方法实现所有进程共享 isPackaged
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Oct 18, 2023
1 parent 4f9cb30 commit 8a5f7d9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@

请参阅 [scrcpy/doc/shortcuts](https://github.com/Genymobile/scrcpy/blob/master/doc/shortcuts.md)

## 设备交互操作栏

- 切换键
- 主屏幕键
- 返回键
- 菜单键
- 电源键
- 截取屏幕
- 安装应用

## 高级配置

> 持续完善中 目前支持 Scrcpy 中以下常用配置
Expand Down Expand Up @@ -159,7 +169,7 @@

## 支持项目

> 如果该项目帮到你的话,可以请我喝杯咖啡,让我更有精神完善该项目😛
> 如果该项目帮到你的话,可以请我喝杯咖啡,让我更有精神完善该项目 😛
> 注意:非 BUG 或计划外的需求,有偿处理;至于金额,根据问题难易程度,你觉得帮助了多少,看着给吧(维护这些项目已经耗费了大量精力,还要免费花时间解答问题就说不过去了吧...所以白嫖的一律不通过。)
Expand Down
1 change: 1 addition & 0 deletions electron/configs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ 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')
7 changes: 4 additions & 3 deletions electron/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { resolve } from 'node:path'
import { contextBridge } from 'electron'

export const isPackaged = !process.env.VITE_DEV_SERVER_URL
export const isPackaged = process.env.IS_PACKAGED === 'true'

export const extraResolve = value =>
isPackaged
export const extraResolve = (value) => {
return isPackaged
? resolve(process.resourcesPath, `extra/${value}`)
: resolve(`electron/resources/extra/${value}`)
}

export const buildResolve = value =>
resolve(`electron/resources/build/${value}`)
Expand Down
6 changes: 6 additions & 0 deletions electron/helpers/packaged.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** 在主进程中获取项目打包状态并将该值存储到环境变量中,从而在预加载脚本中及渲染进程中使用 */
/** 注意: app.isPackaged 可能被被某些方法改变所以请将该文件放到 main.js 必须位于非依赖项的顶部 */

import { app } from 'electron'

process.env.IS_PACKAGED = JSON.stringify(app.isPackaged)
9 changes: 4 additions & 5 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import path from 'node:path'
import { BrowserWindow, app, shell } from 'electron'
import { electronApp, optimizer } from '@electron-toolkit/utils'

import {
icnsLogoPath,
icoLogoPath,
logoPath,
} from '@electron/configs/index.js'
// packaged.js 必须位于非依赖项的顶部
import './helpers/packaged.js'

import { icnsLogoPath, icoLogoPath, logoPath } from './configs/index.js'

import events from './events/index.js'

Expand Down
1 change: 0 additions & 1 deletion src/icons/components/SvgIcon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default {
},
},
render() {
console.log('this', this)
if (this.SvgComponent) {
const props = this.SvgComponent.props
return {
Expand Down

0 comments on commit 8a5f7d9

Please sign in to comment.