Skip to content

Commit b85a74c

Browse files
authored
Bugfix: fix 2 UX issues (#17)
1 parent f648824 commit b85a74c

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

src/background.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@ import {
55
WebResponseDetails,
66
} from "./adapters";
77
import { setIndicator } from "./services/indicator";
8-
import {
9-
getAuthInfos,
10-
getCurrentProxySetting,
11-
onCurrentProxySettingChanged,
12-
} from "./services/proxy";
8+
import { getAuthInfos, getCurrentProxySetting } from "./services/proxy";
139

1410
// indicator
1511
async function initIndicator() {
1612
await setIndicator(await getCurrentProxySetting());
17-
onCurrentProxySettingChanged(async (proxy) => {
18-
await setIndicator(proxy);
13+
Host.onProxyChanged(async () => {
14+
await setIndicator(await getCurrentProxySetting());
1915
});
2016
}
2117

src/services/proxy/index.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ export async function getCurrentProxySetting() {
4343
return await wrapProxySetting(setting);
4444
}
4545

46-
export function onCurrentProxySettingChanged(
47-
cb: (setting: ProxySetting) => void
48-
) {
49-
Host.onProxyChanged(async (setting) => {
50-
const ret = await wrapProxySetting(setting);
51-
cb(ret);
52-
});
53-
}
54-
5546
export async function setProxy(val: ProxyProfile) {
5647
switch (val.proxyType) {
5748
case "system":
@@ -73,18 +64,19 @@ export async function setProxy(val: ProxyProfile) {
7364
*/
7465
export async function refreshProxy() {
7566
const current = await getCurrentProxySetting();
76-
7767
// if it's not controlled by this extension, then do nothing
7868
if (!current.activeProfile) {
7969
return;
8070
}
8171

72+
const newProfile = await getProfile(current.activeProfile.profileID);
73+
8274
// if it's preset profiles, then do nothing
83-
if (current.activeProfile.proxyType in ["system", "direct"]) {
75+
if (!newProfile || current.activeProfile.proxyType in ["system", "direct"]) {
8476
return;
8577
}
8678

87-
const profile = new ProfileConverter(current.activeProfile, getProfile);
79+
const profile = new ProfileConverter(newProfile, getProfile);
8880
await Host.setProxy(await profile.toProxyConfig());
8981
}
9082

0 commit comments

Comments
 (0)