Skip to content

Commit

Permalink
Bugfix: fix 2 UX issues (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
SYM01 authored Oct 20, 2024
1 parent f648824 commit b85a74c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
10 changes: 3 additions & 7 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ import {
WebResponseDetails,
} from "./adapters";
import { setIndicator } from "./services/indicator";
import {
getAuthInfos,
getCurrentProxySetting,
onCurrentProxySettingChanged,
} from "./services/proxy";
import { getAuthInfos, getCurrentProxySetting } from "./services/proxy";

// indicator
async function initIndicator() {
await setIndicator(await getCurrentProxySetting());
onCurrentProxySettingChanged(async (proxy) => {
await setIndicator(proxy);
Host.onProxyChanged(async () => {
await setIndicator(await getCurrentProxySetting());
});
}

Expand Down
16 changes: 4 additions & 12 deletions src/services/proxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ export async function getCurrentProxySetting() {
return await wrapProxySetting(setting);
}

export function onCurrentProxySettingChanged(
cb: (setting: ProxySetting) => void
) {
Host.onProxyChanged(async (setting) => {
const ret = await wrapProxySetting(setting);
cb(ret);
});
}

export async function setProxy(val: ProxyProfile) {
switch (val.proxyType) {
case "system":
Expand All @@ -73,18 +64,19 @@ export async function setProxy(val: ProxyProfile) {
*/
export async function refreshProxy() {
const current = await getCurrentProxySetting();

// if it's not controlled by this extension, then do nothing
if (!current.activeProfile) {
return;
}

const newProfile = await getProfile(current.activeProfile.profileID);

// if it's preset profiles, then do nothing
if (current.activeProfile.proxyType in ["system", "direct"]) {
if (!newProfile || current.activeProfile.proxyType in ["system", "direct"]) {
return;
}

const profile = new ProfileConverter(current.activeProfile, getProfile);
const profile = new ProfileConverter(newProfile, getProfile);
await Host.setProxy(await profile.toProxyConfig());
}

Expand Down

0 comments on commit b85a74c

Please sign in to comment.