Skip to content

Commit

Permalink
Move initGlobalProxy and inject conn to App.vue
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihildt committed Dec 4, 2023
1 parent 0ddb9e3 commit 01f73c4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 42 deletions.
24 changes: 23 additions & 1 deletion src/popup/App.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
<script lang="ts" setup>
import { provide, watch } from 'vue';
import { useQueryProvider } from 'vue-query';
import { NConfigProvider, GlobalThemeOverrides, darkTheme } from 'naive-ui';
import Popup from '@/popup/Popup.vue';
useQueryProvider();
import useConnection, { ConnectionKey } from '@/composables/useConnection';
import useSocksProxy from '@/composables/useSocksProxy';
const { isLoading, connection, isError } = useConnection();
const { initGlobalProxy } = useSocksProxy();
provide(ConnectionKey, { connection, isLoading, isError });
watch(connection, async () => {
// Make sure the proxy always has some value
await initGlobalProxy(
{
hostname: connection.value.server,
country: connection.value.country,
city: connection.value.city,
},
connection.value.protocol!,
);
});
useQueryProvider();
const themeOverrides: GlobalThemeOverrides = {
common: {
cardColor: 'rgba(41, 77, 115, 0.5)',
Expand All @@ -26,6 +47,7 @@ const themeOverrides: GlobalThemeOverrides = {
},
};
</script>

<template>
<n-config-provider :theme-overrides="themeOverrides" :theme="darkTheme">
<Popup />
Expand Down
22 changes: 3 additions & 19 deletions src/popup/views/Home.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
<script lang="ts" setup>
import { provide, watch } from 'vue';
import { inject } from 'vue';
import NotificationsCarousel from '@/components/NotificationsCarousel.vue';
import ConnectionDetails from '@/components/ConnectionDetails/ConnectionDetails.vue';
import useConnection, { ConnectionKey } from '@/composables/useConnection';
import useSocksProxy from '@/composables/useSocksProxy';
import { ConnectionKey, defaultConnection } from '@/composables/useConnection';
const { isLoading, connection, isError } = useConnection();
const { initGlobalProxy } = useSocksProxy();
provide(ConnectionKey, { connection, isLoading, isError });
watch(connection, async () => {
// Make sure the proxy always has some value
await initGlobalProxy(
{
hostname: connection.value.server,
country: connection.value.country,
city: connection.value.city,
},
connection.value.protocol!,
);
});
const { isLoading } = inject(ConnectionKey) || defaultConnection;
</script>

<template>
Expand Down
26 changes: 4 additions & 22 deletions src/popup/views/Proxy.vue
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
<script lang="ts" setup>
import { computed, provide, watch } from 'vue';
import { inject } from 'vue';
import IconLabel from '@/components/IconLabel.vue';
import ProxyGlobal from '@/components/ProxyStatus/ProxyGlobal.vue';
import ProxyHost from '@/components/ProxyStatus/ProxyHost.vue';
import useConnection, { ConnectionKey } from '@/composables/useConnection';
import useSocksProxy from '@/composables/useSocksProxy';
const { isLoading, connection, isError } = useConnection();
const { initGlobalProxy } = useSocksProxy();
const connected = computed(() => connection.value.isMullvad);
provide(ConnectionKey, { connection, isLoading, isError });
watch(connection, async () => {
// Make sure the proxy always has some value
await initGlobalProxy(
{
hostname: connection.value.server,
country: connection.value.country,
city: connection.value.city,
},
connection.value.protocol!,
);
});
import { ConnectionKey, defaultConnection } from '@/composables/useConnection';
const { connection } = inject(ConnectionKey) || defaultConnection;
</script>

<template>
<div v-if="connected">
<div v-if="connection.isMullvad">
<ProxyGlobal />
<ProxyHost />
</div>
Expand Down

0 comments on commit 01f73c4

Please sign in to comment.