Skip to content

Commit a592185

Browse files
committed
feat: env resolve define
1 parent 7e87326 commit a592185

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

electron/lib/env.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const tryFirst = (functionList: (() => any)[]) => {
3737
for (const fun of functionList) {
3838
try {
3939
return fun();
40-
} catch (e) {}
40+
} catch (e) {
41+
}
4142
}
4243
return null;
4344
};
@@ -106,20 +107,20 @@ export const platformUUID = () => {
106107
return platformUUIDCache;
107108
};
108109

109-
export const buildResolve = (value: string) => {
110+
export const buildResolve = (value: string): string => {
110111
return resolve(`electron/resources/build/${value}`);
111112
};
112113

113-
export const binResolve = (value: string) => {
114+
export const binResolve = (value: string): string => {
114115
return resolve(process.resourcesPath, "bin", value);
115116
};
116117

117-
export const extraResolve = (filePath: string) => {
118+
export const extraResolve = (filePath: string): string => {
118119
const basePath = isPackaged ? process.resourcesPath : "electron/resources";
119120
return resolve(basePath, "extra", filePath);
120121
};
121122

122-
export const extraResolveBin = (filePath: string) => {
123+
export const extraResolveBin = (filePath: string): string => {
123124
if (isWin) {
124125
if (!filePath.endsWith(".exe")) {
125126
filePath += ".exe";

electron/mapi/adb/render.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ const destroy = () => {
1919
}
2020
};
2121

22-
const getBinPath = async () => {
22+
const getBinPath = async (returnEmptyWhenDefault: boolean = false): Promise<string> => {
2323
const binPath = await Config.get("common.adbPath");
24+
const binPathDefault = extraResolveBin("scrcpy/adb");
25+
if (returnEmptyWhenDefault && (!binPath || binPath === binPathDefault)) {
26+
return '';
27+
}
2428
if (binPath) {
2529
return binPath;
2630
}
27-
return extraResolveBin("scrcpy/adb");
31+
return binPathDefault;
2832
};
2933

3034
const setBinPath = async (binPath: string) => {

electron/mapi/scrcpy/render.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ import {Apps} from "../app";
44
import {ADB} from "../adb/render";
55
import {IconvUtil} from "../../lib/util";
66

7-
const getBinPath = async () => {
7+
const getBinPath = async (returnEmptyWhenDefault: boolean = false):Promise<string> => {
88
const binPath = await Config.get("common.scrcpyPath");
9+
const binPathDefault = extraResolveBin("scrcpy/scrcpy");
10+
if (returnEmptyWhenDefault && (!binPath || binPath === binPathDefault)) {
11+
return '';
12+
}
913
if (binPath) {
1014
return binPath;
1115
}
12-
return extraResolveBin('scrcpy/scrcpy')
16+
return binPathDefault
1317
};
1418

1519
const setBinPath = async (binPath: string) => {
@@ -39,7 +43,7 @@ const spawnShell = async (
3943
}, option);
4044
option.env["ADB"] = await ADB.getBinPath();
4145
if (isWin) {
42-
option.env["ADB"] = IconvUtil.convert(option.env["ADB"], "gbk");
46+
// option.env["ADB"] = IconvUtil.convert(option.env["ADB"], "gbk");
4347
}
4448
let binary = await getBinPath();
4549
// local debug

src/components/Setting/SettingEnv.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import {onMounted, ref} from "vue";
44
55
const basic = ref({
66
adbPath: null as string | null,
7+
adbPathDefault: null as string | null,
78
scrcpyPath: null as string | null,
9+
scrcpyPathDefault: null as string | null,
810
});
911
const doLoad = async () => {
10-
basic.value.adbPath = await $mapi.adb.getBinPath();
11-
basic.value.scrcpyPath = await $mapi.scrcpy.getBinPath();
12+
basic.value.adbPath = await $mapi.adb.getBinPath(true);
13+
basic.value.adbPathDefault = await $mapi.adb.getBinPath();
14+
basic.value.scrcpyPath = await $mapi.scrcpy.getBinPath(true);
15+
basic.value.scrcpyPathDefault = await $mapi.scrcpy.getBinPath();
1216
};
1317
1418
onMounted(doLoad);
@@ -38,7 +42,9 @@ const doSelectScrcpyPath = async () => {
3842
<template>
3943
<a-form :model="{}" layout="vertical">
4044
<a-form-item field="name" :label="t('adb路径')">
41-
<a-input @change="doAdbPathChange" v-model="basic.adbPath as string">
45+
<a-input @change="doAdbPathChange"
46+
:placeholder="basic.adbPathDefault"
47+
v-model="basic.adbPath as string">
4248
<template #append>
4349
<span @click="doSelectAdbPath" class="cursor-pointer">
4450
{{ t("选择路径") }}
@@ -47,7 +53,9 @@ const doSelectScrcpyPath = async () => {
4753
</a-input>
4854
</a-form-item>
4955
<a-form-item field="name" :label="t('scrcpy路径')">
50-
<a-input @change="doScrcpyPathChange" v-model="basic.scrcpyPath as string">
56+
<a-input @change="doScrcpyPathChange"
57+
:placeholder="basic.scrcpyPathDefault"
58+
v-model="basic.scrcpyPath as string">
5159
<template #append>
5260
<span @click="doSelectScrcpyPath" class="cursor-pointer">
5361
{{ t("选择路径") }}

src/declarations/type.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ type DefsMapi = {
353353
};
354354

355355
adb: {
356-
getBinPath: () => Promise<string>;
356+
getBinPath: (returnEmptyWhenDefault: boolean = false) => Promise<string>;
357357
setBinPath: (binPath: string) => Promise<boolean>;
358358
spawnShell: (
359359
args: string[],
@@ -408,7 +408,7 @@ type DefsMapi = {
408408
}>;
409409
};
410410
scrcpy: {
411-
getBinPath: () => Promise<string>;
411+
getBinPath: (returnEmptyWhenDefault: boolean = false) => Promise<string>;
412412
setBinPath: (binPath: string) => Promise<boolean>;
413413
spawnShell: (
414414
args: string[],

0 commit comments

Comments
 (0)