Skip to content

Commit

Permalink
Remove pre-population of default proxies to stop unintentional history
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihildt committed Feb 15, 2024
1 parent 5985d0b commit 28cc72d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/components/ProxyStatus/ProxyButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ const { toggleLocations } = useLocations();
</script>

<template>
<Button @click="toggleLocations"> Switch location </Button>
<Button @click="toggleLocations"> Select location </Button>
</template>
6 changes: 3 additions & 3 deletions src/components/ProxyStatus/ProxyGlobal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import useLocations from '@/composables/useLocations';
const { globalProxyDetails, globalProxyEnabled, toggleGlobalProxy } = useSocksProxy();
const { hostProxySelect } = useLocations();
const status = computed(() => (globalProxyEnabled.value ? 'enabled' : 'disabled'));
const status = computed(() => (globalProxyEnabled.value ? 'Enabled' : 'Disabled'));
const handleSetGlobalProxy = () => {
hostProxySelect.value = false;
Expand All @@ -24,15 +24,15 @@ const handleSetGlobalProxy = () => {
<n-card :bordered="false" class="mb-4">
<div class="flex justify-between">
<TitleCategory title="Proxy for all websites" />
<n-tooltip>
<n-tooltip v-if="globalProxyDetails.server">
<template #trigger>
<n-switch :value="globalProxyEnabled" @update-value="handleSetGlobalProxy" />
</template>
<span> {{ status }}</span>
</n-tooltip>
</div>

<CurrentProxyDetails :proxy-details="globalProxyDetails" />
<CurrentProxyDetails v-if="globalProxyDetails.server" :proxy-details="globalProxyDetails" />
<ProxyButton />
</n-card>
</template>
4 changes: 2 additions & 2 deletions src/components/ProxyStatus/ProxyHost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const handleHostProxySelect = () => {
<n-card :bordered="false" class="mb-4">
<div class="flex justify-between">
<TitleCategory :title="title" />
<n-tooltip v-if="!currentHostExcluded">
<n-tooltip v-if="currentHostProxyDetails && !currentHostExcluded">
<template #trigger>
<n-switch :value="currentHostProxyEnabled" @update-value="toggleCurrentHostProxy" />
</template>
Expand All @@ -64,7 +64,7 @@ const handleHostProxySelect = () => {

<n-button-group v-else>
<Button class="flex items-center justify-center" @click="handleHostProxySelect">
Switch location
Select location
</Button>

<Button color="error" class="flex items-center justify-center" @click="neverProxyHost">
Expand Down
36 changes: 0 additions & 36 deletions src/composables/useSocksProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,41 +49,6 @@ const toggleCurrentHostProxy = () => {
};
};

const createDefaultProxy = () => {
return {
host: socksIp,
port: baseConfig.port!,
proxyDNS: baseConfig.proxyDNS,
type: ProxyInfoType.socks,
};
};

const initProxies = async ({
hostname,
country,
countryCode,
city,
}: Partial<ProxyOperationArgs>) => {
const newProxyDetails = {
city,
country,
countryCode,
proxyDNS: baseConfig.proxyDNS,
server: hostname,
socksEnabled: false,
};

if (Object.keys(globalProxy.value).length !== 4) {
globalProxy.value = createDefaultProxy();
globalProxyDetails.value = newProxyDetails;
}

if (!hostProxiesDetails.value[activeTabHost.value]) {
hostProxies.value[activeTabHost.value] = createDefaultProxy();
hostProxiesDetails.value[activeTabHost.value] = newProxyDetails;
}
};

const setGlobalProxy = ({
country,
countryCode,
Expand Down Expand Up @@ -151,7 +116,6 @@ const useSocksProxy = () => {
currentHostProxyEnabled,
globalProxyDetails,
globalProxyEnabled,
initProxies,
setCurrentHostProxy,
setGlobalProxy,
toggleCurrentHostProxy,
Expand Down
4 changes: 2 additions & 2 deletions src/composables/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type Store = {
hostProxies: Ref<ProxyInfoMap>;
hostProxiesDetails: Ref<ProxyDetailsMap>;
globalProxy: Ref<ProxyInfo>;
globalProxyDetails: Ref<ProxyDetails>; // TODO make sure it always come from the socks-proxies server info
globalProxyDetails: Ref<ProxyDetails>;
historyEntries: Ref<HistoryEntriesMap>;
mullvadAccount: Ref<string>;
proxiesList: Ref<Country[]>;
Expand All @@ -21,7 +21,7 @@ export type Store = {
const useStore = (): Store => {
const excludedHosts = useBrowserStorageLocal('excludedHosts', []);
const globalProxy = useBrowserStorageLocal('globalProxy', {} as ProxyInfo);
const globalProxyDetails = useBrowserStorageLocal('globalProxyDetails', { socksEnabled: false });
const globalProxyDetails = useBrowserStorageLocal('globalProxyDetails', {} as ProxyDetails);
const hostProxies = useBrowserStorageLocal('hostProxies', {});
const hostProxiesDetails = useBrowserStorageLocal('hostProxiesDetails', {});
const historyEntries = useBrowserStorageLocal('historyEntries', {});
Expand Down
14 changes: 2 additions & 12 deletions src/popup/views/Home.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { computed, inject, watch } from 'vue';
import { computed, inject } from 'vue';
import ConnectionDetails from '@/components/ConnectionDetails/ConnectionDetails.vue';
import IconLabel from '@/components/IconLabel.vue';
Expand All @@ -11,21 +11,11 @@ import useSocksProxy from '@/composables/useSocksProxy';
import useStore from '@/composables/useStore';
const { activeTabHost } = useActiveTab();
const { currentHostProxyDetails, currentHostProxyEnabled, initProxies } = useSocksProxy();
const { currentHostProxyDetails, currentHostProxyEnabled } = useSocksProxy();
const { excludedHosts } = useStore();
const { isLoading, isError, connection } = inject(ConnectionKey, defaultConnection);
const currentHostExcluded = computed(() => excludedHosts.value.includes(activeTabHost.value));
watch(connection, async () => {
// Make sure the proxies always have some value on popup start
await initProxies({
hostname: connection.value.server,
country: connection.value.country,
countryCode: connection.value.server?.slice(0, 2),
city: connection.value.city,
});
});
</script>

<template>
Expand Down

0 comments on commit 28cc72d

Please sign in to comment.