From 14ff2500527d5fe01d5cdcee358393487295dff2 Mon Sep 17 00:00:00 2001 From: sheepzh Date: Wed, 5 Jun 2024 15:51:42 +0800 Subject: [PATCH] Add an text prompt when no file permission allowed (#290) --- src/api/chrome/runtime.ts | 5 ++ src/app/components/Option/common.tsx | 2 +- .../Option/components/StatisticsOption.tsx | 47 +++++++++++-------- src/i18n/message/app/option-resource.json | 10 ++-- src/i18n/message/app/option.ts | 2 + 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/src/api/chrome/runtime.ts b/src/api/chrome/runtime.ts index 75dc08e9..df154ebd 100644 --- a/src/api/chrome/runtime.ts +++ b/src/api/chrome/runtime.ts @@ -51,4 +51,9 @@ export function setUninstallURL(url: string): Promise { */ export function getUrl(path: string): string { return chrome.runtime.getURL(path) +} + +export async function isAllowedFileSchemeAccess(): Promise { + const res = await chrome.extension?.isAllowedFileSchemeAccess?.() + return !!res } \ No newline at end of file diff --git a/src/app/components/Option/common.tsx b/src/app/components/Option/common.tsx index 535c65e0..09e75a1b 100644 --- a/src/app/components/Option/common.tsx +++ b/src/app/components/Option/common.tsx @@ -21,7 +21,7 @@ export const OptionItem = defineComponent({ hideDivider: { type: Boolean, default: false, - } + }, }, setup: (props, ctx) => { return () => { diff --git a/src/app/components/Option/components/StatisticsOption.tsx b/src/app/components/Option/components/StatisticsOption.tsx index 81169ee6..f18af5ae 100644 --- a/src/app/components/Option/components/StatisticsOption.tsx +++ b/src/app/components/Option/components/StatisticsOption.tsx @@ -4,12 +4,15 @@ * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ -import { ElSwitch } from "element-plus" +import { ElSwitch, ElTooltip } from "element-plus" import optionService from "@service/option-service" import { defaultStatistics } from "@util/constant/option" import { defineComponent, reactive, unref, watch } from "vue" import { t } from "@app/locale" import { OptionInstance, OptionItem, OptionTag, OptionTooltip } from "../common" +import { useRequest } from "@hooks" +import { isAllowedFileSchemeAccess } from "@api/chrome/runtime" +import { IS_FIREFOX } from "@util/constant/environment" function copy(target: timer.option.StatisticsOption, source: timer.option.StatisticsOption) { target.collectSiteName = source.collectSiteName @@ -18,6 +21,7 @@ function copy(target: timer.option.StatisticsOption, source: timer.option.Statis const _default = defineComponent((_props, ctx) => { const option = reactive(defaultStatistics()) + const { data: fileAccess } = useRequest(isAllowedFileSchemeAccess) optionService.getAllOption().then(currentVal => { copy(option, currentVal) watch(option, () => optionService.setStatisticsOption(unref(option))) @@ -27,32 +31,35 @@ const _default = defineComponent((_props, ctx) => { } satisfies OptionInstance) return () => <> msg.option.statistics.countLocalFiles} + label={msg => msg.option.statistics.collectSiteName} defaultValue={t(msg => msg.option.yes)} hideDivider v-slots={{ - info: () => {t(msg => msg.option.statistics.localFilesInfo)}, - localFileTime: () => {t(msg => msg.option.statistics.localFileTime)}, + siteName: () => {t(msg => msg.option.statistics.siteName)}, + siteNameUsage: () => {t(msg => msg.option.statistics.siteNameUsage)}, + default: () => option.collectSiteName = val} + /> }} - > - option.countLocalFiles = val} - /> - + /> msg.option.statistics.collectSiteName} - defaultValue={t(msg => msg.option.yes)} + label={msg => msg.option.statistics.countLocalFiles} + defaultValue={fileAccess.value ? t(msg => msg.option.yes) : null} v-slots={{ - siteName: () => {t(msg => msg.option.statistics.siteName)}, - siteNameUsage: () => {t(msg => msg.option.statistics.siteNameUsage)}, + info: () => {t(msg => msg.option.statistics.localFilesInfo)}, + localFileTime: () => {t(msg => msg.option.statistics.localFileTime)}, + default: () => fileAccess.value + ? option.countLocalFiles = val} /> + : IS_FIREFOX ? t(msg => msg.option.statistics.fileAccessFirefox) : t(msg => msg.option.statistics.fileAccessDisabled), + default: () => , + }} + />, }} - > - option.collectSiteName = val} - /> - + /> }) diff --git a/src/i18n/message/app/option-resource.json b/src/i18n/message/app/option-resource.json index e2e19d88..99891fd1 100644 --- a/src/i18n/message/app/option-resource.json +++ b/src/i18n/message/app/option-resource.json @@ -51,7 +51,9 @@ "localFilesInfo": "支持 PDF、图片、txt 以及 json 等格式", "collectSiteName": "{input} 访问网站主页时,是否自动收集 {siteName} {siteNameUsage}", "siteName": "网站的名称", - "siteNameUsage": "数据只存放在本地,将代替域名用于展示,增加辨识度。当然您可以自定义每个网站的名称" + "siteNameUsage": "数据只存放在本地,将代替域名用于展示,增加辨识度。当然您可以自定义每个网站的名称", + "fileAccessDisabled": "目前不允许访问文件网址,请先在管理界面开启", + "fileAccessFirefox": "很抱歉,该功能在 Firefox 中不支持" }, "dailyLimit": { "prompt": "受限时显示的提示文本 {input}", @@ -286,10 +288,12 @@ "idleTimeInfo": "If you do not operate for a long time (such as watching a video in full screen), the browser will automatically enter the idle state", "countLocalFiles": "{input} Whether to count the time to {localFileTime} {info} in the browser", "localFileTime": "read a local file", - "localFilesInfo": "Supports files of types such as PDF, image, txt and json", + "localFilesInfo": "Supports files of types such as PDF, image, txt and json.", "collectSiteName": "{input} Whether to automatically collect {siteName} {siteNameUsage} when visiting the site homepage", "siteName": "the site name", - "siteNameUsage": "The data is only stored locally and will be displayed instead of the URL to increase the recognition.Of course, you can also customize the name of each site." + "siteNameUsage": "The data is only stored locally and will be displayed instead of the URL to increase the recognition.Of course, you can also customize the name of each site.", + "fileAccessDisabled": "Access to file URLs is currently not allowed. Please enable it in the manage page first", + "fileAccessFirefox": "Sorry, this feature is not supported in Firefox" }, "dailyLimit": { "prompt": "Prompt displayed when restricted {input}", diff --git a/src/i18n/message/app/option.ts b/src/i18n/message/app/option.ts index 5e779002..2dfd6d65 100644 --- a/src/i18n/message/app/option.ts +++ b/src/i18n/message/app/option.ts @@ -54,6 +54,8 @@ export type OptionMessage = { collectSiteName: string siteNameUsage: string siteName: string + fileAccessDisabled: string + fileAccessFirefox: string } dailyLimit: { prompt: string