Skip to content

Commit 14ff250

Browse files
committed
Add an text prompt when no file permission allowed (#290)
1 parent f9c8340 commit 14ff250

File tree

5 files changed

+42
-24
lines changed

5 files changed

+42
-24
lines changed

src/api/chrome/runtime.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ export function setUninstallURL(url: string): Promise<void> {
5151
*/
5252
export function getUrl(path: string): string {
5353
return chrome.runtime.getURL(path)
54+
}
55+
56+
export async function isAllowedFileSchemeAccess(): Promise<boolean> {
57+
const res = await chrome.extension?.isAllowedFileSchemeAccess?.()
58+
return !!res
5459
}

src/app/components/Option/common.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const OptionItem = defineComponent({
2121
hideDivider: {
2222
type: Boolean,
2323
default: false,
24-
}
24+
},
2525
},
2626
setup: (props, ctx) => {
2727
return () => {

src/app/components/Option/components/StatisticsOption.tsx

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
* This software is released under the MIT License.
55
* https://opensource.org/licenses/MIT
66
*/
7-
import { ElSwitch } from "element-plus"
7+
import { ElSwitch, ElTooltip } from "element-plus"
88
import optionService from "@service/option-service"
99
import { defaultStatistics } from "@util/constant/option"
1010
import { defineComponent, reactive, unref, watch } from "vue"
1111
import { t } from "@app/locale"
1212
import { OptionInstance, OptionItem, OptionTag, OptionTooltip } from "../common"
13+
import { useRequest } from "@hooks"
14+
import { isAllowedFileSchemeAccess } from "@api/chrome/runtime"
15+
import { IS_FIREFOX } from "@util/constant/environment"
1316

1417
function copy(target: timer.option.StatisticsOption, source: timer.option.StatisticsOption) {
1518
target.collectSiteName = source.collectSiteName
@@ -18,6 +21,7 @@ function copy(target: timer.option.StatisticsOption, source: timer.option.Statis
1821

1922
const _default = defineComponent((_props, ctx) => {
2023
const option = reactive(defaultStatistics())
24+
const { data: fileAccess } = useRequest(isAllowedFileSchemeAccess)
2125
optionService.getAllOption().then(currentVal => {
2226
copy(option, currentVal)
2327
watch(option, () => optionService.setStatisticsOption(unref(option)))
@@ -27,32 +31,35 @@ const _default = defineComponent((_props, ctx) => {
2731
} satisfies OptionInstance)
2832
return () => <>
2933
<OptionItem
30-
label={msg => msg.option.statistics.countLocalFiles}
34+
label={msg => msg.option.statistics.collectSiteName}
3135
defaultValue={t(msg => msg.option.yes)}
3236
hideDivider
3337
v-slots={{
34-
info: () => <OptionTooltip>{t(msg => msg.option.statistics.localFilesInfo)}</OptionTooltip>,
35-
localFileTime: () => <OptionTag>{t(msg => msg.option.statistics.localFileTime)}</OptionTag>,
38+
siteName: () => <OptionTag>{t(msg => msg.option.statistics.siteName)}</OptionTag>,
39+
siteNameUsage: () => <OptionTooltip>{t(msg => msg.option.statistics.siteNameUsage)}</OptionTooltip>,
40+
default: () => <ElSwitch
41+
modelValue={option.collectSiteName}
42+
onChange={(val: boolean) => option.collectSiteName = val}
43+
/>
3644
}}
37-
>
38-
<ElSwitch
39-
modelValue={option.countLocalFiles}
40-
onChange={(val: boolean) => option.countLocalFiles = val}
41-
/>
42-
</OptionItem>
45+
/>
4346
<OptionItem
44-
label={msg => msg.option.statistics.collectSiteName}
45-
defaultValue={t(msg => msg.option.yes)}
47+
label={msg => msg.option.statistics.countLocalFiles}
48+
defaultValue={fileAccess.value ? t(msg => msg.option.yes) : null}
4649
v-slots={{
47-
siteName: () => <OptionTag>{t(msg => msg.option.statistics.siteName)}</OptionTag>,
48-
siteNameUsage: () => <OptionTooltip>{t(msg => msg.option.statistics.siteNameUsage)}</OptionTooltip>,
50+
info: () => <OptionTooltip>{t(msg => msg.option.statistics.localFilesInfo)}</OptionTooltip>,
51+
localFileTime: () => <OptionTag>{t(msg => msg.option.statistics.localFileTime)}</OptionTag>,
52+
default: () => fileAccess.value
53+
? <ElSwitch modelValue={option.countLocalFiles} onChange={(val: boolean) => option.countLocalFiles = val} />
54+
: <ElTooltip
55+
placement="top"
56+
v-slots={{
57+
content: () => IS_FIREFOX ? t(msg => msg.option.statistics.fileAccessFirefox) : t(msg => msg.option.statistics.fileAccessDisabled),
58+
default: () => <ElSwitch modelValue={false} disabled />,
59+
}}
60+
/>,
4961
}}
50-
>
51-
<ElSwitch
52-
modelValue={option.collectSiteName}
53-
onChange={(val: boolean) => option.collectSiteName = val}
54-
/>
55-
</OptionItem>
62+
/>
5663
</>
5764
})
5865

src/i18n/message/app/option-resource.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
"localFilesInfo": "支持 PDF、图片、txt 以及 json 等格式",
5252
"collectSiteName": "{input} 访问网站主页时,是否自动收集 {siteName} {siteNameUsage}",
5353
"siteName": "网站的名称",
54-
"siteNameUsage": "数据只存放在本地,将代替域名用于展示,增加辨识度。当然您可以自定义每个网站的名称"
54+
"siteNameUsage": "数据只存放在本地,将代替域名用于展示,增加辨识度。当然您可以自定义每个网站的名称",
55+
"fileAccessDisabled": "目前不允许访问文件网址,请先在管理界面开启",
56+
"fileAccessFirefox": "很抱歉,该功能在 Firefox 中不支持"
5557
},
5658
"dailyLimit": {
5759
"prompt": "受限时显示的提示文本 {input}",
@@ -286,10 +288,12 @@
286288
"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",
287289
"countLocalFiles": "{input} Whether to count the time to {localFileTime} {info} in the browser",
288290
"localFileTime": "read a local file",
289-
"localFilesInfo": "Supports files of types such as PDF, image, txt and json",
291+
"localFilesInfo": "Supports files of types such as PDF, image, txt and json.",
290292
"collectSiteName": "{input} Whether to automatically collect {siteName} {siteNameUsage} when visiting the site homepage",
291293
"siteName": "the site name",
292-
"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."
294+
"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.",
295+
"fileAccessDisabled": "Access to file URLs is currently not allowed. Please enable it in the manage page first",
296+
"fileAccessFirefox": "Sorry, this feature is not supported in Firefox"
293297
},
294298
"dailyLimit": {
295299
"prompt": "Prompt displayed when restricted {input}",

src/i18n/message/app/option.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export type OptionMessage = {
5454
collectSiteName: string
5555
siteNameUsage: string
5656
siteName: string
57+
fileAccessDisabled: string
58+
fileAccessFirefox: string
5759
}
5860
dailyLimit: {
5961
prompt: string

0 commit comments

Comments
 (0)