Skip to content

Commit

Permalink
revert: incorrect rpc change (#6888)
Browse files Browse the repository at this point in the history
* Revert "fix: mv3 breaks (#6872)"

This reverts commit b681c3d.

* Revert "refactor: migrate the rest (#6871)"

This reverts commit e80e6dc.
  • Loading branch information
nuanyang233 authored Jul 26, 2022
1 parent a331ae0 commit d62a0ee
Show file tree
Hide file tree
Showing 65 changed files with 372 additions and 375 deletions.
8 changes: 2 additions & 6 deletions packages/dashboard/src/initialization/PluginHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Emitter } from '@servie/events'
import { startPluginDashboard, Plugin } from '@masknet/plugin-infra/dashboard'
import { createI18NBundle, i18NextInstance } from '@masknet/shared-base'
import { Services, Messages } from '../API'
import { createPartialSharedUIContext } from '../../../mask/shared/plugin-infra/host'
import { RestPartOfPluginUIContextShared } from '../../../mask/src/utils/plugin-context-shared-ui'
import { createSharedContext } from '../../../mask/src/plugin-infra/host'

const PluginHost: Plugin.__Host.Host<Plugin.Dashboard.DashboardContext> = {
minimalMode: {
Expand All @@ -17,10 +16,7 @@ const PluginHost: Plugin.__Host.Host<Plugin.Dashboard.DashboardContext> = {
addI18NResource(plugin, resource) {
createI18NBundle(plugin, resource)(i18NextInstance)
},
createContext: (id, signal) => ({
...createPartialSharedUIContext(id, signal),
...RestPartOfPluginUIContextShared,
}),
createContext: createSharedContext,
}
setTimeout(() => {
Messages.events.pluginMinimalModeChanged.on(([id, status]) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/.webpack/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export function createConfiguration(rawFlags: BuildFlags): Configuration {
}
plugins.push(new WebExtensionPlugin({ background: { entry: 'background', manifest: 3 } }))
} else {
entries.background = normalizeEntryDescription(join(__dirname, '../background/mv2-entry.ts'))
entries.background = normalizeEntryDescription(join(__dirname, '../src/background-service.ts'))
plugins.push(new WebExtensionPlugin({ background: { entry: 'background', manifest: 2 } }))
plugins.push(
addHTMLEntry({
Expand Down
1 change: 0 additions & 1 deletion packages/mask/background/mv2-entry.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/mask/background/mv3-entry.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
import './setup'
import './services/setup'
import './tasks/setup'
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export async function requestExtensionPermission(permission: browser.permissions
try {
return await browser.permissions.request(permission)
} catch {
// which means we're on Firefox or Manifest V3.
// Chrome Manifest v2 allows permission request from the background.
// which means we're on Firefox.
// Chrome allows permission request from the background.
}
const popup = await browser.windows.create({
height: 600,
Expand Down
27 changes: 15 additions & 12 deletions packages/mask/background/services/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ setup('Identity', () => import(/* webpackPreload: true */ './identity'))
setup('Backup', () => import(/* webpackPreload: true */ './backup'))
setup('Helper', () => import(/* webpackPreload: true */ './helper'))
setup('SocialNetwork', () => import(/* webpackPreload: true */ './site-adaptors'))
setup('Settings', () => import(/* webpackPreload: true */ './settings'), false)
setup('Settings', () => import(/* webpackPreload: true */ './settings'))
setup('ThirdPartyPlugin', () => import(/* webpackPreload: true */ './third-party-plugins'))

if (import.meta.webpackHot) {
Expand All @@ -32,13 +32,13 @@ if (import.meta.webpackHot) {
import.meta.webpackHot.accept(['./third-party-plugins'], () => hmr.dispatchEvent(new Event('thirdPartyPlugin')))
}

function setup<K extends keyof Services>(key: K, implementation: () => Promise<Services[K]>, hasLog = true) {
function setup<K extends keyof Services>(key: K, implementation: () => Promise<Services[K]>) {
const channel = message.events[key].bind(MessageTarget.Broadcast)

async function load() {
const val = await getLocalImplementation(true, `Services.${key}`, implementation, channel)
if (debugMode) {
Reflect.defineProperty(globalThis, key + 'Service', { configurable: true, enumerable: true, value: val })
Reflect.defineProperty(globalThis, key + 'Service', { configurable: true, value: val })
}
return val
}
Expand All @@ -49,15 +49,18 @@ function setup<K extends keyof Services>(key: K, implementation: () => Promise<S
key,
serializer,
channel,
log: hasLog
? {
beCalled: true,
remoteError: false,
type: 'pretty',
requestReplay: debugMode,
}
: false,
strict: true,
log: {
beCalled: true,
remoteError: false,
type: 'pretty',
requestReplay: debugMode,
},
preferLocalImplementation: true,
strict: {
// temporally
methodNotFound: false,
unknownMessage: true,
},
thenable: false,
})
}
Expand Down
24 changes: 7 additions & 17 deletions packages/mask/background/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,14 @@ import type * as Helper from './helper'
import type * as Backup from './backup'
import type * as Identity from './identity'
import type * as Settings from './settings'
import type * as SocialNetwork from './site-adaptors'
import type * as ThirdPartyPlugin from './third-party-plugins'

export type CryptoService = typeof Crypto
export type IdentityService = typeof Identity
export type BackupService = typeof Backup
export type HelperService = typeof Helper
export type SettingsService = typeof Settings
export type SocialNetworkService = typeof SocialNetwork
export type ThirdPartyPluginService = typeof ThirdPartyPlugin
export interface Services {
Crypto: CryptoService
Identity: IdentityService
Backup: BackupService
Helper: HelperService
Settings: SettingsService
SocialNetwork: SocialNetworkService
ThirdPartyPlugin: ThirdPartyPluginService
Crypto: Omit<typeof Crypto, 'decryptionWithSocialNetworkDecoding'>
Identity: typeof Identity
Backup: typeof Backup
Helper: typeof Helper
SocialNetwork: {}
Settings: typeof Settings
ThirdPartyPlugin: {}
}
export type GeneratorServices = {
decryption: typeof decryptionWithSocialNetworkDecoding
Expand Down
3 changes: 0 additions & 3 deletions packages/mask/background/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { inMemory_KVStorageBackend, indexedDB_KVStorageBackend } from './databas
import { setupLegacySettingsAtBackground } from '../shared/legacy-settings/createSettings'
import { __deprecated__getStorage, __deprecated__setStorage } from './utils/deprecated-storage'

import './services/setup'
import './tasks/setup' // Setup Tasks
import '../shared/site-adaptors'
import '../shared/native-rpc' // setup Android and iOS API server

polyfill()
setupMaskKVStorageBackend(indexedDB_KVStorageBackend, inMemory_KVStorageBackend)
Expand Down
58 changes: 0 additions & 58 deletions packages/mask/shared/plugin-infra/host.ts

This file was deleted.

44 changes: 0 additions & 44 deletions packages/mask/shared/plugin-infra/register.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/mask/shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
"lib": ["ES2021"]
},
"include": ["./"],
"exclude": ["./plugin-infra/register.js"],
"references": [{ "path": "../../shared-base" }, { "path": "../../plugin-infra" }]
}
7 changes: 7 additions & 0 deletions packages/mask/src/background-service.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
import '../background/setup'
import './extension/service' // setup Services.*
import '../shared/native-rpc' // setup Android and iOS API server
import './extension/background-script/Jobs' // start jobs

// ! We should gradually stop using i18n in the background
import { addMaskI18N } from '../shared-ui/locales/languages'
import { i18NextInstance } from '@masknet/shared-base'
addMaskI18N(i18NextInstance)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Fragment, useEffect, useReducer } from 'react'
import { extractTextFromTypedMessage, TypedMessage } from '@masknet/typed-message'
import type { ProfileIdentifier } from '@masknet/shared-base'

import Services, { GeneratorServices } from '../../../extension/service'
import Services, { ServicesWithProgress } from '../../../extension/service'
import type { DecryptionProgress, FailureDecryption, SuccessDecryption } from './types'
import { DecryptPostSuccess } from './DecryptedPostSuccess'
import { DecryptPostAwaiting } from './DecryptPostAwaiting'
Expand Down Expand Up @@ -199,7 +199,7 @@ async function makeProgress(
currentSocialNetwork: activatedSocialNetworkUI.encryptionNetwork,
}
let iv: Uint8Array | undefined
for await (const progress of GeneratorServices.decryption(payload, context)) {
for await (const progress of ServicesWithProgress.decryptionWithSocialNetworkDecoding(payload, context)) {
if (signal.aborted) return
if (progress.type === DecryptProgressKind.Success) {
done(progress.content, iv || new Uint8Array())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { startPluginWorker, Plugin } from '@masknet/plugin-infra/background-worker'
import { createPluginDatabase } from '../../database/plugin-db'
import { createPluginHost, createSharedContext } from '../../../shared/plugin-infra/host'
import { getPluginMinimalModeEnabled } from '../../services/settings/old-settings-accessor'

import { createPluginDatabase } from '../../../../background/database/plugin-db'
import { createPluginHost, createSharedContext } from '../../../plugin-infra/host'
export default function (signal: AbortSignal) {
startPluginWorker(createPluginHost(signal, createWorkerContext, getPluginMinimalModeEnabled))
startPluginWorker(createPluginHost(signal, createWorkerContext))
}

function createWorkerContext(pluginID: string, signal: AbortSignal): Plugin.Worker.WorkerContext {
Expand Down
2 changes: 2 additions & 0 deletions packages/mask/src/extension/background-script/Jobs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './index_hmr'
import '../../../../background/tasks/setup'
12 changes: 12 additions & 0 deletions packages/mask/src/extension/background-script/Jobs/index_hmr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Define new task at packages/mask/background/tasks/setup.hmr.ts if possible.
import * as PluginWorker from './StartPluginWorker'

type CancelableJob = { default: (signal: AbortSignal) => void }
const CancelableJobs: CancelableJob[] = [PluginWorker]

const abort = new AbortController()
CancelableJobs.map((x) => x.default(abort.signal))
if (import.meta.webpackHot) {
import.meta.webpackHot.dispose(() => abort.abort())
import.meta.webpackHot.accept()
}
14 changes: 2 additions & 12 deletions packages/mask/src/extension/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import { WalletRPC, WalletMessages } from '../../plugins/Wallet/messages'
// import { PluginTraderMessages, PluginTraderRPC } from '../../plugins/Trader/messages'
// import { PluginPetMessages } from '../../plugins/Pets/messages'
import { MaskMessages } from '../../utils/messages'
import { createPluginHost, createPartialSharedUIContext } from '../../../shared/plugin-infra/host'
import { createPluginHost, createSharedContext } from '../../plugin-infra/host'
import type { DashboardPluginMessages, DashboardPluginServices } from '@masknet/shared'
import { createNormalReactRoot } from '../../utils/createNormalReactRoot'
import { status } from '../../setup.ui'
import { PluginTransakMessages } from '../../plugins/Transak/messages'
import { PluginTraderMessages } from '../../plugins/Trader/messages'
import { RestPartOfPluginUIContextShared } from '../../utils/plugin-context-shared-ui'

const msg: DashboardPluginMessages = {
Wallet: WalletMessages,
Expand All @@ -33,14 +32,5 @@ setMessages(MaskMessages)
setPluginServices(rpc)
// @ts-ignore
setPluginMessages(msg)
startPluginDashboard(
createPluginHost(
undefined,
(id, signal) => ({
...createPartialSharedUIContext(id, signal),
...RestPartOfPluginUIContextShared,
}),
Services.Settings.getPluginMinimalModeEnabled,
),
)
startPluginDashboard(createPluginHost(undefined, createSharedContext))
status.then(() => createNormalReactRoot(<IntegratedDashboard />))
2 changes: 1 addition & 1 deletion packages/mask/src/extension/popups/SSR-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (location.hash === '#/personas') {
})
import(/* webpackPreload: true */ './normal-client')
} else {
import(/* webpackPreload: true */ './normal-client').then(() => console.log('then'))
import(/* webpackPreload: true */ './normal-client')
}

// this function is never called, but it will hint webpack to preload modules we need
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/src/extension/popups/SSR-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function PopupSSR(props: PopupSSR_Props) {
nickname={props.nickname}
/>
) : (
<NormalHeader onClose={noop} />
<NormalHeader />
)}
<PersonaHomeUI
fetchProofsLoading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Web3Helper,
useProviderType,
} from '@masknet/plugin-infra/web3'
import { currentMaskWalletAccountSettings } from '../../../../../shared/legacy-settings/wallet-settings'
import { currentMaskWalletAccountSettings } from '../../../../plugins/Wallet/settings'
import { ChainIcon, useMenuConfig, WalletIcon } from '@masknet/shared'
import { ArrowDownRound } from '@masknet/icons'
import { WalletRPC } from '../../../../plugins/Wallet/messages'
Expand Down
Loading

0 comments on commit d62a0ee

Please sign in to comment.