Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复修饰键和关闭逻辑的冲突问题 #209

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/background/core/configManager/wordMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class WordMarkConfigManager {
...config,
[key]: value,
};
// enable 改变时,将 disable url 全部清空
if (key === 'enable') {
result.disableUrl = [];
}
await Chrome.storage.local.set({
[STORAGE_KEYS.SETTINGS.WORD_MARK_CONFIG]: result,
});
Expand Down Expand Up @@ -70,6 +66,14 @@ class WordMarkConfigManager {
config[key] = defaultWordMarkConfig[key] as never;
}

// 由于历史数据可能被写入 string 或者 string[] 如果判断出是这种数据的,将内容置空
if (key === 'disableUrl') {
const tempValue = config[key];
if (typeof tempValue === 'string' || typeof tempValue?.[0] === 'string') {
config[key] = [];
}
}

/**
* 当缓存中的 toolbars 长度和默认不一致时,说明扩展了 toolbars
* 然后将新增的 toolbars 扩展到缓存的最后
Expand Down
2 changes: 1 addition & 1 deletion src/components/DisableUrlCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function DisableUrlCard(props: IDisableUrlCardProps) {
return null;
}
return (
<Row gutter={20}>
<Row gutter={[20, 20]}>
{options.map((item, index) => {
return (
<Col span={12} key={item.origin}>
Expand Down
5 changes: 3 additions & 2 deletions src/components/WordMarkLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ function WordMarkLayout(props: IWordMarkLayoutProps) {

const isEnableWordMark = (config: IWordMarkConfig | null) => {
const url = `${window.location.origin}${window.location.pathname}`;
if (config?.evokeWordMarkShortKey) {
if (!config?.enable && config?.evokeWordMarkShortKey) {
return true;
}
if (!config?.enable || config.disableUrl?.includes(url)) {
const isDisableUrl = config?.disableUrl?.find?.(item => item.origin === url);
if (!config?.enable || !!isDisableUrl) {
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/isomorphic/constant/wordMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type IWordMarkConfig = {
innerPinList: Array<WordMarkOptionTypeEnum>;

// 禁用页面的 url
disableUrl: Array<string>;
disableUrl: Array<{ origin: string; icon: string }>;

// 剪藏时唤起面板
evokePanelWhenClip: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/inject/LevitateBall/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function App() {
>
{__i18n('设置')}
</div>
{__i18n('开启')}
{__i18n('中开启')}
</div>
</>
),
Expand Down
16 changes: 15 additions & 1 deletion src/pages/inject/WordMark/Inner/DisableMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,38 @@ import React from 'react';
import { __i18n } from '@/isomorphic/i18n';
import LinkHelper from '@/isomorphic/link-helper';
import { backgroundBridge } from '@/core/bridge/background';
import { useWordMarkContext } from '@/components/WordMarkLayout/useWordMarkContext';
import styles from './DisableMenu.module.less';

function DisableMenu() {
const { disableUrl } = useWordMarkContext();
const disableForever = () => {
backgroundBridge.configManager.update('wordMark', 'enable', false, {
notice: true,
});
window._yuque_ext_app.removeWordMark();
};

const disableForPage = () => {
const iconLink =
document.querySelector("link[rel*='icon']") ||
document.querySelector("link[rel*='Icon']");
const iconUrl = (iconLink as HTMLLinkElement)?.href;
backgroundBridge.configManager.update(
'wordMark',
'disableUrl',
`${window.location.origin}${window.location.pathname}`,
[
...disableUrl,
{
origin: `${window.location.origin}${window.location.pathname}`,
icon: iconUrl,
},
],
{
notice: true,
},
);
window._yuque_ext_app.removeWordMark();
};

const disableOnce = () => {
Expand Down
29 changes: 15 additions & 14 deletions src/pages/inject/WordMark/Inner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ function InnerWordMark(props: InnerWordMarkProps) {
}
if (pinedTools.length > 3) {
return (
<Tooltip
title={item.name}
key={item.type}
>
<Tooltip title={item.name} key={item.type}>
<Typography
type="iconButton"
ml={6}
Expand Down Expand Up @@ -89,16 +86,20 @@ function InnerWordMark(props: InnerWordMarkProps) {
<LarkIcon name="more" />
</div>
</Popover>
<div className={styles.line} />
<Popover
placement="bottomRight"
content={<DisableMenu />}
overlayClassName={styles.overlayClassName}
>
<div className={styles.closeActions}>
<LarkIcon name="close-outline" size={14} />
</div>
</Popover>
{(wordMarkContext.enable || !wordMarkContext.evokeWordMarkShortKey) && (
<>
<div className={styles.line} />
<Popover
placement="bottomRight"
content={<DisableMenu />}
overlayClassName={styles.overlayClassName}
>
<div className={styles.closeActions}>
<LarkIcon name="close-outline" size={14} />
</div>
</Popover>
</>
)}
</div>
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/pages/setting/wordMark/index.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@
.iconWrapper {
font-size: @font-size-lg;
}

.disableUrlCard {
margin-top: 18px;
}
26 changes: 25 additions & 1 deletion src/pages/setting/wordMark/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useMemo, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { Select, Switch, Row, Col } from 'antd';
import DisableUrlCard, { IDisableUrlItem } from '@/components/DisableUrlCard';
import { ToolbarItem, toolbars } from '@/pages/inject/WordMark/constants';
import { WordMarkOptionTypeEnum } from '@/isomorphic/constant/wordMark';
import { __i18n } from '@/isomorphic/i18n';
Expand Down Expand Up @@ -94,6 +95,16 @@ function WordMark() {
onConfigChange('disableFunction', result);
};

const onDelete = useCallback(
(item: IDisableUrlItem) => {
const filterArray = config?.disableUrl?.filter(
d => d.origin !== item.origin,
);
onConfigChange('disableUrl', filterArray);
},
[config],
);

useEffect(() => {
backgroundBridge.configManager.get('wordMark').then(res => {
setConfig(res);
Expand Down Expand Up @@ -135,6 +146,19 @@ function WordMark() {
/>
</div>
)}
{!!config.disableUrl?.length && config.enable && (
<div>
<div className={styles.desc}>
{__i18n('管理不展示划词工具栏的页面')}
</div>
<div className={styles.disableUrlCard}>
<DisableUrlCard
options={config.disableUrl}
onDelete={onDelete}
/>
</div>
</div>
)}
</div>
</div>

Expand Down
Loading