Skip to content

Commit

Permalink
refactor: PluginEnableBoundary (#10843)
Browse files Browse the repository at this point in the history
* refactor: remove unused code

* refactor: remove unused code

* refactor: remove unused code

* refactor: remove unused code

* refactor: useof PluginEnableBoundary

* fix: fs contribution

* fix: scamwarnning contribution
  • Loading branch information
guanbinrui committed Sep 25, 2023
1 parent e9020c1 commit 998339d
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 231 deletions.
11 changes: 0 additions & 11 deletions packages/mask/shared-ui/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,7 @@
"application_settings_tab_plug_app-listed-placeholder": "Click the application icon to hide in the APP list.",
"application_display_tab_plug_app-unlisted-placeholder": "Click the setting icon to list it on the App board.",
"application_settings_tab_plug_app-unlisted-placeholder": "Click the application icon to list it on the App board.",
"applications_persona_title": "Persona",
"applications_persona_copy": "Copy Success",
"applications_persona_connect": "Connect {{-nickname}}",
"applications_persona_connect_hint": "Please connect {{-nickname}} before using dApps.",
"applications_persona_verify": "Verify {{-nickname}}",
"applications_persona_verify_hint": "Please verify current persona with social media account before using dApps.",
"applications_persona_verify_connect": "Connect and Verify {{-nickname}}",
"applications_persona_verify_connect_hint": "Please connect {{-nickname}} and send proof post before using dApps.",
"persona_load_failed": "Load failed",
"enable_plugin_boundary": "Enable plugin",
"enable_plugin_boundary_description": "This function has been turned off in the App settings. Enable plug-ins to fully access.",
"additional_post_box__encrypted_post_pre": "Decrypt this post with #mask_io! $t(promote) {{encrypted}}",
"additional_post_box__encrypted_post_pre_red_packet_sns_official_account": "$t(promote_red_packet) Follow @{{account}} for Web3 updates and insights. \n\n🧧🧧🧧 Try sending Lucky Drop to your friends with Mask.io. \n\n{{encrypted}}",
"additional_post_box__encrypted_post_pre_red_packet": "$t(promote_red_packet) \n\n🧧🧧🧧 Try sending Lucky Drop to your friends with Mask.io. \n\n{{encrypted}}",
Expand Down Expand Up @@ -1081,7 +1071,6 @@
"plugin_default_title": "Default",
"plugin_provider_by": "Provided by",
"plugin_enable": "Enable plugin",
"show_wallet_setting_intro": "Please select the wallet to activate the function after saving the settings.",
"show_wallet_setting_button": "Go to Settings",
"web3_profile_no_social_address_list": "Can’t find a valid user address data source.",
"plugin_avatar_feature_general_user_name": "General user",
Expand Down
10 changes: 0 additions & 10 deletions packages/mask/shared-ui/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,7 @@
"application_settings_tab_plug_app-listed-placeholder": "アプリアイコンをクリックして、アプリ一覧で非表示にします。",
"application_display_tab_plug_app-unlisted-placeholder": "設定のアイコンをクリックして、アプリボードに表示します。",
"application_settings_tab_plug_app-unlisted-placeholder": "アプリのアイコンをクリックして、アプリボードに表示します。",
"applications_persona_title": "ペルソナ",
"applications_persona_copy": "コピー完了",
"applications_persona_connect": "{{nickname}} に接続",
"applications_persona_connect_hint": "dAppsを使用する前に、 {{nickname}} に接続してください。",
"applications_persona_verify": "{{nickname}} の認証",
"applications_persona_verify_hint": "dAppsを使用する前に、ソーシャルメディアアカウントで現在のペルソナを確認してください。",
"applications_persona_verify_connect": "{{nickname}} に接続して認証します",
"applications_persona_verify_connect_hint": "dAppsを利用する前に{{nickname}}を接続し、プルーフポストを送信してください。",
"persona_load_failed": "読み込み失敗",
"enable_plugin_boundary": "プラグインを有効にする",
"enable_plugin_boundary_description": "特定のコンテンツを表示するには DApp を開く必要があります。",
"additional_post_box__encrypted_post_pre": "#mask_io で復号しましょう! {{encrypted}}",
"additional_post_box__encrypted_post_pre_red_packet_sns_official_account": "こんにちは、#mask_io @{{account}} でラッキードロップを獲得しましょう。 \n\n$t(promote_red_packet)\n {{encrypted}}",
"additional_post_box__encrypted_post_pre_red_packet": "こんにちは、#mask_io @{{account}} でラッキードロップを獲得しましょう。 \n\n$t(promote_red_packet)\n {{encrypted}}",
Expand Down
11 changes: 0 additions & 11 deletions packages/mask/shared-ui/locales/ko-KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,7 @@
"application_settings_tab_plug_app-listed-placeholder": "애프리케이션 아이콘을 클릭하여 앱 리스트에 숨깁니다.",
"application_display_tab_plug_app-unlisted-placeholder": "설정 아이콘을 클릭하여 앱 보드에 나열합니다.",
"application_settings_tab_plug_app-unlisted-placeholder": "애프리케이션 아이콘을 클릭하여 앱 보드에 나열합니다.",
"applications_persona_title": "페르소나",
"applications_persona_copy": "복사 성공",
"applications_persona_connect": "{{nickname}} 에 연결하기",
"applications_persona_connect_hint": "dApp을 이용하기 전에 {{nickname}} 연결하세요.",
"applications_persona_verify": "{{nickname}} 검증",
"applications_persona_verify_hint": "dApp 이용하기 전에 소셜 미디어 계정으로 이용 중인 페르소나를 검증하세요.",
"applications_persona_verify_connect": "{{nickname}} 연결 및 검증",
"applications_persona_verify_connect_hint": "dApp을 이용하기 전에 {{nickname}} 연결하고 증명 게시글 보내세요.",
"persona_load_failed": "로딩 실패",
"enable_plugin_boundary": "플러그인 활성화",
"enable_plugin_boundary_description": "특정 콘텐츠를 보려면 dApp을 열어야 합니다.",
"additional_post_box__encrypted_post_pre": "#mask_io로 이 게시물을 해독하기. {{encrypted}}",
"additional_post_box__encrypted_post_pre_red_packet_sns_official_account": "#mask_io로 행운 드랍을 수령해 보세요. @{{account}} \n\n$t(promote_red_packet)\n {{encrypted}}",
"additional_post_box__encrypted_post_pre_red_packet": "#mask_io {{encrypted}} 덧붙이고 레드 패킷을 수령하세요.",
Expand Down Expand Up @@ -787,7 +777,6 @@
"plugin_default_title": "디폴트",
"plugin_provider_by": "제공자",
"plugin_enable": "플러그인 활성화",
"show_wallet_setting_intro": "설정 저장 후 이 기능을 활성화하는 데 사용할 월렛을 선택하세요.",
"show_wallet_setting_button": "설정으로 가기",
"web3_profile_no_social_address_list": "인증된 사용자 주소 데이터 소스를 찾을 수 없습니다.",
"plugin_avatar_feature_general_user_name": "일반 사용자",
Expand Down
11 changes: 0 additions & 11 deletions packages/mask/shared-ui/locales/qya-AA.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,7 @@
"application_settings_tab_plug_app-listed-placeholder": "crwdns16228:0crwdne16228:0",
"application_display_tab_plug_app-unlisted-placeholder": "crwdns17254:0crwdne17254:0",
"application_settings_tab_plug_app-unlisted-placeholder": "crwdns16230:0crwdne16230:0",
"applications_persona_title": "crwdns18496:0crwdne18496:0",
"applications_persona_copy": "crwdns18498:0crwdne18498:0",
"applications_persona_connect": "crwdns18500:0{{-nickname}}crwdne18500:0",
"applications_persona_connect_hint": "crwdns18502:0{{-nickname}}crwdne18502:0",
"applications_persona_verify": "crwdns18504:0{{-nickname}}crwdne18504:0",
"applications_persona_verify_hint": "crwdns18506:0crwdne18506:0",
"applications_persona_verify_connect": "crwdns18508:0{{-nickname}}crwdne18508:0",
"applications_persona_verify_connect_hint": "crwdns18510:0{{-nickname}}crwdne18510:0",
"persona_load_failed": "crwdns18600:0crwdne18600:0",
"enable_plugin_boundary": "crwdns18602:0crwdne18602:0",
"enable_plugin_boundary_description": "crwdns19131:0crwdne19131:0",
"additional_post_box__encrypted_post_pre": "crwdns3991:0$t(promote)crwdnd3991:0{{encrypted}}crwdne3991:0",
"additional_post_box__encrypted_post_pre_red_packet_sns_official_account": "crwdns19497:0$t(promote_red_packet)crwdnd19497:0{{account}}crwdnd19497:0{{encrypted}}crwdne19497:0",
"additional_post_box__encrypted_post_pre_red_packet": "crwdns3995:0$t(promote_red_packet)crwdnd3995:0{{encrypted}}crwdne3995:0",
Expand Down Expand Up @@ -1073,7 +1063,6 @@
"plugin_default_title": "crwdns16634:0crwdne16634:0",
"plugin_provider_by": "crwdns16636:0crwdne16636:0",
"plugin_enable": "crwdns19817:0crwdne19817:0",
"show_wallet_setting_intro": "crwdns18672:0crwdne18672:0",
"show_wallet_setting_button": "crwdns18674:0crwdne18674:0",
"web3_profile_no_social_address_list": "crwdns18676:0crwdne18676:0",
"plugin_avatar_feature_general_user_name": "crwdns19103:0crwdne19103:0",
Expand Down
11 changes: 0 additions & 11 deletions packages/mask/shared-ui/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,7 @@
"application_settings_tab_plug_app-listed-placeholder": "点击应用图标将会在应用列表中隐藏。",
"application_display_tab_plug_app-unlisted-placeholder": "点击设置图标进入设置页面,在应用面板上设置显示应用。",
"application_settings_tab_plug_app-unlisted-placeholder": "点击应用图标将会在应用列表中显示。",
"applications_persona_title": "身份",
"applications_persona_copy": "复制成功",
"applications_persona_connect": "连接到 {{nickname}}",
"applications_persona_connect_hint": "请在使用 dApp之前连接到 {{nickname}} 。",
"applications_persona_verify": "验证 {{nickname}}",
"applications_persona_verify_hint": "进入应用前请使用当前身份验证当前社交媒体账号。",
"applications_persona_verify_connect": "连接到 {{nickname}} 并进行验证",
"applications_persona_verify_connect_hint": "请在使用 dApp之前连接到 {{nickname}} 并发送验证推文。",
"persona_load_failed": "加载失败",
"enable_plugin_boundary": "开启插件",
"enable_plugin_boundary_description": "您需要打开 DAPP 才能查看特定内容。",
"additional_post_box__encrypted_post_pre": "安装 #mask_io 解密此贴文 ! {{encrypted}}",
"additional_post_box__encrypted_post_pre_red_packet_sns_official_account": "使用 #mask_io 来领取这个红包!@{{account}} \n\n$t(promote_red_packet)\n {{encrypted}}",
"additional_post_box__encrypted_post_pre_red_packet": "使用 #mask_io 来认领这个红包!@{{encrypted}}",
Expand Down Expand Up @@ -1041,7 +1031,6 @@
"plugin_default_title": "默认",
"plugin_provider_by": "提供方:",
"plugin_enable": "开启插件",
"show_wallet_setting_intro": "请选择钱包保存设置后激活功能。",
"show_wallet_setting_button": "前往设置",
"web3_profile_no_social_address_list": "找不到有效的用户地址数据源。",
"plugin_avatar_feature_general_user_name": "普通用户",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { type ReactNode, useCallback } from 'react'
import { useAsync } from 'react-use'
import type { Option } from 'ts-results-es'
import { useSubscription } from 'use-subscription'
import { Icons } from '@masknet/icons'
import {
type Plugin,
Expand All @@ -11,10 +15,6 @@ import { BooleanPreference, EMPTY_LIST } from '@masknet/shared-base'
import { makeStyles, MaskLightTheme } from '@masknet/theme'
import { extractTextFromTypedMessage } from '@masknet/typed-message'
import { Box, type BoxProps, Button, Skeleton, Typography, useTheme } from '@mui/material'
import { type ReactNode, useCallback } from 'react'
import { useAsync } from 'react-use'
import type { Option } from 'ts-results-es'
import { useSubscription } from 'use-subscription'
import Services from '#services'
import { useI18N } from '../../utils/index.js'

Expand Down Expand Up @@ -42,12 +42,12 @@ export function useDisabledPluginSuggestionFromPost(postContent: Option<string>,

export function useDisabledPluginSuggestionFromMeta(meta: undefined | ReadonlyMap<string, unknown>) {
const disabled = useDisabledPlugins().filter((x) => x.contribution?.metadataKeys)

if (!meta) return EMPTY_LIST
const keys = [...meta.keys()]

const matches = disabled.filter((x) => {
const contributes = x.contribution!.metadataKeys!
return keys.some((key) => contributes.has(key))
return [...meta.keys()].some((key) => contributes.has(key))
})
return matches
}
Expand All @@ -58,6 +58,7 @@ export function PossiblePluginSuggestionPostInspector() {
const matches = useDisabledPluginSuggestionFromPost(message, metaLinks)
return <PossiblePluginSuggestionUI plugins={matches} />
}

export function PossiblePluginSuggestionUI(props: { plugins: Plugin.Shared.Definition[] }) {
const { plugins } = props
const _plugins = useActivatedPluginsSiteAdaptor('any')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import type { PluginWrapperComponent, Plugin, PluginWrapperMethods } from '@masknet/plugin-infra/content-script'
import { MaskPostExtraPluginWrapper, useSharedI18N } from '@masknet/shared'
import { EMPTY_LIST } from '@masknet/shared-base'
import { Typography, useTheme } from '@mui/material'
import {
forwardRef,
memo,
Expand All @@ -13,8 +9,13 @@ import {
useState,
} from 'react'
import type { AsyncState } from 'react-use/lib/useAsyncFn.js'
import type { PluginWrapperComponent, Plugin, PluginWrapperMethods } from '@masknet/plugin-infra/content-script'
import { MaskPostExtraPluginWrapper, useSharedI18N } from '@masknet/shared'
import { EMPTY_LIST } from '@masknet/shared-base'
import { Typography, useTheme } from '@mui/material'
import { useCheckPermissions, useGrantPermissions } from '../DataSource/usePluginHostPermission.js'
import { PossiblePluginSuggestionUISingle } from './DisabledPluginSuggestion.js'

interface PermissionBoundaryProps extends PropsWithChildren<{}> {
permissions: string[]
fallback?:
Expand Down Expand Up @@ -52,6 +53,7 @@ export const MaskPostExtraPluginWrapperWithPermission: PluginWrapperComponent<Pl
}, [])

useImperativeHandle(ref, () => refItem, [refItem])

return (
<PermissionBoundary
permissions={props.definition.enableRequirement.host_permissions ?? EMPTY_LIST}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { DecryptPost } from './DecryptedPost/DecryptedPost.js'
import { useCurrentIdentity } from '../DataSource/useActivatedUI.js'
import { useSubscription } from 'use-subscription'
import {
usePostInfoDetails,
createInjectHooksRenderer,
useActivatedPluginsSiteAdaptor,
} from '@masknet/plugin-infra/content-script'
import { DecryptPost } from './DecryptedPost/DecryptedPost.js'
import { useCurrentIdentity } from '../DataSource/useActivatedUI.js'
import { PossiblePluginSuggestionPostInspector } from './DisabledPluginSuggestion.js'
import { useSubscription } from 'use-subscription'
import { PersistentStorages } from '../../../shared/index.js'
import { MaskPostExtraPluginWrapperWithPermission } from './PermissionBoundary.js'
import { PersistentStorages } from '../../../shared/index.js'

const PluginHooksRenderer = createInjectHooksRenderer(
useActivatedPluginsSiteAdaptor.visibility.useNotMinimalMode,
Expand Down
58 changes: 0 additions & 58 deletions packages/mask/src/components/shared/PluginEnableBoundary.tsx

This file was deleted.

5 changes: 3 additions & 2 deletions packages/plugins/FileService/src/SiteAdaptor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ThemeProvider } from '@mui/material'
import { Trans } from 'react-i18next'
import { base } from '../base.js'
import { META_KEY_1, META_KEY_2, META_KEY_3 } from '../constants.js'
import { FileInfoMetadataReader } from '../helpers.js'
import { getFileInfoMetadata } from '../helpers.js'
import type { FileInfo } from '../types.js'
import { MultipleFileChip, SingleFileChip } from './components/index.js'
import { FileViewer } from './FileViewer.js'
Expand All @@ -32,7 +32,8 @@ const definition: Plugin.SiteAdaptor.Definition = {
setupStorage(context.createKVStorage<StorageOptions>('persistent', { termsConfirmed: undefined }))
},
DecryptedInspector(props) {
const metadata = FileInfoMetadataReader(props.message.meta)
const metadata = getFileInfoMetadata(props.message.meta)

if (!metadata.isOk()) return null
return (
<ThemeProvider theme={MaskLightTheme}>
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/FileService/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Plugin } from '@masknet/plugin-infra'
import { DEFAULT_PLUGIN_PUBLISHER, EnhanceableSite, PluginID } from '@masknet/shared-base'
import { languages } from './locales/languages.js'
import { META_KEY_1, META_KEY_2 } from './constants.js'
import { META_KEY_1, META_KEY_2, META_KEY_3 } from './constants.js'

export const base: Plugin.Shared.Definition = {
ID: PluginID.FileService,
Expand All @@ -21,6 +21,6 @@ export const base: Plugin.Shared.Definition = {
},
i18n: languages,
contribution: {
metadataKeys: new Set([META_KEY_1, META_KEY_2]),
metadataKeys: new Set([META_KEY_1, META_KEY_2, META_KEY_3]),
},
}
2 changes: 1 addition & 1 deletion packages/plugins/FileService/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const reader_v1 = createTypedMessageMetadataReader<FileInfoV1>(META_KEY_1, schem
const reader_v2 = createTypedMessageMetadataReader<FileInfo>(META_KEY_2, schemaV2)
const reader_v3 = createTypedMessageMetadataReader<FileInfo[]>(META_KEY_3, schemaV3)

export function FileInfoMetadataReader(meta: TypedMessage['meta']): Result<FileInfo[], void> {
export function getFileInfoMetadata(meta: TypedMessage['meta']): Result<FileInfo[], void> {
const v3 = reader_v3(meta)
if (v3.isOk()) return v3
const v2 = reader_v2(meta).map((info) => [info])
Expand Down
11 changes: 1 addition & 10 deletions packages/plugins/NextID/src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,5 @@
"persona_load_failed": "Load failed",
"applications_create_persona_title": "Persona",
"applications_create_persona_hint": "Please create a Persona and verify your account to use this function.",
"applications_create_persona_action": "Create persona",
"applications_persona_title": "Persona",
"applications_persona_copy": "Copy Success",
"applications_persona_connect": "Connect {{-nickname}}",
"applications_persona_connect_hint": "Please connect {{-nickname}} before using dApps.",
"applications_persona_verify": "Verify {{-nickname}}",
"applications_persona_verify_hint": "Please verify current persona with social media account before using dApps.",
"applications_persona_verify_connect": "Connect and Verify {{-nickname}}",
"applications_persona_verify_connect_hint": "Please connect {{-nickname}} and send proof post before using dApps.",
"enable_plugin": "You need to open the DAPP to view the specific content"
"applications_create_persona_action": "Create persona"
}

0 comments on commit 998339d

Please sign in to comment.