-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
872 additions
and
116 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { levitateConfigManager } from '@/background/core/configManager/levitate'; | ||
import { | ||
IOperateConfigManagerData, | ||
OperateConfigManagerEnum, | ||
} from '@/isomorphic/background/configManager'; | ||
import { wordMarkConfigManager } from '../core/configManager/wordMark'; | ||
import { RequestMessage } from './index'; | ||
|
||
const managerMap = { | ||
wordMark: wordMarkConfigManager, | ||
levitate: levitateConfigManager, | ||
}; | ||
|
||
export async function createManagerConfigActionListener( | ||
request: RequestMessage<IOperateConfigManagerData>, | ||
callback: (params: any) => void, | ||
) { | ||
const { type, value, key, managerType, option = {} } = request.data; | ||
const manage = managerMap[managerType]; | ||
switch (type) { | ||
case OperateConfigManagerEnum.get: { | ||
const result = await manage.get(); | ||
callback(result); | ||
break; | ||
} | ||
case OperateConfigManagerEnum.update: { | ||
const res = await manage.update(key, value, option); | ||
callback(res); | ||
break; | ||
} | ||
default: { | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import Chrome from '@/background/core/chrome'; | ||
import { ContentScriptEvents } from '@/isomorphic/event/contentScript'; | ||
import { | ||
defaultLevitateConfig, | ||
ILevitateConfig, | ||
LevitateConfigKey, | ||
} from '@/isomorphic/constant/levitate'; | ||
import { IConfigManagerOption } from '@/isomorphic/background/configManager'; | ||
import { STORAGE_KEYS } from '@/config'; | ||
import Storage from '../storage'; | ||
|
||
class LevitateConfigManager { | ||
async get() { | ||
const config: ILevitateConfig = | ||
(await Storage.get(STORAGE_KEYS.SETTINGS.LEVITATE_BALL_CONFIG)) || {}; | ||
|
||
// 做一次 config 的合并,保证获取时一定包含 config 中的每一个元素 | ||
for (const _key of Object.keys(defaultLevitateConfig)) { | ||
const key = _key as LevitateConfigKey; | ||
const value = config[key]; | ||
if (typeof value === 'undefined') { | ||
config[key] = defaultLevitateConfig[key] as never; | ||
} | ||
} | ||
|
||
return config; | ||
} | ||
|
||
async update(key: string, value: any, option?: IConfigManagerOption) { | ||
const config = await this.get(); | ||
const result: ILevitateConfig = { | ||
...config, | ||
[key]: value, | ||
}; | ||
await Chrome.storage.local.set({ | ||
[STORAGE_KEYS.SETTINGS.LEVITATE_BALL_CONFIG]: result, | ||
}); | ||
this.noticeWebPage(result); | ||
return result; | ||
} | ||
|
||
private noticeWebPage(config: ILevitateConfig) { | ||
// 异步通知页面 config 发生了改变 | ||
Chrome.tabs.query({ status: 'complete' }, tabs => { | ||
for (const tab of tabs) { | ||
if (tab.id) { | ||
Chrome.tabs.sendMessage(tab.id, { | ||
action: ContentScriptEvents.LevitateConfigChange, | ||
data: config, | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
export const levitateConfigManager = new LevitateConfigManager(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
@import '~@/styles/parameters.less'; | ||
|
||
.wrapper { | ||
display: flex; | ||
align-items: center; | ||
border-radius: 8px; | ||
box-shadow: @panel-default-box-shadow; | ||
padding: 12px; | ||
border: 1px solid @border-light-color; | ||
flex-wrap: wrap; | ||
gap: 16px; | ||
|
||
.cardItemWrapper { | ||
display: flex; | ||
gap: 12px; | ||
padding: 6px 12px; | ||
align-items: center; | ||
background-color: @grey-2; | ||
border-radius: 8px; | ||
width: calc(50% - 8px); | ||
border: 1px solid @border-color-primary; | ||
|
||
.icon { | ||
width: 16px; | ||
height: 16px; | ||
border-radius: 50%; | ||
flex: 0 0 auto; | ||
} | ||
|
||
.name { | ||
overflow: hidden; | ||
flex: 1 1 auto; | ||
white-space: nowrap; | ||
text-overflow: ellipsis; | ||
} | ||
|
||
.deleteWrapper { | ||
padding: 4px; | ||
display: flex; | ||
align-items: center; | ||
cursor: pointer; | ||
flex: 0 0 auto; | ||
border-radius: 4px; | ||
|
||
&:hover { | ||
background-color: @bg-primary-hover; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import { DeleteOutlined } from '@ant-design/icons'; | ||
import styles from './index.module.less'; | ||
|
||
export interface IDisableUrlItem { | ||
icon: string; | ||
origin: string; | ||
} | ||
|
||
interface IDisableUrlCardProps { | ||
options: Array<IDisableUrlItem>; | ||
onDelete: (item: IDisableUrlItem, index: number) => void; | ||
} | ||
|
||
function DisableUrlCard(props: IDisableUrlCardProps) { | ||
const { options = [] } = props; | ||
if (!options.length) { | ||
return null; | ||
} | ||
return ( | ||
<div className={styles.wrapper}> | ||
{options.map((item, index) => { | ||
return ( | ||
<div key={item.origin} className={styles.cardItemWrapper}> | ||
<img src={item.icon} className={styles.icon} /> | ||
<span className={styles.name}>{item.origin}</span> | ||
<div | ||
className={styles.deleteWrapper} | ||
onClick={() => props.onDelete(item, index)} | ||
> | ||
<DeleteOutlined /> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
} | ||
|
||
export default React.memo(DisableUrlCard); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { BackgroundEvents } from '@/isomorphic/background'; | ||
import { | ||
OperateConfigManagerEnum, | ||
IConfigManagerOption, | ||
ManagerType, | ||
ManagerKey, | ||
} from '@/isomorphic/background/configManager'; | ||
import type { ICallBridgeImpl } from './index'; | ||
|
||
export function createConfigManagerBridge(impl: ICallBridgeImpl) { | ||
return { | ||
configManager: { | ||
async update( | ||
managerType: ManagerType, | ||
key: ManagerKey, | ||
value: any, | ||
option?: IConfigManagerOption, | ||
): Promise<boolean> { | ||
return new Promise(resolve => { | ||
impl( | ||
BackgroundEvents.OperateManagerConfig, | ||
{ | ||
type: OperateConfigManagerEnum.update, | ||
key, | ||
value, | ||
option, | ||
managerType, | ||
}, | ||
() => { | ||
resolve(true); | ||
}, | ||
); | ||
}); | ||
}, | ||
|
||
async get(managerType: ManagerType): Promise<any> { | ||
return new Promise(resolve => { | ||
impl( | ||
BackgroundEvents.OperateManagerConfig, | ||
{ type: OperateConfigManagerEnum.get, managerType }, | ||
res => { | ||
resolve(res); | ||
}, | ||
); | ||
}); | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.