Skip to content

Commit 98ed63e

Browse files
committed
chore(deps): clean up imports and use shared lib
1 parent ebce3bb commit 98ed63e

File tree

9 files changed

+24
-28
lines changed

9 files changed

+24
-28
lines changed

src/components/common/navbar/NavbarSettingsDopdown.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<script setup lang="ts">
2+
import { chromeRuntimeId } from '@dvcol/web-extension-utils/chrome/runtime';
3+
4+
import { createTab } from '@dvcol/web-extension-utils/chrome/tabs';
25
import { NAvatar, NDropdown, NEllipsis, NFlex, NIcon } from 'naive-ui';
36
47
import { computed, defineProps, h, ref } from 'vue';
@@ -24,7 +27,6 @@ import { logger } from '~/stores/settings/log.store';
2427
import { useLogout } from '~/stores/settings/use-logout';
2528
import { defaultUser, useUserSettingsStoreRefs } from '~/stores/settings/user.store';
2629
27-
import { chromeRuntimeId, createTab } from '~/utils/browser/browser.utils';
2830
import { useI18n } from '~/utils/i18n.utils';
2931
3032
const i18n = useI18n('navbar', 'settings');

src/components/views/settings/SettingsAccount.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts" setup>
2+
import { chromeRuntimeId } from '@dvcol/web-extension-utils/chrome/runtime';
23
import { NAvatar, NButton, NCard, NFlex, NIcon } from 'naive-ui';
34
45
import { computed, ref } from 'vue';
@@ -14,7 +15,7 @@ import { useLinksStore } from '~/stores/settings/links.store';
1415
import { logger } from '~/stores/settings/log.store';
1516
import { useLogout } from '~/stores/settings/use-logout';
1617
import { useUserSettingsStoreRefs } from '~/stores/settings/user.store';
17-
import { chromeRuntimeId } from '~/utils/browser/browser.utils';
18+
1819
import { useI18n } from '~/utils/i18n.utils';
1920
2021
const i18n = useI18n('settings', 'account');

src/components/views/settings/SettingsMenus.vue

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts" setup>
2+
import { chromeRuntimeId } from '@dvcol/web-extension-utils/chrome/runtime';
23
import { NSwitch } from 'naive-ui';
34
45
import SettingsFormItem from '~/components/views/settings/SettingsFormItem.vue';
@@ -22,7 +23,12 @@ const { toggleContextMenu } = useContextMenuStore();
2223
:key="id"
2324
:label="i18n(`label_menu__${ id }`)"
2425
>
25-
<NSwitch :value="state" class="form-switch" @update:value="toggleContextMenu(id)">
26+
<NSwitch
27+
:value="state"
28+
:disabled="!chromeRuntimeId"
29+
class="form-switch"
30+
@update:value="toggleContextMenu(id)"
31+
>
2632
<template #checked>{{ i18n('on', 'common', 'button') }}</template>
2733
<template #unchecked>{{ i18n('off', 'common', 'button') }}</template>
2834
</NSwitch>

src/components/views/settings/SettingsTabs.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts" setup>
2+
import { chromeRuntimeId } from '@dvcol/web-extension-utils/chrome/runtime';
23
import { NIcon, NSelect, NSwitch, type SelectOption } from 'naive-ui';
34
45
import { type Component, computed, h, onBeforeMount, ref } from 'vue';
@@ -153,7 +154,9 @@ const container = ref();
153154
<NSwitch
154155
:value="state"
155156
class="form-switch"
156-
:disabled="state && disabled"
157+
:disabled="
158+
(state && disabled) || (Route.Progress === route && !chromeRuntimeId)
159+
"
157160
@update:value="toggleTab(route)"
158161
>
159162
<template #checked>{{ i18n('on', 'common', 'button') }}</template>

src/models/context/context-menu-hooks.model.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { createTab } from '@dvcol/web-extension-utils/chrome/tabs';
2+
13
import type { RouteLocationNormalized } from 'vue-router';
24

