Skip to content
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
1 change: 1 addition & 0 deletions packages/plugins/SwitchLogo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@masknet/shared-base": "workspace:^",
"@masknet/shared-base-ui": "workspace:^",
"@masknet/theme": "workspace:^",
"@masknet/web3-providers": "workspace:^",
"@types/use-subscription": "^1.0.0",
"react-use": "^17.4.0",
"use-subscription": "^1.8.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* cspell: disable */
import { useCallback, useLayoutEffect } from 'react'
import { Icons } from '@masknet/icons'
import { CrossIsolationMessages, PluginID, SwitchLogoType } from '@masknet/shared-base'
import { useIsMinimalMode, type IdentityResolved } from '@masknet/plugin-infra/content-script'
import { makeStyles } from '@masknet/theme'
import { LiveSelector } from '@dimensiondev/holoflows-kit'
import { Icons } from '@masknet/icons'
import { useSwitchLogoStorage } from './storage.js'

const BlueBirdHTML = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const SwitchLogoDialog = memo<SwitchLogoDialogProps>(() => {

const onSave = useCallback(async () => {
if (!identity?.identifier?.userId) return
setupStorage(identity.identifier.userId, logoType ?? defaultLogoType)
await setupStorage(identity.identifier.userId, logoType ?? defaultLogoType)
setOpen(false)
if (needShare) {
share?.([t.share_text(), t.share_mask()].join('\n'))
Expand Down
24 changes: 11 additions & 13 deletions packages/plugins/SwitchLogo/src/SNSAdaptor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Plugin } from '@masknet/plugin-infra'
import { base } from '../base.js'
import { PLUGIN_ID } from '../constants.js'
import { PluginID, SwitchLogoType } from '@masknet/shared-base'
import { Trans } from 'react-i18next'
import { Icons } from '@masknet/icons'
import type { Plugin } from '@masknet/plugin-infra'
import { SNSAdaptorContext } from '@masknet/plugin-infra/content-script'
import { SNSAdaptorPluginContext } from '@masknet/web3-providers'
import { PluginID, SwitchLogoType } from '@masknet/shared-base'
import { SwitchLogoDialog } from './SwitchLogoDialog.js'
import { setupStorage } from './storage.js'
import { SNSAdaptorContext } from '@masknet/plugin-infra/content-script'
import { SharedContext } from '../settings.js'
import { base } from '../base.js'
import { PLUGIN_ID } from '../constants.js'

const recommendFeature = {
description: <Trans i18nKey="description" ns={PluginID.SwitchLogo} />,
Expand All @@ -17,16 +17,14 @@ const recommendFeature = {
const sns: Plugin.SNSAdaptor.Definition = {
...base,
init(signal, context) {
setupStorage(
context
.createKVStorage('persistent', {})
.createSubScope('SwitchLogo', { value: { default: SwitchLogoType.New } }),
)
SharedContext.value = context
SNSAdaptorPluginContext.setup(context)

const storage = context.createKVStorage('persistent', { value: { default: SwitchLogoType.New } })
setupStorage(storage)
},
GlobalInjection() {
return (
<SNSAdaptorContext.Provider value={SharedContext.value!}>
<SNSAdaptorContext.Provider value={SNSAdaptorPluginContext.context}>
<SwitchLogoDialog />
</SNSAdaptorContext.Provider>
)
Expand Down
24 changes: 12 additions & 12 deletions packages/plugins/SwitchLogo/src/SNSAdaptor/storage.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import type { ScopedStorage, SwitchLogoType } from '@masknet/shared-base'
import { useSubscription } from 'use-subscription'
import type { ScopedStorage, SwitchLogoType } from '@masknet/shared-base'

export type SwitchLogoStorageOptions = {
export interface SwitchLogoStorageOptions {
value: Record<string, SwitchLogoType>
}

let switchLogoStorage: ScopedStorage<SwitchLogoStorageOptions>
let storage: ScopedStorage<SwitchLogoStorageOptions> = null!

export function setupStorage(_: ScopedStorage<SwitchLogoStorageOptions>) {
switchLogoStorage = _
storage = _
}

export function useSwitchLogoStorage(
userId?: string,
): [value: SwitchLogoType, callback: (userId: string, newValue: SwitchLogoType) => void] {
const value = useSubscription(switchLogoStorage?.storage?.value?.subscription)
export function useSwitchLogoStorage(currentUserId = 'default') {
const value = useSubscription(storage?.storage.value.subscription)

return [
value[userId || 'default'],
function setSwitchLogoType(userId: string, newValue: SwitchLogoType) {
value[currentUserId],
async (userId: string, newValue: SwitchLogoType) => {
value[userId] = newValue
switchLogoStorage.storage.value.setValue(value)
await storage.storage.value.setValue(value)
},
]
] as const
}
3 changes: 0 additions & 3 deletions packages/plugins/SwitchLogo/src/settings.ts

This file was deleted.

58 changes: 10 additions & 48 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.