From 894b581988995ad8e6e386041b231722ca9e7ffa Mon Sep 17 00:00:00 2001 From: viarotel Date: Thu, 26 Oct 2023 18:11:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=94=A7=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E8=B7=AF=E5=BE=84=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/exposes/adbkit/index.js | 6 +- electron/exposes/scrcpy/index.js | 4 +- src/store/index.js | 4 +- src/store/scrcpy/index.js | 185 ------------------------- src/store/scrcpy/model/audio/index.js | 17 --- src/store/scrcpy/model/custom/index.js | 39 ------ src/store/scrcpy/model/device/index.js | 44 ------ src/store/scrcpy/model/index.js | 6 - src/store/scrcpy/model/record/index.js | 23 --- src/store/scrcpy/model/video/index.js | 154 -------------------- src/store/scrcpy/model/window/index.js | 34 ----- 11 files changed, 6 insertions(+), 510 deletions(-) delete mode 100644 src/store/scrcpy/index.js delete mode 100644 src/store/scrcpy/model/audio/index.js delete mode 100644 src/store/scrcpy/model/custom/index.js delete mode 100644 src/store/scrcpy/model/device/index.js delete mode 100644 src/store/scrcpy/model/index.js delete mode 100644 src/store/scrcpy/model/record/index.js delete mode 100644 src/store/scrcpy/model/video/index.js delete mode 100644 src/store/scrcpy/model/window/index.js diff --git a/electron/exposes/adbkit/index.js b/electron/exposes/adbkit/index.js index 67b278d..ba274aa 100644 --- a/electron/exposes/adbkit/index.js +++ b/electron/exposes/adbkit/index.js @@ -18,8 +18,8 @@ window.addEventListener('beforeunload', () => { } }) -appStore.onDidChange('scrcpy.common.adbPath', async (value, oldValue) => { - console.log('onDidChange.scrcpy.common.adbPath', value) +appStore.onDidChange('common.adbPath', async (value, oldValue) => { + console.log('onDidChange.common.adbPath', value) if (value === oldValue) { return false @@ -146,7 +146,7 @@ const watch = async (callback) => { } export default () => { - const binPath = appStore.get('scrcpy.common.adbPath') || adbPath + const binPath = appStore.get('common.adbPath') || adbPath client = Adb.createClient({ bin: binPath, diff --git a/electron/exposes/scrcpy/index.js b/electron/exposes/scrcpy/index.js index fb489ae..69b8ef6 100644 --- a/electron/exposes/scrcpy/index.js +++ b/electron/exposes/scrcpy/index.js @@ -3,8 +3,8 @@ import appStore from '@electron/helpers/store.js' import { adbPath, scrcpyPath } from '@electron/configs/index.js' const shell = async (command, { stdout, stderr } = {}) => { - const spawnPath = appStore.get('scrcpy.common.scrcpyPath') || scrcpyPath - const ADB = appStore.get('scrcpy.common.adbPath') || adbPath + const spawnPath = appStore.get('common.scrcpyPath') || scrcpyPath + const ADB = appStore.get('common.adbPath') || adbPath const args = command.split(' ') const scrcpyProcess = spawn(`"${spawnPath}"`, args, { diff --git a/src/store/index.js b/src/store/index.js index 77d21e5..eafdc42 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,9 +1,8 @@ import { createPinia } from 'pinia' -import { useScrcpyStore } from './scrcpy/index.js' import { useDeviceStore } from './device/index.js' import { usePreferenceStore } from './preference/index.js' -export { useScrcpyStore, useDeviceStore, usePreferenceStore } +export { useDeviceStore, usePreferenceStore } export default { install(app) { @@ -12,7 +11,6 @@ export default { app.use(store) app.config.globalProperties.$store = { - scrcpy: useScrcpyStore(), device: useDeviceStore(), preference: usePreferenceStore(), } diff --git a/src/store/scrcpy/index.js b/src/store/scrcpy/index.js deleted file mode 100644 index 6f182dc..0000000 --- a/src/store/scrcpy/index.js +++ /dev/null @@ -1,185 +0,0 @@ -import { defineStore } from 'pinia' -import { cloneDeep, mergeWith } from 'lodash-es' -import * as scrcpyModel from './model/index.js' -import { replaceIP } from '@/utils/index.js' - -const $appStore = window.appStore - -const { adbPath, scrcpyPath } = window.electron?.configs || {} - -function mergeConfig(object, sources, { debug = false } = {}) { - const customizer = (objValue, srcValue) => { - if (debug) { - console.log('objValue', typeof objValue) - console.log('srcValue', typeof srcValue) - } - - if (typeof srcValue === 'boolean') { - return srcValue - } - - return srcValue || objValue - } - - const value = mergeWith(cloneDeep(object), cloneDeep(sources), customizer) - - return value -} - -/** - * 获取 Scrcpy 默认配置 - */ -function getDefaultConfig(type) { - const model = [] - if (type) { - const handler = scrcpyModel[type] - model.push(...handler()) - } - else { - // console.raw('scrcpyModel', scrcpyModel) - const values = Object.values(scrcpyModel) - model.push(...values.flatMap(handler => handler())) - } - - const value = model.reduce((obj, item) => { - const { field, value } = item - obj[field] = value - return obj - }, {}) - - return value -} - -export const useScrcpyStore = defineStore({ - id: 'app-scrcpy', - state() { - return { - scope: $appStore.get('scrcpy.scope') || 'global', - model: { ...scrcpyModel }, - defaultConfig: getDefaultConfig(), - config: {}, - excludeKeys: ['--record-format', 'savePath', 'adbPath', 'scrcpyPath'], - } - }, - actions: { - replaceIP, - getDefaultConfig, - init(scope = this.scope) { - let tempConfig = mergeConfig( - this.defaultConfig, - $appStore.get('scrcpy.global') || {}, - ) - - if (scope !== 'global') { - const scopeConfig = $appStore.get(`scrcpy.${replaceIP(scope)}`) || {} - tempConfig = mergeConfig(tempConfig, scopeConfig) - } - - this.config = tempConfig - - return this.config - }, - reset(scope) { - if (scope) { - this.scope = scope - $appStore.set(`scrcpy.${replaceIP(scope)}`, {}) - } - else { - this.scope = 'global' - $appStore.set('scrcpy', {}) - } - - this.init() - }, - resetDeps(type) { - switch (type) { - case 'adb': - $appStore.set('scrcpy.common.adbPath', '') - break - case 'scrcpy': - $appStore.set('scrcpy.common.scrcpyPath', '') - break - default: - $appStore.set('scrcpy.common.adbPath', '') - $appStore.set('scrcpy.common.scrcpyPath', '') - break - } - this.init() - }, - setScope(value) { - this.scope = replaceIP(value) - $appStore.set('scrcpy.scope', this.scope) - this.init() - }, - getStringConfig(scope = this.scope) { - const config = this.getConfig(scope) - - if (!config) { - return '' - } - - const value = Object.entries(config) - .reduce((arr, [key, value]) => { - if (!value) { - return arr - } - - if (this.excludeKeys.includes(key)) { - return arr - } - - if (typeof value === 'boolean') { - arr.push(key) - } - else { - arr.push(`${key}=${value}`) - } - - return arr - }, []) - .join(' ') - - // console.log('stringifyConfig.value', value) - - return value - }, - setConfig(data, scope = this.scope) { - const cloneData = cloneDeep(data) - - // console.log('adbPath', adbPath) - // console.log('scrcpyPath', scrcpyPath) - - if (data.adbPath === adbPath) { - delete cloneData.adbPath - } - - if (data.scrcpyPath === scrcpyPath) { - delete cloneData.scrcpyPath - } - - $appStore.set(`scrcpy.${replaceIP(scope)}`, cloneData) - - this.init(scope) - }, - getConfig(scope = this.scope) { - const value = this.init(scope) - return value - }, - getModel(key, params) { - const handler = this.model[key] - const value = handler(params) - // console.log('setModel.value', value) - - return value - }, - setModel(key, params) { - const handler = this.model[key] - const value = handler(params) - // console.log('setModel.value', value) - - this.model[key] = () => value - - return this.model - }, - }, -}) diff --git a/src/store/scrcpy/model/audio/index.js b/src/store/scrcpy/model/audio/index.js deleted file mode 100644 index 5855d67..0000000 --- a/src/store/scrcpy/model/audio/index.js +++ /dev/null @@ -1,17 +0,0 @@ -import { t } from '@/locales/index.js' - -export default () => { - // "[server] INFO: List of audio encoders:" - // "--audio-codec=opus --audio-encoder='c2.android.opus.encoder'" - // "--audio-codec=aac --audio-encoder='c2.android.aac.encoder'" - // "--audio-codec=aac --audio-encoder='OMX.google.aac.encoder'" - return [ - { - label: t('preferences.audio.disable.name'), - field: '--no-audio', - type: 'switch', - value: false, - placeholder: t('preferences.audio.disable.placeholder'), - }, - ] -} diff --git a/src/store/scrcpy/model/custom/index.js b/src/store/scrcpy/model/custom/index.js deleted file mode 100644 index 87782a6..0000000 --- a/src/store/scrcpy/model/custom/index.js +++ /dev/null @@ -1,39 +0,0 @@ -import { t } from '@/locales/index.js' - -export default () => { - const { adbPath, scrcpyPath, desktopPath } = window?.electron?.configs || {} - - return [ - { - label: t('preferences.common.file.name'), - type: 'input.path', - field: 'savePath', - value: desktopPath, - placeholder: t('preferences.common.file.placeholder'), - tips: t('preferences.common.file.tips'), - properties: ['openDirectory'], - }, - { - label: t('preferences.common.adb.name'), - field: 'adbPath', - type: 'input.path', - value: adbPath, - placeholder: t('preferences.common.adb.placeholder'), - tips: t('preferences.common.adb.tips'), - properties: ['openFile'], - filters: [{ name: t('preferences.common.adb.name'), extensions: ['*'] }], - }, - { - label: t('preferences.common.scrcpy.name'), - field: 'scrcpyPath', - type: 'input.path', - value: scrcpyPath, - placeholder: t('preferences.common.scrcpy.placeholder'), - tips: t('preferences.common.scrcpy.tips'), - properties: ['openFile'], - filters: [ - { name: t('preferences.common.scrcpy.name'), extensions: ['*'] }, - ], - }, - ] -} diff --git a/src/store/scrcpy/model/device/index.js b/src/store/scrcpy/model/device/index.js deleted file mode 100644 index aa7191a..0000000 --- a/src/store/scrcpy/model/device/index.js +++ /dev/null @@ -1,44 +0,0 @@ -import { t } from '@/locales/index.js' - -export default () => { - return [ - { - label: t('preferences.device.show-touch.name'), - type: 'switch', - field: '--show-touches', - value: false, - placeholder: t('preferences.device.show-touch.placeholder'), - tips: t('preferences.device.show-touch.tips'), - }, - { - label: t('preferences.device.stay-awake.name'), - type: 'switch', - field: '--stay-awake', - value: false, - placeholder: t('preferences.device.stay-awake.placeholder'), - tips: t('preferences.device.stay-awake.tips'), - }, - { - label: t('preferences.device.control-in-close-screen.name'), - type: 'switch', - field: '--turn-screen-off', - value: false, - placeholder: t('preferences.device.control-in-close-screen.placeholder'), - }, - { - label: t('preferences.device.control-end-video.name'), - type: 'switch', - field: '--power-off-on-close', - value: false, - placeholder: t('preferences.device.control-end-video.placeholder'), - }, - { - label: t('preferences.device.control-in-stop-charging.name'), - type: 'switch', - field: '--no-power-on', - value: false, - placeholder: t('preferences.device.control-in-stop-charging.placeholder'), - tips: t('preferences.device.control-in-stop-charging.tips'), - }, - ] -} diff --git a/src/store/scrcpy/model/index.js b/src/store/scrcpy/model/index.js deleted file mode 100644 index 45efbc6..0000000 --- a/src/store/scrcpy/model/index.js +++ /dev/null @@ -1,6 +0,0 @@ -export { default as custom } from './custom/index.js' -export { default as video } from './video/index.js' -export { default as device } from './device/index.js' -export { default as window } from './window/index.js' -export { default as audio } from './audio/index.js' -export { default as record } from './record/index.js' diff --git a/src/store/scrcpy/model/record/index.js b/src/store/scrcpy/model/record/index.js deleted file mode 100644 index 5c7eec1..0000000 --- a/src/store/scrcpy/model/record/index.js +++ /dev/null @@ -1,23 +0,0 @@ -import { t } from '@/locales/index.js' - -export default () => { - return [ - { - label: t('preferences.record.format.name'), - type: 'select', - field: '--record-format', - value: 'mp4', - placeholder: t('preferences.record.format.placeholder'), - options: [ - { - label: 'mp4', - value: 'mp4', - }, - { - label: 'mkv', - value: 'mkv', - }, - ], - }, - ] -} diff --git a/src/store/scrcpy/model/video/index.js b/src/store/scrcpy/model/video/index.js deleted file mode 100644 index 7268504..0000000 --- a/src/store/scrcpy/model/video/index.js +++ /dev/null @@ -1,154 +0,0 @@ -import { t } from '@/locales/index.js' - -const getDisplayOptions = (display = []) => - display?.map(value => ({ label: value, value })) || [] - -export default ({ display } = {}) => { - const displayOptions = display?.length - ? getDisplayOptions(display) - : [ - { label: '0', value: '0' }, - { label: '1', value: '1' }, - { label: '2', value: '2' }, - ] - - return [ - { - label: t('preferences.video.resolution.name'), - type: 'input.number', - field: '--max-size', - value: '', - placeholder: t('preferences.video.resolution.placeholder'), - }, - { - label: t('preferences.video.bit.name'), - type: 'input', - field: '--video-bit-rate', - value: '', - placeholder: t('preferences.video.bit.placeholder'), - }, - { - label: t('preferences.video.refresh-rate.name'), - type: 'input.number', - field: '--max-fps', - value: '', - placeholder: t('preferences.video.refresh-rate.placeholder'), - }, - { - label: t('preferences.video.decoder.name'), - type: 'select', - field: '--video-codec', - value: '', - placeholder: t('preferences.video.decoder.placeholder'), - options: [ - { - label: 'h264', - value: 'h264', - }, - { - label: 'h265', - value: 'h265', - }, - { - label: 'av1', - value: 'av1', - }, - ], - }, - { - label: t('preferences.video.encoder.name'), - type: 'select', - field: '--video-encoder', - value: '', - placeholder: t('preferences.video.encoder.placeholder'), - // "[server] INFO: List of video encoders:" - // "--video-codec=h264 --video-encoder='OMX.qcom.video.encoder.avc'" - // "--video-codec=h264 --video-encoder='c2.android.avc.encoder'" - // "--video-codec=h264 --video-encoder='OMX.google.h264.encoder'" - // "--video-codec=h265 --video-encoder='OMX.qcom.video.encoder.hevc'" - // "--video-codec=h265 --video-encoder='c2.android.hevc.encoder'" - options: [ - { - label: 'Android HEVC(H.265) ', - value: 'OMX.qcom.video.encoder.avc', - }, - { - label: 'Qualcomm HEVC(H.265) ', - value: 'c2.android.avc.encoder', - }, - { - label: 'Google H.264(AVC)', - value: 'OMX.google.h264.encoder', - }, - { - label: 'Android AVC(H.264) ', - value: 'OMX.qcom.video.encoder.hevc', - }, - { - label: 'Qualcomm AVC(H.264)', - value: 'c2.android.hevc.encoder', - }, - ], - }, - { - label: t('preferences.video.screen-rotation.name'), - type: 'select', - field: '--rotation', - value: '', - placeholder: t('preferences.video.screen-rotation.placeholder'), - options: [ - { label: '0°', value: '0' }, - { label: '-90°', value: '1' }, - { label: '180°', value: '2' }, - { label: '90°', value: '3' }, - ], - }, - { - label: t('preferences.video.screen-cropping.name'), - type: 'input', - field: '--crop', - value: '', - placeholder: t('preferences.video.screen-cropping.placeholder'), - }, - { - label: t('preferences.video.multi-display.name'), - type: 'select', - field: '--display', - value: '', - placeholder: t('preferences.video.multi-display.placeholder'), - options: displayOptions, - props: { - filterable: true, - allowCreate: true, - }, - }, - { - label: t('preferences.video.video-buffering.name'), - type: 'input.number', - field: '--display-buffer', - value: '', - placeholder: t('preferences.video.video-buffering.placeholder'), - }, - { - label: t('preferences.video.audio-buffering.name'), - type: 'input.number', - field: '--audio-buffer', - value: '', - placeholder: t('preferences.video.video-buffering.placeholder'), - }, - { - label: t('preferences.video.receiver-buffering.name'), - type: 'input.number', - field: '--v4l2-buffer', - value: '', - placeholder: t('preferences.video.video-buffering.placeholder'), - }, - { - label: t('preferences.video.disable.name'), - type: 'switch', - field: '--no-video', - value: false, - placeholder: t('preferences.video.disable.placeholder'), - }, - ] -} diff --git a/src/store/scrcpy/model/window/index.js b/src/store/scrcpy/model/window/index.js deleted file mode 100644 index 8b3f1e1..0000000 --- a/src/store/scrcpy/model/window/index.js +++ /dev/null @@ -1,34 +0,0 @@ -import { t } from '@/locales/index.js' - -export default () => { - return [ - { - label: t('preferences.window.borderless.name'), - field: '--window-borderless', - type: 'switch', - value: false, - placeholder: t('preferences.window.borderless.placeholder'), - }, - { - label: t('preferences.window.full-screen.name'), - field: '--fullscreen', - type: 'switch', - value: false, - placeholder: t('preferences.window.full-screen.placeholder'), - }, - { - label: t('preferences.window.always-top.name'), - field: '--always-on-top', - type: 'switch', - value: false, - placeholder: t('preferences.window.always-top.placeholder'), - }, - { - label: t('preferences.window.disable-screen-saver.name'), - field: '--disable-screensaver', - type: 'switch', - value: false, - placeholder: t('preferences.window.disable-screen-saver.placeholder'), - }, - ] -}