35
import { ContextMenuConstants, ContextMenuId, type ContextMenuIds, ContextMenus } from '~/models/context/context-menu.model';
@@ -6,7 +8,6 @@ import { action } from '~/utils/browser/borwser-action.utils';
68
import { context, type ContextMenuOnClickedData } from '~/utils/browser/browser-context.utils';
79
import { runtime } from '~/utils/browser/browser-runtime.utils';
810
import { storage } from '~/utils/browser/browser-storage.utils';
9-
import { createTab } from '~/utils/browser/browser.utils';
1011

1112
const setLastRoute = (data: ContextMenuOnClickedData) => {
1213
if (!data?.selectionText) return;

src/services/trakt.service.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { TraktApiExtended } from '@dvcol/trakt-http-client/models';
1919

2020
import { TvdbClient } from '@dvcol/tvdb-http-client';
2121

22+
import { createTab } from '@dvcol/web-extension-utils/chrome/tabs';
23+
2224
import type { JsonWriterOptions } from '@dvcol/common-utils/common/save';
2325
import type { CancellablePromise } from '@dvcol/common-utils/http/fetch';
2426
import type {
@@ -70,7 +72,7 @@ import { tvdbClientSettings } from '~/settings/tvdb.api';
7072
import { useAuthSettingsStore } from '~/stores/settings/auth.store';
7173
import { logger } from '~/stores/settings/log.store';
7274
import { useUserSettingsStore } from '~/stores/settings/user.store';
73-
import { createTab } from '~/utils/browser/browser.utils';
75+
7476
import { CachePrefix, ChromeCacheStore } from '~/utils/cache.utils';
7577
import { cancellablePaginatedWriteJson } from '~/utils/trakt-service.utils';
7678

src/settings/traktv.api.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Config as TraktConfig } from '@dvcol/trakt-http-client/config';
22

3+
import { chromeRuntimeId } from '@dvcol/web-extension-utils/chrome/runtime';
4+
35
import type { TraktClientSettings } from '@dvcol/trakt-http-client/models';
46

57
import { WebConfig } from '~/settings/web.config';
6-
import { chromeRuntimeId } from '~/utils/browser/browser.utils';
78

89
export const Config = {
910
UserAgent: `${import.meta.env.PKG_NAME}/${import.meta.env.PKG_VERSION}`,

src/stores/settings/links.store.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { createTab } from '@dvcol/web-extension-utils/chrome/tabs';
12
import { defineStore, storeToRefs } from 'pinia';
23
import { computed, reactive, ref, type Ref } from 'vue';
34

45
import type { TagLink } from '~/models/tag.model';
56

67
import { logger } from '~/stores/settings/log.store';
78
import { storage } from '~/utils/browser/browser-storage.utils';
8-
import { createTab } from '~/utils/browser/browser.utils';
99
import { debounce } from '~/utils/debounce.utils';
1010
import { clearProxy } from '~/utils/vue.utils';
1111

src/utils/browser/browser.utils.ts

-20
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
/**
2-
* Open a new tab with the given options.
3-
*
4-
* This is a wrapper around `chrome.tabs.create` that falls back to `window.open` if the method is not available.
5-
*
6-
* @param options - The options for the new tab.
7-
*/
8-
const openTab = (options: chrome.tabs.CreateProperties) => window.open(options.url, options.active ? '_self' : '_blank');
9-
10-
/**
11-
* @see [chrome.tabs.create](https://developer.chrome.com/docs/extensions/reference/tabs/#method-create)
12-
*/
13-
export const createTab = (options: chrome.tabs.CreateProperties) => (globalThis?.chrome?.tabs?.create ?? openTab)(options);
14-
15-
/**
16-
* The ID of the current extension.
17-
* @see [chrome.runtime.id](https://developer.chrome.com/docs/extensions/reference/runtime/#property-id)
18-
*/
19-
export const chromeRuntimeId: typeof chrome.runtime.id | undefined = globalThis?.chrome?.runtime?.id;
20-
211
/**
222
* The i18n API for the current browser.
233
* @see [chrome.i18n](https://developer.chrome.com/docs/extensions/reference/i18n/)

0 commit comments

Comments
 (0)