aboutsummaryrefslogtreecommitdiff
path: root/extension/src/entries/store/features.ts
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-11-22 02:21:53 -0500
committerLibravatar vnugent <public@vaughnnugent.com>2023-11-22 02:21:53 -0500
commit2ba94602a87c87b47f566745bdab40ce75e0e879 (patch)
tree396cb9c6d73d6bfb4e4b2d4fb440d7656fe493e0 /extension/src/entries/store/features.ts
parent43429314c0989b423e116be3e9f222eba5b636c3 (diff)
latest patches, remove webext-bridge, lastest vnlib.browser
Diffstat (limited to 'extension/src/entries/store/features.ts')
-rw-r--r--extension/src/entries/store/features.ts50
1 files changed, 5 insertions, 45 deletions
diff --git a/extension/src/entries/store/features.ts b/extension/src/entries/store/features.ts
index 9bf3052..219386f 100644
--- a/extension/src/entries/store/features.ts
+++ b/extension/src/entries/store/features.ts
@@ -2,10 +2,8 @@
import 'pinia'
import { } from 'lodash'
import { PiniaPluginContext } from 'pinia'
-import { type Tabs, tabs } from 'webextension-polyfill'
import {
- SendMessageHandler,
useAuthApi,
useHistoryApi,
useIdentityApi,
@@ -18,9 +16,8 @@ import {
useInjectAllowList
} from "../../features"
-import { RuntimeContext, createPort } from '../../webext-bridge'
-import { ref } from 'vue'
import { onWatchableChange } from '../../features/types'
+import { ChannelContext } from '../../messaging'
export type BgPlugins = ReturnType<typeof usePlugins>
export type BgPluginState<T> = { plugins: BgPlugins } & T
@@ -28,13 +25,12 @@ export type BgPluginState<T> = { plugins: BgPlugins } & T
declare module 'pinia' {
export interface PiniaCustomProperties {
plugins: BgPlugins
- currentTab: Tabs.Tab | undefined
}
}
-const usePlugins = (sendMessage: SendMessageHandler) => {
+const usePlugins = (context: ChannelContext) => {
//Create plugin wrapping function
- const { use } = useForegoundFeatures(sendMessage)
+ const { use } = useForegoundFeatures(context)
return {
settings: use(useSettingsApi),
@@ -49,14 +45,11 @@ const usePlugins = (sendMessage: SendMessageHandler) => {
}
}
-export const useBackgroundPiniaPlugin = (context: RuntimeContext) => {
+export const useBackgroundPiniaPlugin = (context: ChannelContext) => {
//Create port for context
- const { sendMessage } = createPort(context)
- const plugins = usePlugins(sendMessage)
+ const plugins = usePlugins(context)
const { user } = plugins;
- const currentTab = ref<Tabs.Tab | undefined>(undefined)
-
//Plugin store
return ({ store }: PiniaPluginContext) => {
@@ -71,46 +64,13 @@ export const useBackgroundPiniaPlugin = (context: RuntimeContext) => {
//Wait for settings changes
onWatchableChange(plugins.settings, async () => {
-
//Update settings and dark mode on change
store.settings = await plugins.settings.getSiteConfig();
store.darkMode = await plugins.settings.getDarkMode();
- console.log("Settings changed")
}, { immediate: true })
-
-
- const initTab = async () => {
-
- if(!tabs){
- return;
- }
-
- //Get the current tab
- const [active] = await tabs.query({ active: true, currentWindow: true })
- currentTab.value = active
-
- //Watch for changes to the current tab
- tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
- //If the url changed, update the current tab
- if (changeInfo.url) {
- currentTab.value = tab
- }
- })
-
- tabs.onActivated.addListener(async ({ tabId }) => {
- //Get the tab
- const tab = await tabs.get(tabId)
- //Update the current tab
- currentTab.value = tab
- })
- }
-
-
- initTab()
return{
plugins,
- currentTab,
}
}
} \ No newline at end of file