mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
fix(gui): guard runtime errors and follow the active locale in more places
- Latency test: a network error left the selected rows on "testing..." forever; reset them in .catch. - Relative times only knew zh and en from localStorage; use the vue-i18n locale and load the dayjs locales for fa, ru, pt and ko. - i18n: an unknown stored _lang silently fell back to English; ignore it and detect from the browser. Set <html lang> to the chosen locale. - networkInspect polled err.response.status on plain network errors (TypeError every 3 s); the GFW list update spinner never closed on a rejected request; the routing dialog threw in render when a saved rule named a .dat file that no longer exists. - axios: the "https frontend talking to http backend" branch fired for every error on HTTPS deployments because parseURL fabricates http:// for a relative apiRoot; require an absolute http:// backend URL, and do not dereference the parsed URL when err.config is absent. - The status tag is focusable and announced as a button but only reacted to clicks; Enter and Space now activate it.
This commit is contained in:
8 files changed
+36
-19
No files matched your search
+2
-1
@@ -8,7 +8,8 @@
|
||||
<b-navbar-item tag="div">
|
||||
<b-tag id="statusTag" class="pointerTag" role="button" tabindex="0" :type="statusMap[runningState.running]"
|
||||
@mouseenter.native="handleOnStatusMouseEnter" @mouseleave.native="handleOnStatusMouseLeave"
|
||||
@click.native="handleClickStatus">{{ coverStatusText ? coverStatusText : runningState.running }}
|
||||
@click.native="handleClickStatus" @keydown.native.enter.prevent="handleClickStatus"
|
||||
@keydown.native.space.prevent="handleClickStatus">{{ coverStatusText ? coverStatusText : runningState.running }}
|
||||
</b-tag>
|
||||
</b-navbar-item>
|
||||
<b-navbar-item tag="div">
|
||||
|
||||
@@ -36,7 +36,7 @@ function waitingConnected(promise, interval, cancel, timeout) {
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.response.status === 401) {
|
||||
if (err && err.response && err.response.status === 401) {
|
||||
clearInterval(timer);
|
||||
cancel && cancel();
|
||||
}
|
||||
|
||||
@@ -104,16 +104,12 @@
|
||||
<b-select
|
||||
v-model="rule.tags"
|
||||
multiple
|
||||
:native-size="
|
||||
siteDatFiles[rule.filename].tags.length > 16
|
||||
? 16
|
||||
: siteDatFiles[rule.filename].tags.length
|
||||
"
|
||||
:native-size="Math.min(16, tagsOf(rule.filename).length)"
|
||||
size="is-small"
|
||||
expanded
|
||||
>
|
||||
<option
|
||||
v-for="tag of siteDatFiles[rule.filename].tags"
|
||||
v-for="tag of tagsOf(rule.filename)"
|
||||
:key="tag"
|
||||
:value="tag"
|
||||
>
|
||||
@@ -242,6 +238,11 @@ export default {
|
||||
})();
|
||||
},
|
||||
methods: {
|
||||
tagsOf(filename) {
|
||||
// a saved rule may name a .dat file that no longer exists
|
||||
const f = this.siteDatFiles[filename];
|
||||
return f && f.tags ? f.tags : [];
|
||||
},
|
||||
handleNew() {
|
||||
this.customPac.routingRules.push({
|
||||
filename: this.firstSiteDatFilename,
|
||||
|
||||
@@ -102,6 +102,8 @@ export default {
|
||||
queue: false,
|
||||
});
|
||||
});
|
||||
}).catch(() => {
|
||||
loading.close();
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
+10
-7
@@ -774,6 +774,10 @@ import ModalPickProxyGroup from "@/components/modalPickProxyGroup";
|
||||
import { waitingConnected } from "@/assets/js/networkInspect";
|
||||
import axios from "@/plugins/axios";
|
||||
import dayjs from "dayjs";
|
||||
import i18n from "@/plugins/i18n";
|
||||
|
||||
// vue-i18n locale -> dayjs locale (all loaded in plugins/dayjs.js)
|
||||
const DAYJS_LOCALES = { zh: "zh-cn", en: "en", fa: "fa", ru: "ru", pt: "pt-br", ko: "ko" };
|
||||
|
||||
export default {
|
||||
name: "Node",
|
||||
@@ -781,13 +785,7 @@ export default {
|
||||
filters: {
|
||||
unix2datetime(x) {
|
||||
x = dayjs.unix(x);
|
||||
let now = dayjs();
|
||||
if (localStorage["_lang"] === "zh") {
|
||||
now = now.locale("zh-cn");
|
||||
} else if (localStorage["_lang"] === "en") {
|
||||
now = now.locale("en");
|
||||
}
|
||||
return now.to(x);
|
||||
return dayjs().locale(DAYJS_LOCALES[i18n.locale] || "en").to(x);
|
||||
},
|
||||
},
|
||||
props: {
|
||||
@@ -1771,6 +1769,11 @@ export default {
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch(() => {
|
||||
// network error: the interceptor already reported it; do not
|
||||
// leave the rows on "testing..."
|
||||
this.checkedRows.forEach((x) => (x.pingLatency = ""));
|
||||
})
|
||||
.finally(() => {
|
||||
clearTimeout(timerTip);
|
||||
});
|
||||
|
||||
@@ -143,8 +143,12 @@ axios.interceptors.response.use(
|
||||
}
|
||||
return Promise.reject(err);
|
||||
} else if (
|
||||
u &&
|
||||
location.protocol.substr(0, 5) === "https" &&
|
||||
u.protocol === "http"
|
||||
u.protocol === "http" &&
|
||||
// parseURL fabricates http:// for a relative apiRoot; only an absolute
|
||||
// http:// backend address is the mixed-content case
|
||||
/^http:\/\//i.test(err.config.url)
|
||||
) {
|
||||
// https frontend communicating with http backend
|
||||
let msg = i18n.t("axios.messages.cannotCommunicate.0");
|
||||
@@ -187,8 +191,9 @@ axios.interceptors.response.use(
|
||||
},
|
||||
});
|
||||
} else if (
|
||||
(err.message && err.message === "Network Error") ||
|
||||
(err.config && err.config.url === "/api/version")
|
||||
u &&
|
||||
((err.message && err.message === "Network Error") ||
|
||||
(err.config && err.config.url === "/api/version"))
|
||||
) {
|
||||
informNotRunning(u.source.replace(u.relative, ""));
|
||||
} else {
|
||||
|
||||
@@ -7,6 +7,10 @@ import utc from "dayjs/plugin/utc";
|
||||
import Vue from "vue";
|
||||
import "dayjs/locale/zh-cn";
|
||||
import "dayjs/locale/en";
|
||||
import "dayjs/locale/fa";
|
||||
import "dayjs/locale/ru";
|
||||
import "dayjs/locale/pt-br";
|
||||
import "dayjs/locale/ko";
|
||||
|
||||
dayjs.extend(relativeTime);
|
||||
dayjs.extend(utc);
|
||||
|
||||
@@ -9,7 +9,7 @@ Vue.use(VueI18n);
|
||||
// Create VueI18n instance with options
|
||||
let locale = "en";
|
||||
let _lang = localStorage["_lang"];
|
||||
if (_lang) {
|
||||
if (_lang && _lang in messages) {
|
||||
locale = _lang;
|
||||
} else {
|
||||
for (let l of window.navigator.languages) {
|
||||
@@ -26,5 +26,6 @@ const i18n = new VueI18n({
|
||||
messages,
|
||||
fallbackLocale: "en",
|
||||
});
|
||||
document.documentElement.lang = locale;
|
||||
|
||||
export default i18n;
|
||||
Reference in new issue
Block a user