Skip to content

Commit

Permalink
refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
whalechoi committed Dec 11, 2024
1 parent 081895c commit cddbf95
Show file tree
Hide file tree
Showing 8 changed files with 519 additions and 599 deletions.
782 changes: 410 additions & 372 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
"dependencies": {
"buffer": "^6.0.3",
"kernelsu": "^1.0.6",
"vant": "^4.9.8",
"vue": "^3.5.12",
"vue-i18n": "^10.0.4",
"vue-router": "^4.4.5",
"yaml": "^2.6.0"
"vant": "^4.9.10",
"vue": "^3.5.13",
"vue-i18n": "^10.0.5",
"vue-router": "^4.5.0",
"yaml": "^2.6.1"
},
"devDependencies": {
"@vant/auto-import-resolver": "^1.2.1",
"@vitejs/plugin-vue": "^5.1.5",
"unplugin-auto-import": "^0.18.3",
"unplugin-vue-components": "^0.27.4",
"vite": "^5.4.11"
"@vitejs/plugin-vue": "^5.2.1",
"unplugin-auto-import": "^0.18.6",
"unplugin-vue-components": "^0.27.5",
"vite": "^6.0.3"
}
}
11 changes: 2 additions & 9 deletions src/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,15 @@
</van-radio-group>
</van-popup>
<!-- stdout receiver -->
<van-popup v-model:show="receiver" round :style="{ width: '90%' ,minHeight:'35%',maxHeight:'85%'}" @closed="refresh">
<van-cell :title="$t('common.stdout')" title-style="max-width:100%;" size="large"/>
<div class="stdout"><p>{{ stdout }}</p></div>
</van-popup>
<StdoutReceiver v-model:show="receiver" v-model:stdout="stdout" @closed="refresh"/>
</van-pull-refresh>
</template>

<script setup>
import {ref} from 'vue';
import {callApi, execCmd, execXrayHelperCmd, readFile, saveFile} from "./tools.js";
import i18n from "./locales/i18n.js"
import StdoutReceiver from "./components/StdoutReceiver.vue";
defineProps(["theme"]);
const MODULE_PROP = "/data/adb/modules/xray4magisk/module.prop"
Expand Down Expand Up @@ -226,9 +224,4 @@ initStatus()
</script>

<style>
.stdout {
white-space: pre-line;
margin-left: 1em;
margin-right: 1em;
}
</style>
30 changes: 4 additions & 26 deletions src/Manage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<template #right>
<van-space wrap>
<van-icon
name="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxZW0iIGhlaWdodD0iMWVtIiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxwYXRoIGZpbGw9IiMxOTg5ZmEiIGQ9Ik0xMSA5LjQ3VjExaDMuNzZMMTMgMTQuNTNWMTNIOS4yNHpNMTMgMUw2IDE1aDV2OGw3LTE0aC01eiIvPjwvc3ZnPg=="
size="1.2rem" @click="confirmSpeedtestAll()" />
name="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxZW0iIGhlaWdodD0iMWVtIiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxwYXRoIGZpbGw9IiMxOTg5ZmEiIGQ9Ik0xMSA5LjQ3VjExaDMuNzZMMTMgMTQuNTNWMTNIOS4yNHpNMTMgMUw2IDE1aDV2OGw3LTE0aC01eiIvPjwvc3ZnPg=="
size="1.2rem" @click="confirmSpeedtestAll()" />
<van-icon name="filter-o" size="1.2rem" @click="searchText = !searchText" />
</van-space>
</template>
Expand Down Expand Up @@ -62,21 +62,7 @@
</van-cell-group>
</van-list>
<!-- switch custom editor -->
<van-popup v-model:show="switchCustomEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveSwitchCustom">
<van-cell :title="$t('manage.edit-custom')" title-style="max-width:100%;">
<template #right-icon>
<van-icon size="1.2rem" name="plus" @click="addSwitchCustom"/>
</template>
</van-cell>
<van-list>
<van-field v-for="(item, idx) in switchCustomResult" :label="idx+':'" labelWidth="1.5em" :model-value="item"
@update:model-value="v => editSwitchCustom(v, idx)">
<template #right-icon>
<van-icon size="1rem" name="cross" @click="deleteSwitchCustom(idx)"/>
</template>
</van-field>
</van-list>
</van-popup>
<ListEditor :title="$t('manage.edit-custom')" v-model:show="switchCustomEditor" v-model:list="switchCustomResult" @closed="saveSwitchCustom"/>
<!-- rule manage -->
<van-popup v-model:show="ruleManage" round :style="{ width: '90%' ,maxHeight:'85%'}">
<van-cell :title="$t('manage.rule-manage')" title-style="max-width:100%;">
Expand Down Expand Up @@ -239,6 +225,7 @@ import {
standardizeDnsruleObject as standardizeDnsruleObjectSingbox,
} from "./sing-box.js";
import {Buffer} from "buffer";
import ListEditor from "./components/ListEditor.vue";

