Skip to content

Commit

Permalink
feat: 🚀 新增支持导入及导出配置
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Oct 18, 2023
1 parent 7a59329 commit 326a133
Show file tree
Hide file tree
Showing 21 changed files with 589 additions and 235 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@
- 截取屏幕
- 安装应用

## 高级配置
## 偏好设置

> 持续完善中 目前支持 Scrcpy 中以下常用配置
> 持续完善中 目前支持以下常用配置
### 自定义

- Adb 路径
- Scrcpy 路径
- 文件存储路径(音视频及截图保存在这里)

### 视频控制

Expand Down
62 changes: 49 additions & 13 deletions electron/events/handles/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import fs from 'fs-extra'
import { dialog, ipcMain, shell } from 'electron'

export default () => {
ipcMain.handle('show-open-dialog', async (event, params) => {
// console.log('params', params)
try {
const res = await dialog.showOpenDialog(params)
// console.log('showOpenDialog.res', res)
if (res.canceled) {
ipcMain.handle(
'show-open-dialog',
async (event, { preset = '', ...options } = {}) => {
// console.log('options', options)
try {
const res = await dialog.showOpenDialog(options)
// console.log('showOpenDialog.res', res)
if (res.canceled) {
return false
}
const filePaths = res.filePaths

switch (preset) {
case 'replaceFile':
await fs.copy(filePaths[0], options.filePath, { overwrite: true })
break
}

return filePaths
}
catch (error) {
console.warn(error?.message || error)
return false
}
return res.filePaths
}
catch (error) {
console.warn(error?.message || error)
return false
}
})
},
)

ipcMain.handle('open-path', async (event, pathValue) => {
try {
Expand All @@ -38,4 +50,28 @@ export default () => {
return false
}
})

ipcMain.handle(
'show-save-dialog',
async (event, { filePath = '', ...options } = {}) => {
try {
const result = await dialog.showSaveDialog({
...options,
})
if (!result || result.canceled || !result.filePath) {
return false
}

const destinationPath = result.filePath

await fs.copy(filePath, destinationPath)

return true
}
catch (error) {
console.error(error?.message || error)
return false
}
},
)
}
12 changes: 11 additions & 1 deletion electron/exposes/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import path from 'node:path'

import * as configs from '@electron/configs/index.js'
import store from './store/index.js'
import electron from './electron/index.js'
import adbkit from './adbkit/index.js'
import scrcpy from './scrcpy/index.js'

export default {
init(expose) {
expose('nodePath', path)
expose('electron', electron())

expose('appStore', store())

expose('electron', {
...electron(),
configs,
})

expose('adbkit', adbkit())
expose('scrcpy', scrcpy())
},
Expand Down
27 changes: 27 additions & 0 deletions electron/exposes/store/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Store from 'electron-store'
import { createProxy } from '@electron/helpers/index'

export default () => {
const appStore = new Store()

appStore.onDidAnyChange(() => {
console.log('reload.appStore.onDidAnyChange', appStore.store)
})

return {
...createProxy(appStore, [
'set',
'get',
'delete',
'clear',
'reset',
'has',
'onDidChange',
'onDidAnyChange',
'openInEditor',
]),
...appStore,
getAll: () => appStore.store,
setAll: value => (appStore.store = value),
}
}
15 changes: 15 additions & 0 deletions electron/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,18 @@ export function exposeContext(key, value) {
window[key] = value
}
}

/**
* 创建一个代理对象,将目标对象的指定方法转发并执行。
*
* @param {object} targetObject - 目标对象,包含要代理的方法。
* @param {string[]} methodNames - 要代理的方法名称数组。
* @returns {object} - 代理对象,包含转发的方法。
*/
export function createProxy(targetObject, methodNames) {
return methodNames.reduce((proxyObj, methodName) => {
proxyObj[methodName] = (...args) => targetObject[methodName](...args)

return proxyObj
}, {})
}
3 changes: 3 additions & 0 deletions electron/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'node:path'
import { BrowserWindow, app, shell } from 'electron'
import Store from 'electron-store'
import { electronApp, optimizer } from '@electron-toolkit/utils'

// packaged.js 必须位于非依赖项的顶部
Expand All @@ -9,6 +10,8 @@ import { icnsLogoPath, icoLogoPath, logoPath } from './configs/index.js'

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

const appStore = new Store()

// The built directory structure
//
// ├─┬─┬ dist
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
"dayjs": "^1.11.10",
"electron": "^26.1.0",
"electron-builder": "^24.6.4",
"electron-store": "^8.1.0",
"electron-updater": "^6.1.4",
"element-plus": "^2.4.0",
"fs-extra": "^11.1.1",
"lodash-es": "^4.17.21",
"pinia": "^2.1.7",
"typescript": "^5.2.2",
Expand Down
Loading

0 comments on commit 326a133

Please sign in to comment.