Skip to content

Commit

Permalink
optimize pages
Browse files Browse the repository at this point in the history
  • Loading branch information
whalechoi committed Sep 26, 2024
1 parent 00287e5 commit 6fcce11
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ const execServiceCmd = (operation) => {
disablePull.value = true
setTimeout(() => {
execXrayHelperCmd("service " + operation.value).then(value => {
if(operation.value=="start"||operation.value=="restart"){
if(operation.value==="start"||operation.value==="restart"){
execXrayHelperCmd("proxy refresh").then(value2 => {
stdout.value=value+'\n'+value2;
})
}else if (operation.value=="stop"){
}else if (operation.value==="stop"){
execXrayHelperCmd("proxy disable").then(value2 => {
stdout.value=value+'\n'+value2;
})
Expand Down
25 changes: 11 additions & 14 deletions src/Manage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,22 @@
<van-checkbox-group v-model="checked">
<van-cell-group style="top: 46px;">
<van-cell v-for="(item, index) in showNodeList" :key="index" center>
<template #icon>
<!-- <van-icon size="30px" v-show="item.balancing" name="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMCIgaGVpZ2h0PSIzMCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSJub25lIiBzdHJva2U9IiMwMDAwRUUiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIxLjUiIGQ9Im0xMiAxM2w1IDQuNU0xMiAxM2wtNSA0LjVtNS00LjVWOG02LjE5MiA4LjQ0NmMuNTE2LS4yOTguNzc0LS40NDYgMS4wNTgtLjQ0NnMuNTQyLjE0OCAxLjA1OC40NDZsLjYzNC4zNjRjLjUxNi4yOTcuNzc0LjQ0NS45MTYuNjlzLjE0Mi41NDIuMTQyIDEuMTM2di43Mj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uNjlzLS4xNDItLjU0Mi0uMTQyLTEuMTM2di0uNzI4YzAtLjU5NCAwLS44OTEuMTQyLTEuMTM2cy40LS4zOTMuOTE3LS42OXoiIGNvbG9yPSIjMDAwMEVFIi8+PC9zdmc+" /> -->
<van-icon name="link-o" v-show="item.selected" color="#07c160" size="30px" />
</template>
<template #title>
<span class="custom-title">{{ item.remarks }}</span>
<span class="custom-title">{{ item.remarks }}</span><br/>
</template>
<template #label>
<van-space wrap>
<van-space fill>
<van-tag type="primary">{{ item.type }}</van-tag>
<van-tag :color="item.color" v-show:="item.show">{{ item.ping }}</van-tag>
<van-tag :color="item.color" v-show="item.show">{{ item.ping }}</van-tag>
</van-space>
<!-- <span class="custom-title">{{ item.Server }}:{{ item.Port }}</span> -->
<span class="custom-title">{{ item.host }}:{{ item.port }}</span>
</template>
<template #value>
<van-space wrap>
<van-button plain hairline type="default" size="small"
:loading="item.speedtestLoading" @click="clickSpeedtest(item, index)">{{
i18n.global.t('manage.speedtest') }}</van-button>
:loading="item.speedtestLoading" @click="clickSpeedtest(item, index)">{{ i18n.global.t('manage.speedtest') }}</van-button>
<van-button plain hairline type="default" size="small" :loading="item.switchLoading"
@click="switchChecked(item)">{{
i18n.global.t('manage.switch') }}</van-button>
@click="switchChecked(item)">{{ item.selected? '\u0008\u0008✔\u0008\u0008':i18n.global.t('manage.switch') }}</van-button>
<van-checkbox :name="index" shape="square" v-show="checkBoxShow"></van-checkbox>
</van-space>
</template>
Expand Down Expand Up @@ -119,6 +113,7 @@ const getConfig = async () => {
})
}
const switchChecked = (item) => {
item.switchLoading = true;
//有BUG,如果在查找的情况下就会导致
console.info('switchChecked')
let idx = allNodeList.value.indexOf(item);
Expand All @@ -145,7 +140,8 @@ const switchChecked = (item) => {
} else {
showToast(i18n.global.t('dashboard.tool-switch-failed'))
}
onRefresh();
item.switchLoading = false
onRefresh()
})
}
const onLoad = () => {
Expand Down Expand Up @@ -393,7 +389,7 @@ const convertObject = (arr, custom) => {
obj['custom'] = custom;
obj['hashId'] = cyrb53(JSON.stringify(obj));
// TODO 可能会出现多个相同节点?
obj['selected'] = lastSelected === obj.hashId;
obj['selected'] = lastSelected == obj.hashId;
convertArr.push(obj);
}
return convertArr;
Expand Down Expand Up @@ -441,6 +437,7 @@ initStatus()
.custom-title {
margin-right: 4px;
vertical-align: middle;
white-space: nowrap;
}
.search-icon {
Expand Down
21 changes: 10 additions & 11 deletions src/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
import {ref} from 'vue'
import i18n from "./locales/i18n.js"
import YAML from "yaml"
import {callApi, readFile,execCmdWithErrNo,execXrayHelperCmd, saveFile, XRAYHELPER_CONFIG} from "./tools.js"
import {callApi, readFile,execCmdWithExitCode,execXrayHelperCmd, saveFile, XRAYHELPER_CONFIG} from "./tools.js"
defineProps(["theme"])
const loading = ref(false)
Expand All @@ -269,11 +269,10 @@ const changeCoreType = (core) => {
saveConfig()
showConfirmDialog({
message: i18n.global.t('setting.switch-core')
})
.then(() => {
const basePath='/data/adb/xray'
const binPath=`${basePath}/bin/${core.value}`
config.value.xrayHelper.corePath=binPath
}).then(() => {
const basePath = '/data/adb/xray'
const binPath = `${basePath}/bin/${core.value}`
config.value.xrayHelper.corePath = binPath
switch (core.value) {
case 'v2ray':
config.value.xrayHelper.coreConfig = `${basePath}/v2rayconfs/config.json`
Expand All @@ -296,8 +295,7 @@ const changeCoreType = (core) => {
}
saveConfig()
checkCoreBin(binPath)
})
.catch(() => {
}).catch(() => {
() => resolve(true)
});
}
Expand Down Expand Up @@ -350,8 +348,8 @@ const socksPortEditor = ref(false)
const tunDeviceEditor = ref(false)
const checkCoreBin = (corePath) => {
execCmdWithErrNo(`ls ${corePath}`).then(errno => {
if(errno!=0){
execCmdWithExitCode(`ls ${corePath}`).then(errno => {
if(errno!==0){
showConfirmDialog({
message: i18n.global.t('setting.core-not-found'),
}).then(() => {
Expand Down Expand Up @@ -479,13 +477,14 @@ const saveConfig = () => {
setTimeout(() => {
callApi("get status").then(value => {
if (value.pid.length > 0) {
execXrayHelperCmd("proxy refresh").then(value2 => {
execXrayHelperCmd("proxy refresh").then(() => {
showToast(i18n.global.t('setting.refresh-proxy'))
})
}
})
}, 50)
}
const onRefresh = () => {
setTimeout(() => {
initConfig()
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const manage = {
'placeholder-text': 'Please enter an Remarks.',
'speedtest-fail': 'The speed measurement failed and an exception occurred.',
'speedtest-reject': 'Wait patiently until the speed measurement of other nodes is completed before continuing.',
'speedtest-all-warn': 'All nodes will be speed tested soon to prevent the airport from being blocked! Use with caution (ps: not recommended. Too many nodes will freeze the page). Confirm to continue?',
'speedtest-all-warn': 'All nodes will be speed tested soon to prevent the airport from being blocked! Use with caution. Confirm to continue?',
}
export const setting = {
'xrayhelper': 'Config - XrayHelper',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const manage = {
'placeholder-text': '请输入别名',
'speedtest-fail': '测速失败,发生异常。',
'speedtest-reject': '耐心等待其他节点测速结束后再继续。',
'speedtest-all-warn': '即将测速所有节点,以防机场封号!谨慎使用(ps:不推荐,节点多页面会卡死),确认继续?',
'speedtest-all-warn': '即将测速所有节点,以防机场封号!谨慎使用,确认继续?',
}
export const setting = {
'xrayhelper': '配置项 - XrayHelper',
Expand Down
6 changes: 2 additions & 4 deletions src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Buffer} from 'buffer/'
export const XRAYHELPER = "/data/adb/xray/bin/xrayhelper"
export const XRAYHELPER_CONFIG = "/data/adb/xray/xrayhelper.yml"

export const execCmdWithErrNo = async (cmd) => {
export const execCmdWithExitCode = async (cmd) => {
console.info(cmd)
const {errno, stdout,stderr} = await exec(cmd, {cwd: '/'})
if (errno === 0) {
Expand Down Expand Up @@ -51,15 +51,13 @@ export const callApi = async (api) => {
} else if (!(api instanceof Array)) {
api = api.split(" ")
}
let params = ["-c", XRAYHELPER, "-c", XRAYHELPER_CONFIG, "api"]
let params = ["-c", XRAYHELPER, "-c", XRAYHELPER_CONFIG, "-t", "3", "api"]
params.push(...api)
let process = spawn('su', params);
process.stdout.on('data', (data) => {
debugger
result.data = JSON.parse(data)
})
process.on('exit', () => {
debugger
result.exited = true
})
while (true) {
Expand Down

0 comments on commit 6fcce11

Please sign in to comment.