diff --git a/package.json b/package.json
index 2397d2e..5e8e7db 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "proxyverse",
"private": true,
- "version": "0.9.0",
+ "version": "0.9.1",
"type": "module",
"scripts": {
"dev": "vite",
diff --git a/src/background.ts b/src/background.ts
index 28de2d3..8478255 100644
--- a/src/background.ts
+++ b/src/background.ts
@@ -10,4 +10,5 @@ async function initIndicator() {
}
-initIndicator().catch(console.error)
\ No newline at end of file
+initIndicator().catch(console.error)
+chrome.proxy.onProxyError.addListener(console.warn)
\ No newline at end of file
diff --git a/src/components/ProfileConfig.vue b/src/components/ProfileConfig.vue
index 2002237..0da63cd 100644
--- a/src/components/ProfileConfig.vue
+++ b/src/components/ProfileConfig.vue
@@ -151,7 +151,7 @@ const loadProfile = async (profileID: string) => {
profileFirstLoaded = true
Object.assign(profileConfig, profile)
- if (profileConfig.proxyRules.ftp || profileConfig.proxyRules.http || profileConfig.proxyRules.https) {
+ if (profileConfig.proxyType == 'proxy' && (profileConfig.proxyRules.ftp || profileConfig.proxyRules.http || profileConfig.proxyRules.https)) {
showAdvanceConfig.value = true
}
}
@@ -168,7 +168,7 @@ onMounted(() => {
{{
profileConfig.profileName
- }}
+ }}
diff --git a/src/models/indicator.ts b/src/models/indicator.ts
index 04cdd26..6a3828b 100644
--- a/src/models/indicator.ts
+++ b/src/models/indicator.ts
@@ -1,18 +1,22 @@
+import { SystemProfile } from "./profile";
import { ProxySetting } from "./proxy";
export async function setIndicator(proxy: ProxySetting) {
const curMode = proxy.setting.value?.mode
+ let profile = proxy.activeProfile
+ // overide profile
switch (curMode) {
case 'system':
- return await setBadge('', '#000000')
-
+ profile = SystemProfile.SYSTEM
+ break
case 'direct':
- return await setBadge('DIRECT', '#7ad39e')
+ profile = SystemProfile.DIRECT
+ break
}
- if (proxy.activeProfile) {
- await setBadge(proxy.activeProfile.profileName, proxy.activeProfile.color)
+ if (profile) {
+ await setBadge(profile.profileName, profile.color)
}
}
diff --git a/src/models/profile.ts b/src/models/profile.ts
index 7cd8b33..45b6078 100644
--- a/src/models/profile.ts
+++ b/src/models/profile.ts
@@ -9,7 +9,13 @@ export type ProxyServer = (chrome.proxy.ProxyServer & {
scheme: 'direct' | 'http' | 'https' | 'socks4' | 'socks5'
})
-type ProxyConfigSimple = {
+type ProxyConfigMeta = {
+ profileID: string,
+ color: string,
+ profileName: string,
+}
+
+export type ProxyConfigSimple = ProxyConfigMeta & {
proxyType: 'proxy' | 'pac',
proxyRules: {
default: ProxyServer,
@@ -21,12 +27,27 @@ type ProxyConfigSimple = {
pacScript: chrome.proxy.PacScript
}
-export type ProfileConfig = {
- profileID: string,
- color: string,
- profileName: string,
+export type ProxyConfigPreset = ProxyConfigMeta & {
+ proxyType: 'system' | 'direct'
+}
+
+export type ProfileConfig = ProxyConfigSimple | ProxyConfigPreset
+
-} & (ProxyConfigSimple)
+export const SystemProfile: Record = {
+ DIRECT: {
+ profileID: '367DEDBC-6750-4454-8321-4E4B088E20B1',
+ color: '#7ad39e',
+ profileName: 'DIRECT',
+ proxyType: 'direct'
+ },
+ SYSTEM: {
+ profileID: '4FDEF36F-F389-4AF3-9BBC-B2E01B3B09E6',
+ color: '#0000',
+ profileName: '', // no name needed for `system`
+ proxyType: 'system'
+ },
+}
const keyProfileStorage = 'profiles'
diff --git a/src/models/proxy/index.ts b/src/models/proxy/index.ts
index 7065e1e..637c226 100644
--- a/src/models/proxy/index.ts
+++ b/src/models/proxy/index.ts
@@ -1,8 +1,6 @@
-import { ProfileConfig } from "../profile"
+import { ProfileConfig, SystemProfile } from "../profile"
import { get, set } from "../store"
-import { SimpleProxyValue, genSimpleProxyCfg } from "./proxyRules"
-
-export type ProxyValue = SimpleProxyValue
+import { genSimpleProxyCfg } from "./proxyRules"
export type ProxySetting = {
activeProfile?: ProfileConfig
@@ -20,6 +18,15 @@ async function wrapProxySetting(setting: chrome.types.ChromeSettingGetResultDeta
ret.activeProfile = await get(keyActiveProfile) || undefined
}
+ switch (setting.value?.mode) {
+ case 'system':
+ ret.activeProfile = SystemProfile.SYSTEM
+ break
+ case 'direct':
+ ret.activeProfile = SystemProfile.DIRECT
+ break
+ }
+
return ret
}
@@ -35,30 +42,30 @@ export function onCurrentProxySettingChanged(cb: (setting: ProxySetting) => void
})
}
-export async function setProxy(val: ProxyValue) {
- switch (val) {
+export async function setProxy(val: ProfileConfig) {
+ switch (val.proxyType) {
case 'system':
- case 'direct':
- await defaultSetProxy(genSimpleProxyCfg(val), val)
- return
- }
+ await defaultClearProxy()
+ break
- switch (val.proxyType) {
+ case 'direct':
case 'proxy':
case 'pac':
- await defaultSetProxy(genSimpleProxyCfg(val), val)
- return
+ await defaultSetProxy(genSimpleProxyCfg(val))
+ break
}
+
+ await set(keyActiveProfile, val)
}
-async function defaultSetProxy(cfg: chrome.proxy.ProxyConfig, meta: ProxyValue) {
+async function defaultSetProxy(cfg: chrome.proxy.ProxyConfig) {
await chrome.proxy.settings.set({
value: cfg,
scope: "regular",
})
+}
- if (typeof meta != 'string' && meta.profileID) {
- await set(keyActiveProfile, meta)
- }
+async function defaultClearProxy() {
+ await chrome.proxy.settings.clear({ scope: 'regular' })
}
diff --git a/src/models/proxy/proxyRules.ts b/src/models/proxy/proxyRules.ts
index 4aefb84..11f4238 100644
--- a/src/models/proxy/proxyRules.ts
+++ b/src/models/proxy/proxyRules.ts
@@ -1,29 +1,27 @@
import { generate as generateJS } from 'escodegen'
import { Program, FunctionDeclaration, Identifier, Statement, Literal, ReturnStatement, Expression, IfStatement, CallExpression, MemberExpression } from 'estree'
import { IPv4, IPv6, isValidCIDR, parseCIDR } from "ipaddr.js";
-import { ProfileConfig, ProxyServer } from "../profile";
+import { ProxyConfigPreset, ProxyConfigSimple, ProxyServer } from "../profile";
-export type SimpleProxyValue = ProfileConfig | 'direct' | 'system'
-export function genSimpleProxyCfg(val: SimpleProxyValue): chrome.proxy.ProxyConfig {
- switch (val) {
+export function genSimpleProxyCfg(val: ProxyConfigSimple | ProxyConfigPreset): chrome.proxy.ProxyConfig {
+ switch (val.proxyType) {
case 'direct':
case 'system':
- return { mode: val }
- }
+ return { mode: val.proxyType }
+
+ case 'pac':
+ return {
+ mode: 'pac_script',
+ pacScript: val.pacScript
+ }
- switch (val.proxyType) {
case 'proxy':
if (containsDirectRules(val)) {
// @ts-ignore
return genComplexRuleForProfile(val)
}
return genFixServerRuleForProfile(val)
- case 'pac':
- return {
- mode: 'pac_script',
- pacScript: val.pacScript
- }
}
// this case should never be happen
@@ -33,7 +31,7 @@ export function genSimpleProxyCfg(val: SimpleProxyValue): chrome.proxy.ProxyConf
-function genFixServerRuleForProfile(val: ProfileConfig): chrome.proxy.ProxyConfig {
+function genFixServerRuleForProfile(val: ProxyConfigSimple): chrome.proxy.ProxyConfig {
const rules = val.proxyRules
const ret: chrome.proxy.ProxyConfig & { rules: chrome.proxy.ProxyRules } = {
mode: "fixed_servers",
@@ -57,7 +55,7 @@ function genFixServerRuleForProfile(val: ProfileConfig): chrome.proxy.ProxyConfi
return ret
}
-function containsDirectRules(val: ProfileConfig): boolean {
+function containsDirectRules(val: ProxyConfigSimple): boolean {
return [
val.proxyRules.default.scheme,
val.proxyRules.ftp?.scheme,
@@ -66,7 +64,7 @@ function containsDirectRules(val: ProfileConfig): boolean {
].includes("direct")
}
-function allDirectRules(val: ProfileConfig): boolean {
+function allDirectRules(val: ProxyConfigSimple): boolean {
return [
val.proxyRules.default.scheme,
val.proxyRules.ftp?.scheme,
@@ -76,7 +74,7 @@ function allDirectRules(val: ProfileConfig): boolean {
}
-function genComplexRuleForProfile(val: ProfileConfig & { proxyType: 'proxy' }): chrome.proxy.ProxyConfig {
+function genComplexRuleForProfile(val: ProxyConfigSimple & { proxyType: 'proxy' }): chrome.proxy.ProxyConfig {
if (allDirectRules(val)) {
return {
mode: 'direct'
@@ -92,7 +90,7 @@ function genComplexRuleForProfile(val: ProfileConfig & { proxyType: 'proxy' }):
}
-class SimplePacScriptForProfile {
+class SimplePacScriptForProfile {
private newIdentifier(name: string): Identifier {
return {
type: "Identifier",
diff --git a/src/pages/PopupPage.vue b/src/pages/PopupPage.vue
index dbb332c..a706b83 100644
--- a/src/pages/PopupPage.vue
+++ b/src/pages/PopupPage.vue
@@ -1,9 +1,9 @@