Skip to content

Commit

Permalink
after chaning the proxy config, refresh the proxy setting
Browse files Browse the repository at this point in the history
  • Loading branch information
SYM01 committed Oct 20, 2024
1 parent ba0b3b3 commit 513aa39
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/components/ProfileConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import { FieldRule, Notification } from "@arco-design/web-vue";
import { useRouter } from "vue-router";
import { Host, PacScript } from "@/adapters";
import { refreshProxy } from "@/services/proxy";
const router = useRouter();
const props = defineProps<{
Expand Down Expand Up @@ -131,7 +132,6 @@ const proxyServerFieldRule = (
type: "object",
required: required,
validator(value, callback) {
console.log(value);
if (value == undefined || value.scheme == "direct") {
return;
}
Expand Down Expand Up @@ -182,13 +182,17 @@ const saveProfileEvent = async () => {
content: Host.getMessage("config_feedback_saved"),
});
// need to overwrite the current proxy settings
await refreshProxy();
if (newProfileMode) {
router.replace({
name: "profile.custom",
params: { id: profileConfig.profileID },
});
return;
}
editing.value = false;
} catch (e: any) {
Notification.error({
Expand Down
21 changes: 21 additions & 0 deletions src/services/proxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ export async function setProxy(val: ProxyProfile) {
await Host.set<ProxyProfile>(keyActiveProfile, val);
}

/**
* Refresh the current proxy setting. This is useful when the proxy setting is changed by user.
* @returns
*/
export async function refreshProxy() {
const current = await getCurrentProxySetting();

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

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

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

export async function previewAutoSwitchPac(val: ProfileAuthSwitch) {
const profile = new ProfileConverter(val, getProfile);
return await profile.toPAC();
Expand Down
1 change: 0 additions & 1 deletion src/services/proxy/profile2config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export class ProfileConverter {
* @returns
*/
async toClosure() {
console.log("toClosure", this.profile.profileID);
const stmts = await this.genStatements();
stmts.push(
PACScriptHelper.newReturnStatement(
Expand Down

0 comments on commit 513aa39

Please sign in to comment.