-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
154 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script lang="ts" setup> | ||
import { computed, inject } from 'vue'; | ||
import IconLabel from '@/components/IconLabel.vue'; | ||
import useActiveTab from '@/composables/useActiveTab'; | ||
import { ConnectionKey, defaultConnection } from '@/composables/useConnection'; | ||
import useSocksProxy from '@/composables/useSocksProxy'; | ||
import useStore from '@/composables/useStore'; | ||
const { activeTabHost, isAboutPage } = useActiveTab(); | ||
const { currentHostProxyDetails, currentHostProxyEnabled, globalProxyDetails, globalProxyEnabled } = | ||
useSocksProxy(); | ||
const { excludedHosts } = useStore(); | ||
const { connection } = inject(ConnectionKey, defaultConnection); | ||
const currentHostExcluded = computed(() => { | ||
return excludedHosts.value.includes(activeTabHost.value); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<IconLabel v-if="currentHostExcluded" type="info" class="my-2"> | ||
<strong>{{ activeTabHost }}</strong> is set to never be proxied | ||
</IconLabel> | ||
|
||
<IconLabel v-else-if="currentHostProxyEnabled && connection.isMullvad" type="info" class="my-2"> | ||
<strong>{{ activeTabHost }}</strong> is set to always be proxied through | ||
<strong>{{ currentHostProxyDetails.server }}</strong> | ||
</IconLabel> | ||
|
||
<IconLabel | ||
v-if="globalProxyEnabled && connection.isMullvad && !isAboutPage" | ||
type="info" | ||
class="my-2" | ||
> | ||
All websites are set to be proxied through | ||
<strong>{{ globalProxyDetails.server }}</strong> | ||
</IconLabel> | ||
|
||
<IconLabel v-if="currentHostProxyEnabled && !connection.isMullvad" type="warning" class="my-2"> | ||
<strong>{{ activeTabHost }}</strong> can't be reached, either disconnect its proxy or connect to | ||
Mullvad VPN. | ||
</IconLabel> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { getProxyPermissions } from '@/helpers/permissions'; | ||
import { updateCurrentTabProxyBadge, updateTabProxyBadge } from '@/helpers/proxyBadge'; | ||
import { getActiveProxyDetails, handleProxyRequest } from '@/helpers/socksProxy'; | ||
|
||
export const initProxyListeners = () => { | ||
// Will init listeners on extension start if permissions are granted | ||
initListeners(); | ||
|
||
// Will monitor permissions changes and update proxy accordingly | ||
browser.permissions.onAdded.addListener(initListeners); | ||
browser.permissions.onRemoved.addListener(cleanListeners); | ||
}; | ||
|
||
const initListeners = async () => { | ||
const proxyPermissionsGranted = await getProxyPermissions(); | ||
|
||
if (proxyPermissionsGranted) { | ||
updateCurrentTabProxyBadge(); | ||
|
||
// Initialize tab listeners | ||
browser.tabs.onActivated.addListener(handleActivedTab); | ||
browser.tabs.onUpdated.addListener(handleUpdatedTab); | ||
|
||
// Initialize proxy request listener | ||
browser.proxy.onRequest.addListener(handleProxyRequest, { urls: ['<all_urls>'] }); | ||
} | ||
}; | ||
|
||
const cleanListeners = async () => { | ||
const proxyPermissionsGranted = await getProxyPermissions(); | ||
|
||
if (!proxyPermissionsGranted) { | ||
// Clear the badge for all tabs | ||
// TODO Add a notification to warn the user the proxy has been deactivated | ||
const tabs = await browser.tabs.query({}); | ||
for (const tab of tabs) { | ||
if (tab.id !== undefined) { | ||
browser.browserAction.setBadgeText({ text: '', tabId: tab.id }); | ||
} | ||
} | ||
|
||
// Remove tab listeners | ||
browser.tabs.onActivated.removeListener(handleActivedTab); | ||
browser.tabs.onUpdated.removeListener(handleUpdatedTab); | ||
|
||
// Remove proxy request listener | ||
browser.proxy.onRequest.removeListener(handleProxyRequest); | ||
} | ||
}; | ||
|
||
const handleActivedTab = async (activeInfo: browser.tabs._OnActivatedActiveInfo) => { | ||
const tab = await browser.tabs.get(activeInfo.tabId); | ||
updateTabProxyBadge(tab, await getActiveProxyDetails()); | ||
}; | ||
|
||
const handleUpdatedTab = async ( | ||
_tabId: number, | ||
_changeInfo: browser.tabs._OnUpdatedChangeInfo, | ||
tab: browser.tabs.Tab, | ||
) => { | ||
updateTabProxyBadge(tab, await getActiveProxyDetails()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.