-
Notifications
You must be signed in to change notification settings - Fork 316
feat(plugin-infra): add metadata previewer API; add minimal mode #4028
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
5698323
feat: add metadata reader API
Jack-Works 427032d
chore: add example
Jack-Works 3a734d5
fix: typo
Jack-Works 7679efc
chore: add contribution field
Jack-Works 6f1bbbd
chore: declare contributions for all plugin
Jack-Works 4328fe0
feat: plugin contribute hint when disabled. close #4918
Jack-Works 105a050
feat: update PossiblePluginSuggestionUI
yanzhihong23 df5a173
chore: add links to match list
Jack-Works 8e9d393
fix: collectible url match
yanzhihong23 9cb89ac
feat: show persona status in timeline
yanzhihong23 0f6ff8b
Merge branch 'develop' into metadata-reader
yanzhihong23 0211c66
Merge branch 'develop' into metadata-reader
yanzhihong23 5ebf8fb
style: plugin wrapper ui
yanzhihong23 85b509d
feat: hide switch for swap and transack
yanzhihong23 dc85edd
fix: enabled initial val
yanzhihong23 118f4cf
feat: support minimal mode in plugin infra
Jack-Works 7836b00
Merge branch 'develop' into metadata-reader
yanzhihong23 7f45e75
feat: check persona connect status in plugin wrapper
yanzhihong23 bf35378
fix: typo
yanzhihong23 668375a
fix: inversed options
Jack-Works 56402b1
fix: inversed options
Jack-Works db89078
fix: minimal mode switch
yanzhihong23 fd420c0
fix: minimal mode switch
yanzhihong23 7fef05b
feat: add minimal mode check for pets plugin
yanzhihong23 0d5ef38
feat: add publisher info for ITO & Lucky Drop
yanzhihong23 68d9ba5
feat: add publisher info for NFT Lucky Drop & MaskBox
yanzhihong23 f45f503
chore: reply review
yanzhihong23 c5fa9c9
Merge branch 'develop' into metadata-reader
yanzhihong23 ce5917f
Merge branch 'develop' into metadata-reader
yanzhihong23 aa5c1ad
fix: boundary
Jack-Works 0c2e613
feat: show plugin name
yanzhihong23 7e0b728
refactor: reply review
yanzhihong23 00b6c6f
Merge branch 'develop' into metadata-reader
yanzhihong23 d8f092f
fix: merge
yanzhihong23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
39 changes: 39 additions & 0 deletions
39
packages/mask/src/components/DataSource/usePersonaConnectStatus.ts
This file contains hidden or 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,39 @@ | ||
| import { DashboardRoutes, ProfileIdentifier } from '@masknet/shared-base' | ||
| import stringify from 'json-stable-stringify' | ||
| import { useMemo } from 'react' | ||
| import Services from '../../extension/service' | ||
| import { currentSetupGuideStatus } from '../../settings/settings' | ||
| import { activatedSocialNetworkUI } from '../../social-network' | ||
| import { SetupGuideStep } from '../InjectedComponents/SetupGuide' | ||
| import { useLastRecognizedIdentity } from './useActivatedUI' | ||
| import { useMyPersonas } from './useMyPersonas' | ||
|
|
||
| const createPersona = () => { | ||
| Services.Welcome.openOptionsPage(DashboardRoutes.Setup) | ||
| } | ||
|
|
||
| const connectPersona = async () => { | ||
| const currentPersonaIdentifier = await Services.Settings.getCurrentPersonaIdentifier() | ||
| currentSetupGuideStatus[activatedSocialNetworkUI.networkIdentifier].value = stringify({ | ||
| status: SetupGuideStep.FindUsername, | ||
| persona: currentPersonaIdentifier?.toText(), | ||
| }) | ||
| } | ||
|
|
||
| export function usePersonaConnectStatus() { | ||
| const personas = useMyPersonas() | ||
| const lastRecognized = useLastRecognizedIdentity() | ||
|
|
||
| return useMemo(() => { | ||
| const id = new ProfileIdentifier(activatedSocialNetworkUI.networkIdentifier, lastRecognized.identifier.userId) | ||
| let connected = false | ||
| personas.forEach((p) => { | ||
| p.identifier | ||
| if (p.linkedProfiles.get(id)) { | ||
| connected = true | ||
| } | ||
| }) | ||
| const action = !personas.length ? createPersona : !connected ? connectPersona : null | ||
| return { connected, action, hasPersona: !!personas.length } | ||
| }, [personas, lastRecognized, activatedSocialNetworkUI]) | ||
| } |
This file contains hidden or 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 hidden or 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
72 changes: 72 additions & 0 deletions
72
packages/mask/src/components/InjectedComponents/DisabledPluginSuggestion.tsx
This file contains hidden or 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,72 @@ | ||
| import { | ||
| useActivatedPluginsSNSAdaptor, | ||
| registeredPlugins, | ||
| usePostInfoDetails, | ||
| Result, | ||
| Plugin, | ||
| } from '@masknet/plugin-infra' | ||
| import { extractTextFromTypedMessage } from '@masknet/shared-base' | ||
| import { Switch } from '@mui/material' | ||
| import Services from '../../extension/service' | ||
| import MaskPluginWrapper from '../../plugins/MaskPluginWrapper' | ||
| import { useI18N } from '../../utils' | ||
|
|
||
| function useDisabledPlugins() { | ||
| const activated = new Set(useActivatedPluginsSNSAdaptor('any').map((x) => x.ID)) | ||
| const minimalMode = new Set(useActivatedPluginsSNSAdaptor(true).map((x) => x.ID)) | ||
| const disabledPlugins = [...registeredPlugins].filter((x) => !activated.has(x.ID) || minimalMode.has(x.ID)) | ||
| return disabledPlugins | ||
| } | ||
|
|
||
| export function useDisabledPluginSuggestionFromPost(postContent: Result<string, any>, metaLinks: string[]) { | ||
| const disabled = useDisabledPlugins().filter((x) => x.contribution?.postContent) | ||
|
|
||
| const { ok, val } = postContent | ||
| const matches = disabled.filter((x) => { | ||
| for (const pattern of x.contribution!.postContent!) { | ||
| if (ok && val.match(pattern)) return true | ||
| if (metaLinks.some((link) => link.match(pattern))) return true | ||
| } | ||
| return false | ||
| }) | ||
| return matches | ||
| } | ||
|
|
||
| export function useDisabledPluginSuggestionFromMeta(meta: ReadonlyMap<string, unknown>) { | ||
| const disabled = useDisabledPlugins().filter((x) => x.contribution?.metadataKeys) | ||
| const keys = [...meta.keys()] | ||
|
|
||
| const matches = disabled.filter((x) => { | ||
| const contributes = x.contribution!.metadataKeys! | ||
| return keys.some((key) => contributes.has(key)) | ||
| }) | ||
| return matches | ||
| } | ||
|
|
||
| export function PossiblePluginSuggestionPostInspector() { | ||
| const message = extractTextFromTypedMessage(usePostInfoDetails.rawMessage()) | ||
| const metaLinks = usePostInfoDetails.postMetadataMentionedLinks().concat(usePostInfoDetails.mentionedLinks()) | ||
| const matches = useDisabledPluginSuggestionFromPost(message, metaLinks) | ||
| return <PossiblePluginSuggestionUI plugins={matches} /> | ||
| } | ||
| export function PossiblePluginSuggestionUI(props: { plugins: Plugin.DeferredDefinition[] }) { | ||
| const { t } = useI18N() | ||
| const { plugins } = props | ||
| if (!plugins.length) return null | ||
| return ( | ||
| <> | ||
| {plugins.map((x) => ( | ||
| <MaskPluginWrapper | ||
| key={x.ID} | ||
| pluginName={t('plugin_not_enabled', { plugin: x.name.fallback })} | ||
| action={ | ||
| <Switch | ||
| sx={{ marginRight: '-12px' }} | ||
| onChange={() => Services.Settings.setPluginMinimalModeEnabled(x.ID, false)} | ||
| /> | ||
| } | ||
| /> | ||
| ))} | ||
| </> | ||
| ) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.