defineProps(["theme"])
const panelUrl = ref('http://127.0.0.1:65532/ui');
Expand Down Expand Up @@ -288,15 +275,6 @@ const showSwitchCustomEditor = () => {
})
})
}
const editSwitchCustom = (value, index) => {
switchCustomResult.value[index] = value
}
const deleteSwitchCustom = (index) => {
switchCustomResult.value.splice(index, 1)
}
const addSwitchCustom = () => {
switchCustomResult.value.push('')
}
const saveSwitchCustom = () => {
let content = ""
for (let v of switchCustomResult.value) {
Expand Down
214 changes: 31 additions & 183 deletions src/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,147 +106,44 @@
clickable @click="intraListEditor = true"/>
</van-cell-group>
</van-pull-refresh>
<!-- popup: xrayhelper editors -->
<van-popup v-model:show="corePathEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.xrayhelper-core-path')" v-model="config.xrayHelper.corePath"/>
</van-popup>
<van-popup v-model:show="coreConfigEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.xrayhelper-core-config')" v-model="config.xrayHelper.coreConfig"/>
</van-popup>
<van-popup v-model:show="dataDirEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.xrayhelper-data-dir')" v-model="config.xrayHelper.dataDir"/>
</van-popup>
<van-popup v-model:show="runDirEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.xrayhelper-run-dir')" v-model="config.xrayHelper.runDir"/>
</van-popup>
<van-popup v-model:show="cpuLimitEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.xrayhelper-cpu-limit')" v-model.number="config.xrayHelper.cpuLimit"/>
</van-popup>
<van-popup v-model:show="memLimitEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.xrayhelper-mem-limit')" v-model.number="config.xrayHelper.memLimit"/>
</van-popup>
<van-popup v-model:show="proxyTagEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.xrayhelper-proxy-tag')" v-model="config.xrayHelper.proxyTag"/>
</van-popup>
<van-popup v-model:show="subListEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-cell :title="$t('setting.xrayhelper-sub-list')" title-style="max-width:100%;">
<template #right-icon>
<van-icon size="1.2rem" name="plus" @click="addSubList"/>
</template>
</van-cell>
<van-list>
<van-field v-for="(item, idx) in config.xrayHelper.subList" :label="idx+':'" labelWidth="1.5em" :model-value="item"
@update:model-value="v => editSubList(v, idx)">
<template #right-icon>
<van-icon size="1rem" name="cross" @click="deleteSubList(idx)"/>
</template>
</van-field>
</van-list>
</van-popup>
<van-popup v-model:show="userAgentEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.xrayhelper-user-agent')" v-model="config.xrayHelper.userAgent"/>
</van-popup>
<!-- popup: clash editors -->
<van-popup v-model:show="clashDnsPortEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.clash-dns-port')" v-model.number="config.clash.dnsPort"/>
</van-popup>
<van-popup v-model:show="clashTemplateEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.clash-template')" v-model="config.clash.template"/>
</van-popup>
<van-popup v-model:show="clashApiEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.panel-url')" v-model="config.clash.panelUrl"/>
</van-popup>
<!-- popup: adgHome editors -->
<van-popup v-model:show="adgHomeAddressEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.adghome-address')" v-model="config.adgHome.address"/>
</van-popup>
<van-popup v-model:show="adgHomeWorkDirEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.adghome-work-dir')" v-model="config.adgHome.workDir"/>
</van-popup>
<van-popup v-model:show="adgHomeDnsPortEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.adghome-dns-port')" v-model.number="config.adgHome.dnsPort"/>
</van-popup>
<!-- popup: proxy editors -->
<van-popup v-model:show="tproxyPortEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.proxy-tproxy-port')" v-model.number="config.proxy.tproxyPort"/>
</van-popup>
<van-popup v-model:show="socksPortEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.proxy-socks-port')" v-model.number="config.proxy.socksPort"/>
</van-popup>
<van-popup v-model:show="tunDeviceEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-field class="config" :label="$t('setting.proxy-tun-device')" v-model="config.proxy.tunDevice"/>
</van-popup>
<van-popup v-model:show="pkgListEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-cell :title="$t('setting.proxy-pkg-list')" title-style="max-width:100%;">
<template #right-icon>
<van-icon size="1.2rem" name="plus" @click="addPkgList"/>
</template>
</van-cell>
<van-list>
<van-field v-for="(item, idx) in config.proxy.pkgList" :label="idx+':'" labelWidth="1.5em" :model-value="item"
@update:model-value="v => editPkgList(v, idx)">
<template #right-icon>
<van-icon size="1rem" name="cross" @click="deletePkgList(idx)"/>
</template>
</van-field>
</van-list>
</van-popup>
<van-popup v-model:show="apListEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-cell :title="$t('setting.proxy-ap-list')" title-style="max-width:100%;">
<template #right-icon>
<van-icon size="1.2rem" name="plus" @click="addApList"/>
</template>
</van-cell>
<van-list>
<van-field v-for="(item, idx) in config.proxy.apList" :label="idx+':'" labelWidth="1.5em" :model-value="item"
@update:model-value="v => editApList(v, idx)">
<template #right-icon>
<van-icon size="1rem" name="cross" @click="deleteApList(idx)"/>
</template>
</van-field>
</van-list>
</van-popup>
<van-popup v-model:show="ignoreListEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-cell :title="$t('setting.proxy-ignore-list')" title-style="max-width:100%;">
<template #right-icon>
<van-icon size="1.2rem" name="plus" @click="addIgnoreList"/>
</template>
</van-cell>
<van-list>
<van-field v-for="(item, idx) in config.proxy.ignoreList" :label="idx+':'" labelWidth="1.5em" :model-value="item"
@update:model-value="v => editIgnoreList(v, idx)">
<template #right-icon>
<van-icon size="1rem" name="cross" @click="deleteIgnoreList(idx)"/>
</template>
</van-field>
</van-list>
</van-popup>
<van-popup v-model:show="intraListEditor" round :style="{ width: '90%' ,maxHeight:'85%'}" @closed="saveConfig">
<van-cell :title="$t('setting.proxy-intra-list')" title-style="max-width:100%;">
<template #right-icon>
<van-icon size="1.2rem" name="plus" @click="addIntraList"/>
</template>
</van-cell>
<van-list>
<van-field v-for="(item, idx) in config.proxy.intraList" :label="idx+':'" labelWidth="1.5em" :model-value="item"
@update:model-value="v => editIntraList(v, idx)">
<template #right-icon>
<van-icon size="1rem" name="cross" @click="deleteIntraList(idx)"/>
</template>
</van-field>
</van-list>
</van-popup>
<van-popup v-model:show="receiver" round :style="{ width: '90%' ,minHeight:'30%',maxHeight:'85%'}" >
<van-cell :title="$t('common.stdout')" title-style="max-width:100%;" size="large"/>
<div class="stdout"><p>{{ stdout }}</p></div>
</van-popup>
<!-- xrayhelper editors -->
<FieldEditor :label="$t('setting.xrayhelper-core-path')" tips="tips" v-model:show="corePathEditor" v-model:field="config.xrayHelper.corePath" @closed="saveConfig"/>
<FieldEditor :label="$t('setting.xrayhelper-core-config')" tips="tips" v-model:show="coreConfigEditor" v-model:field="config.xrayHelper.coreConfig" @closed="saveConfig"/>
<FieldEditor :label="$t('setting.xrayhelper-data-dir')" tips="tips" v-model:show="dataDirEditor" v-model:field="config.xrayHelper.dataDir" @closed="saveConfig"/>
<FieldEditor :label="$t('setting.xrayhelper-run-dir')" tips="tips" v-model:show="runDirEditor" v-model:field="config.xrayHelper.runDir" @closed="saveConfig"/>
<FieldEditor number :label="$t('setting.xrayhelper-cpu-limit')" tips="tips" v-model:show="cpuLimitEditor" v-model:field="config.xrayHelper.cpuLimit" @closed="saveConfig"/>
<FieldEditor number :label="$t('setting.xrayhelper-mem-limit')" tips="tips" v-model:show="memLimitEditor" v-model:field="config.xrayHelper.memLimit" @closed="saveConfig"/>
<FieldEditor :label="$t('setting.xrayhelper-proxy-tag')" tips="tips" v-model:show="proxyTagEditor" v-model:field="config.xrayHelper.proxyTag" @closed="saveConfig"/>
<ListEditor :title="$t('setting.xrayhelper-sub-list')" v-model:show="subListEditor" v-model:list="config.xrayHelper.subList" @closed="saveConfig"/>
<FieldEditor :label="$t('setting.xrayhelper-user-agent')" tips="tips" v-model:show="userAgentEditor" v-model:field="config.xrayHelper.userAgent" @closed="saveConfig"/>
<!-- clash editors -->
<FieldEditor number :label="$t('setting.clash-dns-port')" tips="tips" v-model:show="clashDnsPortEditor" v-model:field="config.clash.dnsPort" @closed="saveConfig"/>
<FieldEditor :label="$t('setting.clash-template')" tips="tips" v-model:show="clashTemplateEditor" v-model:field="config.clash.template" @closed="saveConfig"/>
<FieldEditor :label="$t('setting.panel-url')" tips="tips" v-model:show="clashApiEditor" v-model:field="config.clash.panelUrl" @closed="saveConfig"/>
<!-- adgHome editors -->
<FieldEditor :label="$t('setting.adghome-address')" tips="tips" v-model:show="adgHomeAddressEditor" v-model:field="config.adgHome.address" @closed="saveConfig"/>
<FieldEditor :label="$t('setting.adghome-work-dir')" tips="tips" v-model:show="adgHomeWorkDirEditor" v-model:field="config.adgHome.workDir" @closed="saveConfig"/>
<FieldEditor number :label="$t('setting.adghome-dns-port')" tips="tips" v-model:show="adgHomeDnsPortEditor" v-model:field="config.adgHome.dnsPort" @closed="saveConfig"/>
<!-- proxy editors -->
<FieldEditor number :label="$t('setting.proxy-tproxy-port')" tips="tips" v-model:show="tproxyPortEditor" v-model:field="config.proxy.tproxyPort" @closed="saveConfig"/>
<FieldEditor number :label="$t('setting.proxy-socks-port')" tips="tips" v-model:show="socksPortEditor" v-model:field="config.proxy.socksPort" @closed="saveConfig"/>
<FieldEditor :label="$t('setting.proxy-tun-device')" tips="tips" v-model:show="tunDeviceEditor" v-model:field="config.proxy.tunDevice" @closed="saveConfig"/>
<ListEditor :title="$t('setting.proxy-pkg-list')" v-model:show="pkgListEditor" v-model:list="config.proxy.pkgList" @closed="saveConfig"/>
<ListEditor :title="$t('setting.proxy-ap-list')" v-model:show="apListEditor" v-model:list="config.proxy.apList" @closed="saveConfig"/>
<ListEditor :title="$t('setting.proxy-ignore-list')" v-model:show="ignoreListEditor" v-model:list="config.proxy.ignoreList" @closed="saveConfig"/>
<ListEditor :title="$t('setting.proxy-intra-list')" v-model:show="intraListEditor" v-model:list="config.proxy.intraList" @closed="saveConfig"/>
<!-- stdout receiver -->
<StdoutReceiver v-model:show="receiver" v-model:stdout="stdout" @closed="() => this.stdout.value = ''"/>
</template>

<script setup>
import {ref} from 'vue'
import i18n from "./locales/i18n.js"
import YAML from "yaml"
import {callApi, readFile,execCmdWithExitCode,execXrayHelperCmd, saveFile, XRAYHELPER_CONFIG} from "./tools.js"
import ListEditor from "./components/ListEditor.vue";
import StdoutReceiver from "./components/StdoutReceiver.vue";
import FieldEditor from "./components/FieldEditor.vue";
defineProps(["theme"])
const loading = ref(false)
Expand Down Expand Up @@ -311,15 +208,6 @@ const changeAllowInsecure = (choose) => {
saveConfig()
}
const subListEditor = ref(false)
const editSubList = (value, index) => {
config.value.xrayHelper.subList[index] = value
}
const deleteSubList = (index) => {
config.value.xrayHelper.subList.splice(index, 1)
}
const addSubList = () => {
config.value.xrayHelper.subList.push('')
}
const userAgentEditor = ref(false)
// clash
const clashDnsPortEditor = ref(false)
Expand Down Expand Up @@ -381,45 +269,9 @@ const changeMode = (mode) => {
saveConfig()
}
const pkgListEditor = ref(false)
const editPkgList = (value, index) => {
config.value.proxy.pkgList[index] = value
}
const deletePkgList = (index) => {
config.value.proxy.pkgList.splice(index, 1)
}
const addPkgList = () => {
config.value.proxy.pkgList.push('')
}
const apListEditor = ref(false)
const editApList = (value, index) => {
config.value.proxy.apList[index] = value
}
const deleteApList = (index) => {
config.value.proxy.apList.splice(index, 1)
}
const addApList = () => {
config.value.proxy.apList.push('')
}
const ignoreListEditor = ref(false)
const editIgnoreList = (value, index) => {
config.value.proxy.ignoreList[index] = value
}
const deleteIgnoreList = (index) => {
config.value.proxy.ignoreList.splice(index, 1)
}
const addIgnoreList = () => {
config.value.proxy.ignoreList.push('')
}
const intraListEditor = ref(false)
const editIntraList = (value, index) => {
config.value.proxy.intraList[index] = value
}
const deleteIntraList = (index) => {
config.value.proxy.intraList.splice(index, 1)
}
const addIntraList = () => {
config.value.proxy.intraList.push('')
}
const config = ref()
Expand Down Expand Up @@ -524,9 +376,5 @@ const initConfig = () => {
}
initConfig()
</script>

<style>
.config {
--van-field-label-width: 7em;
}
</style>
Loading

0 comments on commit cddbf95

Please sign in to comment.