From fa1d69c28fb7a6197bf135eb64e318f19f4e9052 Mon Sep 17 00:00:00 2001 From: Victor Date: Sun, 5 May 2024 16:54:28 +0200 Subject: [PATCH 1/6] #278 initial commit --- packages/app/src/app-worker.ts | 7 ++++++ packages/app/src/app/duck.js | 9 +++++++ packages/app/src/app/sagas.js | 13 +++++++++- packages/app/src/applications/Application.tsx | 25 +++++++++++++++---- .../services/services/session/interface.ts | 8 ++++++ .../app/src/services/services/session/main.ts | 7 +++++- .../src/services/services/session/worker.ts | 18 +++++++++++++ 7 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 packages/app/src/services/services/session/worker.ts diff --git a/packages/app/src/app-worker.ts b/packages/app/src/app-worker.ts index 1b7e7b1e..c6837478 100644 --- a/packages/app/src/app-worker.ts +++ b/packages/app/src/app-worker.ts @@ -42,6 +42,8 @@ import { AutolaunchProviderServiceImpl } from './services/services/autolaunch/au import { ManifestServiceImpl } from './services/services/manifest/main'; import { IMenuServiceObserverOnClickItemParam } from './services/services/menu/interface'; import { SDKv2ServiceImpl } from './services/services/sdkv2/worker'; +import { SessionServiceImpl } from './services/services/session/main'; +import { SessionProviderServiceImpl } from './services/services/session/worker'; import services from './services/servicesManager'; import { configureStore } from './store/configureStore.worker'; import { BasicAuthDetailsProviderServiceImpl } from './tab-webcontents/basicAuthDetailsProvider'; @@ -90,6 +92,7 @@ export class BrowserXAppWorker { this.initWebContentsOverrideProvider().catch(handleError()); this.initSDKv2(); this.initAutoLaunch().catch(handleError()); + this.initSessionService(); } catch (e) { handleError()(e); remote.app.exit(1); @@ -394,6 +397,10 @@ export class BrowserXAppWorker { return services.autolaunch.setAutolaunchProvider(new AutolaunchProviderServiceImpl(this.store)); } + private initSessionService() { + (services.defaultSession as SessionServiceImpl).init(new SessionProviderServiceImpl(this.store)) + } + private dispatch(action: any) { return this.store.dispatch(action); } diff --git a/packages/app/src/app/duck.js b/packages/app/src/app/duck.js index 5a064bf4..cc0b191c 100644 --- a/packages/app/src/app/duck.js +++ b/packages/app/src/app/duck.js @@ -32,6 +32,7 @@ export const OPEN_PROCESS_MANAGER = 'browserX/app/OPEN_PROCESS_MANAGER'; export const TOGGLE_PROMPT_DOWNLOAD = 'browserX/app/TOGGLE_PROMPT_DOWNLOAD'; export const SET_APP_METADATA = 'browserX/app/SET_APP_METADATA'; +export const DISABLE_SSL_CERT_VERIFICATION = 'browserX/app/DISABLE_SSL_CERT_VERIFICATION'; // Action creators export const ready = () => ({ type: READY }); @@ -133,6 +134,11 @@ export const setAppMetadata = (metadata) => { }; }; +export const disableSslCertVerification = (partition) => ({ + type: DISABLE_SSL_CERT_VERIFICATION, + partition, +}); + // Reducer export default function app(state = new Map(), action) { switch (action.type) { @@ -178,6 +184,9 @@ export default function app(state = new Map(), action) { case TOGGLE_PROMPT_DOWNLOAD: return state.set('promptDownload', Boolean(action.promptDownload)); + case DISABLE_SSL_CERT_VERIFICATION: + return state.set('disableSslCertVerification', action.partition); + case SET_APP_METADATA: return state .set('appName', action.name) diff --git a/packages/app/src/app/sagas.js b/packages/app/src/app/sagas.js index c38fa85c..eb863ad5 100644 --- a/packages/app/src/app/sagas.js +++ b/packages/app/src/app/sagas.js @@ -36,7 +36,8 @@ import { setLoadingScreenVisibility, TOGGLE_PROMPT_DOWNLOAD, TOGGLE_KBD_SHORTCUTS, - TOGGLE_MAXIMIZE + TOGGLE_MAXIMIZE, + DISABLE_SSL_CERT_VERIFICATION, } from './duck'; import { DELAY } from '../persistence/backend'; import { getWindowCurrentTabId } from '../windows/get'; @@ -249,6 +250,15 @@ function* sagaHandleOpenProcessManager() { yield callService('processManager', 'open', undefined); } +function* sagaDisableSslCertVerification() { + + + require('electron-log').info('>>>>>>>>>>>', process.type); + + + +} + /** * Will load the app metadata in the state. */ @@ -275,6 +285,7 @@ export default function* main(bxApp) { takeEveryWitness(TOGGLE_KBD_SHORTCUTS, sagaToggleKbdShortcutsOverlay), takeEveryWitness(CHANGE_APP_FOCUS_STATE, onChangeAppFocusState), takeEveryWitness(OPEN_PROCESS_MANAGER, sagaHandleOpenProcessManager), + takeEveryWitness(DISABLE_SSL_CERT_VERIFICATION, sagaDisableSslCertVerification), // For dev purpose takeEveryWitness('STATION_MANUAL_ERR', sagaTriggerError) ]); diff --git a/packages/app/src/applications/Application.tsx b/packages/app/src/applications/Application.tsx index e7a34f3b..7545d5f0 100644 --- a/packages/app/src/applications/Application.tsx +++ b/packages/app/src/applications/Application.tsx @@ -7,7 +7,8 @@ import { GradientType, withGradient } from '@getstation/theme'; import ElectronWebview from '../common/components/ElectronWebview'; import * as classNames from 'classnames'; import { clipboard } from 'electron'; -import * as remote from '@electron/remote'; +import services from '../services/servicesManager'; +// import * as remote from '@electron/remote'; // @ts-ignore no declaration file import { fetchFavicon, setFetchFaviconTimeout } from '@getstation/fetch-favicon'; import Maybe from 'graphql/tsutils/Maybe'; @@ -51,6 +52,7 @@ import LazyWebview from './LazyWebview'; import { withGetApplicationState } from './queries@local.gql.generated'; import { getApplicationDescription } from './selectors'; import { ApplicationImmutable } from './types'; +// @ts-ignore no declaration file import { getForeFrontNavigationStateProperty } from './utils'; type WebviewMethod = (webview: ElectronWebview) => void; @@ -97,6 +99,7 @@ export interface OwnProps { loading: boolean, manifestURL: Maybe, applicationId: string, + appstoreApplicationId: string, applicationName: Maybe, applicationIcon: Maybe, @@ -388,12 +391,10 @@ class ApplicationImpl extends React.PureComponent { const webview = this.webView.view; webview.addEventListener('dom-ready', () => { - const webContents = remote.webContents.fromId(webview.getWebContentsId()); - webview.addEventListener('did-navigate-in-page', (e: any) => this.handleDidNavigateInPage(e)); webview.addEventListener('did-navigate', (e: any) => this.handleDidNavigate(e)); webview.addEventListener('ipc-message', (e: any) => this.handleIPCMessage(e)); - this.props.onWebcontentsAttached(webContents.id); + this.props.onWebcontentsAttached(webview.getWebContentsId()); }); } } @@ -403,7 +404,8 @@ class ApplicationImpl extends React.PureComponent { const useNativeWindowOpen = !this.props.notUseNativeWindowOpen; const tabUrl = tab.get('url', ''); const { - applicationId, applicationName, applicationIcon, themeColor, manifestURL, + applicationId, applicationName, applicationIcon, + appstoreApplicationId, themeColor, manifestURL, askResetApplication, onChooseAccount, crashed, errorCode, errorDescription, canGoBack, themeGradient, email, @@ -411,6 +413,18 @@ class ApplicationImpl extends React.PureComponent { useDefaultSession, } = this.props; + const partition = useDefaultSession ? '' : `persist:${applicationId}`; + + // disable SSL check for private applications + if (!useDefaultSession && Number(appstoreApplicationId) > 1000000) { + services.defaultSession.disableSslCertVerification(partition); + + // const appSession = remote.session.fromPartition(partition); + // appSession.setCertificateVerifyProc((_, callback) => { + // callback(0); + // }) + } + return (
{ + // @ts-ignore + disableSslCertVerification(partition: string) : Promise {} +} + @service('session') export class SessionService extends ServiceBase implements RPC.Interface { // ⚠️This class will also have to handle WhatsApp User-Agent @@ -13,4 +19,6 @@ export class SessionService extends ServiceBase implements RPC.Interface {} // @ts-ignore getCookies(filter: Electron.CookiesGetFilter): Promise {} + // @ts-ignore + disableSslCertVerification(partition: string) : Promise {} } diff --git a/packages/app/src/services/services/session/main.ts b/packages/app/src/services/services/session/main.ts index 7be81844..3272912a 100644 --- a/packages/app/src/services/services/session/main.ts +++ b/packages/app/src/services/services/session/main.ts @@ -1,12 +1,13 @@ import * as Electron from 'electron'; import { waitDefaultSession } from '../../api/sessions'; import { RPC } from '../../lib/types'; -import { SessionService } from './interface'; +import { SessionService, SessionProviderService } from './interface'; export type SessionOptions = { partition: string }; export class SessionServiceImpl extends SessionService implements RPC.Interface { private session?: Electron.Session; + private provider?: RPC.Node; constructor(uuid?: string, options?: SessionOptions) { super(uuid, { ready: false }); @@ -16,6 +17,10 @@ export class SessionServiceImpl extends SessionService implements RPC.Interface< }); } + init(provider: RPC.Node) { + this.provider = provider; + } + async getUserAgent(): Promise { const session = await this.getSession(); return session.getUserAgent(); diff --git a/packages/app/src/services/services/session/worker.ts b/packages/app/src/services/services/session/worker.ts new file mode 100644 index 00000000..30766c65 --- /dev/null +++ b/packages/app/src/services/services/session/worker.ts @@ -0,0 +1,18 @@ +// @ts-ignore: no declaration file +import { disableSslCertVerification } from '../../../app/duck'; +import { StationStoreWorker } from '../../../types'; +import { RPC } from '../../lib/types'; +import { SessionProviderService } from './interface'; + +export class SessionProviderServiceImpl extends SessionProviderService implements RPC.Interface { + store: StationStoreWorker; + + constructor(store: StationStoreWorker, uuid?: string) { + super(uuid); + this.store = store; + } + + async disableSslCertVerification(partition: string) { + this.store.dispatch(disableSslCertVerification(partition)); + } +} From 7ba466aa4fd2ea0ff2f14ff70bf22ce93ac0ef22 Mon Sep 17 00:00:00 2001 From: Victor Date: Tue, 7 May 2024 23:04:45 +0200 Subject: [PATCH 2/6] no delete data confirmation on update --- packages/app/build/installer.nsh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/app/build/installer.nsh b/packages/app/build/installer.nsh index 92905f47..5e7a4e14 100644 --- a/packages/app/build/installer.nsh +++ b/packages/app/build/installer.nsh @@ -1,9 +1,15 @@ !macro customUnInstall -MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete also user data and settings for Station?" IDNO skip -RMDir /r "$APPDATA\Station" -RMDir /r "$APPDATA\Stationv2" + ${GetParameters} $R0 + ${GetOptions} $R0 "--update" $R1 + ${If} ${Errors} -skip: + MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete also user data and settings for Station?" IDNO skip + RMDir /r "$APPDATA\Station" + RMDir /r "$APPDATA\Stationv2" + + skip: + + ${endif} !macroend From 8a2fa1a8ba9cf6d3c1049dee8ac5063d785d8181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Charles?= Date: Wed, 8 May 2024 01:21:51 +0200 Subject: [PATCH 3/6] chore: fix usage of disableSslCertVerification --- packages/app/src/app-worker.ts | 5 ----- packages/app/src/app/duck.js | 3 --- packages/app/src/app/sagas.js | 9 ++------- packages/app/src/applications/Application.tsx | 13 +++++-------- .../src/services/services/session/interface.ts | 6 ------ .../app/src/services/services/session/main.ts | 14 ++++++++------ .../src/services/services/session/worker.ts | 18 ------------------ 7 files changed, 15 insertions(+), 53 deletions(-) delete mode 100644 packages/app/src/services/services/session/worker.ts diff --git a/packages/app/src/app-worker.ts b/packages/app/src/app-worker.ts index c6837478..b2b2e1ea 100644 --- a/packages/app/src/app-worker.ts +++ b/packages/app/src/app-worker.ts @@ -92,7 +92,6 @@ export class BrowserXAppWorker { this.initWebContentsOverrideProvider().catch(handleError()); this.initSDKv2(); this.initAutoLaunch().catch(handleError()); - this.initSessionService(); } catch (e) { handleError()(e); remote.app.exit(1); @@ -397,10 +396,6 @@ export class BrowserXAppWorker { return services.autolaunch.setAutolaunchProvider(new AutolaunchProviderServiceImpl(this.store)); } - private initSessionService() { - (services.defaultSession as SessionServiceImpl).init(new SessionProviderServiceImpl(this.store)) - } - private dispatch(action: any) { return this.store.dispatch(action); } diff --git a/packages/app/src/app/duck.js b/packages/app/src/app/duck.js index cc0b191c..cc3a20d0 100644 --- a/packages/app/src/app/duck.js +++ b/packages/app/src/app/duck.js @@ -184,9 +184,6 @@ export default function app(state = new Map(), action) { case TOGGLE_PROMPT_DOWNLOAD: return state.set('promptDownload', Boolean(action.promptDownload)); - case DISABLE_SSL_CERT_VERIFICATION: - return state.set('disableSslCertVerification', action.partition); - case SET_APP_METADATA: return state .set('appName', action.name) diff --git a/packages/app/src/app/sagas.js b/packages/app/src/app/sagas.js index eb863ad5..d15d76d4 100644 --- a/packages/app/src/app/sagas.js +++ b/packages/app/src/app/sagas.js @@ -250,13 +250,8 @@ function* sagaHandleOpenProcessManager() { yield callService('processManager', 'open', undefined); } -function* sagaDisableSslCertVerification() { - - - require('electron-log').info('>>>>>>>>>>>', process.type); - - - +function* sagaDisableSslCertVerification({ partition }) { + yield callService('defaultSession', 'disableSslCertVerification', partition); } /** diff --git a/packages/app/src/applications/Application.tsx b/packages/app/src/applications/Application.tsx index 7545d5f0..2ad9d8f8 100644 --- a/packages/app/src/applications/Application.tsx +++ b/packages/app/src/applications/Application.tsx @@ -7,7 +7,6 @@ import { GradientType, withGradient } from '@getstation/theme'; import ElectronWebview from '../common/components/ElectronWebview'; import * as classNames from 'classnames'; import { clipboard } from 'electron'; -import services from '../services/servicesManager'; // import * as remote from '@electron/remote'; // @ts-ignore no declaration file import { fetchFavicon, setFetchFaviconTimeout } from '@getstation/fetch-favicon'; @@ -42,6 +41,7 @@ import { } from '../tab-webcontents/duck'; import { getTabWebcontentsById, getWebcontentsAuthInfo, getWebcontentsAuthState } from '../tab-webcontents/selectors'; import { updateLoadingState, updateTabBadge, updateTabFavicons, updateTabTitle, updateTabURL } from '../tabs/duck'; +import { disableSslCertVerification } from '../app/duck'; import { getTabId, getTabLoadingState } from '../tabs/get'; import { StationTabImmutable } from '../tabs/types'; import { RecursiveImmutableMap, StationState } from '../types'; @@ -145,6 +145,7 @@ export interface DispatchProps { onChooseAccount: Function, onApplicationRemoved: Function, updateResetAppModal: Function, + disableSslCertVerification: (partition: string) => any, } export interface ComputedProps { @@ -404,7 +405,7 @@ class ApplicationImpl extends React.PureComponent { const useNativeWindowOpen = !this.props.notUseNativeWindowOpen; const tabUrl = tab.get('url', ''); const { - applicationId, applicationName, applicationIcon, + applicationId, applicationName, applicationIcon, appstoreApplicationId, themeColor, manifestURL, askResetApplication, onChooseAccount, crashed, errorCode, errorDescription, @@ -417,12 +418,7 @@ class ApplicationImpl extends React.PureComponent { // disable SSL check for private applications if (!useDefaultSession && Number(appstoreApplicationId) > 1000000) { - services.defaultSession.disableSslCertVerification(partition); - - // const appSession = remote.session.fromPartition(partition); - // appSession.setCertificateVerifyProc((_, callback) => { - // callback(0); - // }) + this.props.disableSslCertVerification(partition); } return ( @@ -564,6 +560,7 @@ const Application = compose( onChooseAccount: (identityId) => setConfigData(applicationId, { identityId }), onApplicationRemoved: uninstallApplication, updateResetAppModal: (appFocus) => updateUI('confirmResetApplicationModal', 'isVisible', appFocus), + disableSslCertVerification: disableSslCertVerification, }, dispatch ); diff --git a/packages/app/src/services/services/session/interface.ts b/packages/app/src/services/services/session/interface.ts index 7166fd63..acda258e 100644 --- a/packages/app/src/services/services/session/interface.ts +++ b/packages/app/src/services/services/session/interface.ts @@ -3,12 +3,6 @@ import { ServiceBase } from '../../lib/class'; import { service } from '../../lib/decorator'; import { RPC } from '../../lib/types'; -@service('session') -export class SessionProviderService extends ServiceBase implements RPC.Interface { - // @ts-ignore - disableSslCertVerification(partition: string) : Promise {} -} - @service('session') export class SessionService extends ServiceBase implements RPC.Interface { // ⚠️This class will also have to handle WhatsApp User-Agent diff --git a/packages/app/src/services/services/session/main.ts b/packages/app/src/services/services/session/main.ts index 3272912a..d0fe0596 100644 --- a/packages/app/src/services/services/session/main.ts +++ b/packages/app/src/services/services/session/main.ts @@ -1,13 +1,12 @@ import * as Electron from 'electron'; import { waitDefaultSession } from '../../api/sessions'; import { RPC } from '../../lib/types'; -import { SessionService, SessionProviderService } from './interface'; +import { SessionService } from './interface'; export type SessionOptions = { partition: string }; export class SessionServiceImpl extends SessionService implements RPC.Interface { private session?: Electron.Session; - private provider?: RPC.Node; constructor(uuid?: string, options?: SessionOptions) { super(uuid, { ready: false }); @@ -17,10 +16,6 @@ export class SessionServiceImpl extends SessionService implements RPC.Interface< }); } - init(provider: RPC.Node) { - this.provider = provider; - } - async getUserAgent(): Promise { const session = await this.getSession(); return session.getUserAgent(); @@ -31,6 +26,13 @@ export class SessionServiceImpl extends SessionService implements RPC.Interface< return session.cookies.get(filter); } + async disableSslCertVerification(partition: string) : Promise { + const session = Electron.session.fromPartition(partition); + session.setCertificateVerifyProc((_, callback) => { + callback(0); + }); + } + private async initSession(options?: SessionOptions): Promise { if (options && options.partition) { return Electron.session.fromPartition(options.partition); diff --git a/packages/app/src/services/services/session/worker.ts b/packages/app/src/services/services/session/worker.ts deleted file mode 100644 index 30766c65..00000000 --- a/packages/app/src/services/services/session/worker.ts +++ /dev/null @@ -1,18 +0,0 @@ -// @ts-ignore: no declaration file -import { disableSslCertVerification } from '../../../app/duck'; -import { StationStoreWorker } from '../../../types'; -import { RPC } from '../../lib/types'; -import { SessionProviderService } from './interface'; - -export class SessionProviderServiceImpl extends SessionProviderService implements RPC.Interface { - store: StationStoreWorker; - - constructor(store: StationStoreWorker, uuid?: string) { - super(uuid); - this.store = store; - } - - async disableSslCertVerification(partition: string) { - this.store.dispatch(disableSslCertVerification(partition)); - } -} From 7c56b1a167d6657b165366c9b42f0f87251a24d5 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 10 May 2024 01:26:16 +0200 Subject: [PATCH 4/6] Rename bx to bxApi --- .../webui/MultiInstanceConfigurator.tsx | 14 +++++++------- .../webui/components/ChooseIdentityForm.tsx | 4 ++-- .../multi-instance-configuration/webui/index.tsx | 2 +- .../app/src/notification-center/webview-preload.ts | 8 ++++---- packages/app/src/plugins/bxapi.d.ts | 2 +- .../plugins/injected-js/messengerInjectedScript.js | 2 +- .../plugins/injected-js/whatsappInjectedScript.js | 2 +- packages/app/src/plugins/webview-preload.js | 2 +- .../appstore/src/HOC/withCustomApplications.tsx | 2 +- packages/appstore/src/api.ts | 4 ++-- packages/appstore/src/app-request/sagas.ts | 2 +- packages/appstore/src/app.tsx | 4 ++-- .../AppStoreMyCustomApps/AppStoreMyCustomApps.tsx | 2 +- 13 files changed, 25 insertions(+), 25 deletions(-) diff --git a/packages/app/src/applications/multi-instance-configuration/webui/MultiInstanceConfigurator.tsx b/packages/app/src/applications/multi-instance-configuration/webui/MultiInstanceConfigurator.tsx index 07e8f36c..21d31a0e 100644 --- a/packages/app/src/applications/multi-instance-configuration/webui/MultiInstanceConfigurator.tsx +++ b/packages/app/src/applications/multi-instance-configuration/webui/MultiInstanceConfigurator.tsx @@ -10,7 +10,7 @@ import { MultiInstanceConfigPreset as Preset } from '../../manifest-provider/typ import NormalFlowForm from './components/NormalFlowForm'; import { getPresets } from '../../manifest-provider/helpers'; -const requestGoogleSignin = () => window.bx.identities.requestLogin('google'); +const requestGoogleSignin = () => window.bxApi.identities.requestLogin('google'); const { Undefined: UndefinedPreset, @@ -79,28 +79,28 @@ export default class MultiInstanceConfigurator extends React.Component { - window.bx.applications.setConfigData(this.props.applicationId, { subdomain }); + window.bxApi.applications.setConfigData(this.props.applicationId, { subdomain }); } submitIdentityForm = (identityId: string) => { - window.bx.applications.setConfigData(this.props.applicationId, { identityId }); + window.bxApi.applications.setConfigData(this.props.applicationId, { identityId }); } submitOnPremiseForm = (customURL: string) => { - window.bx.applications.setConfigData(this.props.applicationId, { customURL }); + window.bxApi.applications.setConfigData(this.props.applicationId, { customURL }); } submitNormalForm = () => { - window.bx.applications.setConfigData(this.props.applicationId, {}); + window.bxApi.applications.setConfigData(this.props.applicationId, {}); } removeApplication = () => { - window.bx.applications.uninstall(this.props.applicationId); + window.bxApi.applications.uninstall(this.props.applicationId); } componentDidMount() { const { manifestURL } = this.props; - window.bx.manifest.getManifest(manifestURL).then(({ body }) => { + window.bxApi.manifest.getManifest(manifestURL).then(({ body }) => { const manifest = body; const presets = this.getPresets(manifest); const selectedPreset = isOnlyOnPremise(presets) ? UndefinedPreset : presets[0]; diff --git a/packages/app/src/applications/multi-instance-configuration/webui/components/ChooseIdentityForm.tsx b/packages/app/src/applications/multi-instance-configuration/webui/components/ChooseIdentityForm.tsx index a2be4024..86a87db5 100644 --- a/packages/app/src/applications/multi-instance-configuration/webui/components/ChooseIdentityForm.tsx +++ b/packages/app/src/applications/multi-instance-configuration/webui/components/ChooseIdentityForm.tsx @@ -51,11 +51,11 @@ export default class ChooseIdentityForm extends React.PureComponent(); -window.bx.theme.addThemeColorsChangeListener( +window.bxApi.theme.addThemeColorsChangeListener( (_: any, result: any) => themeColorsObservable.next(result) ); diff --git a/packages/app/src/notification-center/webview-preload.ts b/packages/app/src/notification-center/webview-preload.ts index c63b357c..d0434b0e 100644 --- a/packages/app/src/notification-center/webview-preload.ts +++ b/packages/app/src/notification-center/webview-preload.ts @@ -66,7 +66,7 @@ export class BxNotification extends EventTarget('click', 'error', 'close', 'show }); this._registerIPC(); - window.bx.notificationCenter.sendNotification(this.id, { + window.bxApi.notificationCenter.sendNotification(this.id, { timestamp: this.timestamp, title: this.title, body: this.body, @@ -87,17 +87,17 @@ export class BxNotification extends EventTarget('click', 'error', 'close', 'show } close() { - window.bx.notificationCenter.closeNotification(this.id); + window.bxApi.notificationCenter.closeNotification(this.id); // ipcRenderer.send('notification-close', this.id); } _registerIPC() { - window.bx.notificationCenter.addNotificationClickListener(this._handleNotificationClickIPC); + window.bxApi.notificationCenter.addNotificationClickListener(this._handleNotificationClickIPC); // ipcRenderer.on('trigger-notification-click', this._handleNotificationClickIPC); } _unregisterIPC() { - window.bx.notificationCenter.removeNotificationClickListener(this._handleNotificationClickIPC); + window.bxApi.notificationCenter.removeNotificationClickListener(this._handleNotificationClickIPC); // ipcRenderer.removeListener('trigger-notification-click', this._handleNotificationClickIPC); } diff --git a/packages/app/src/plugins/bxapi.d.ts b/packages/app/src/plugins/bxapi.d.ts index 5d09615c..cb9f88f1 100644 --- a/packages/app/src/plugins/bxapi.d.ts +++ b/packages/app/src/plugins/bxapi.d.ts @@ -174,6 +174,6 @@ interface Bx { declare global { interface Window { - bx: Bx; + bxApi: Bx; } } diff --git a/packages/app/src/plugins/injected-js/messengerInjectedScript.js b/packages/app/src/plugins/injected-js/messengerInjectedScript.js index f04a6945..602f25e3 100644 --- a/packages/app/src/plugins/injected-js/messengerInjectedScript.js +++ b/packages/app/src/plugins/injected-js/messengerInjectedScript.js @@ -64,7 +64,7 @@ const turnOffAudioVolumeObserver = target => { let disconnectTurnOffAudioVolumeObserver; -window.bx.notificationCenter.addSnoozeDurationInMsChangeListener((_, duration) => { +window.bxApi.notificationCenter.addSnoozeDurationInMsChangeListener((_, duration) => { if (duration && !document.location.pathname.includes('/videocall/incall/')) { disconnectTurnOffAudioVolumeObserver = turnOffAudioVolumeObserver(document.body); } else { diff --git a/packages/app/src/plugins/injected-js/whatsappInjectedScript.js b/packages/app/src/plugins/injected-js/whatsappInjectedScript.js index 71e662c6..c16226a3 100644 --- a/packages/app/src/plugins/injected-js/whatsappInjectedScript.js +++ b/packages/app/src/plugins/injected-js/whatsappInjectedScript.js @@ -13,6 +13,6 @@ Audio.prototype.play = function() { return Promise.resolve(); }; -window.bx.notificationCenter.addSnoozeDurationInMsChangeListener((_, duration) => { +window.bxApi.notificationCenter.addSnoozeDurationInMsChangeListener((_, duration) => { snoozed = Boolean(duration); }); diff --git a/packages/app/src/plugins/webview-preload.js b/packages/app/src/plugins/webview-preload.js index b8890b0d..9975c17f 100644 --- a/packages/app/src/plugins/webview-preload.js +++ b/packages/app/src/plugins/webview-preload.js @@ -122,6 +122,6 @@ } }; - contextBridge.exposeInMainWorld('bx', bxApi); + contextBridge.exposeInMainWorld('bxApi', bxApi); console.log('>>>> contextBridge done') diff --git a/packages/appstore/src/HOC/withCustomApplications.tsx b/packages/appstore/src/HOC/withCustomApplications.tsx index 65e2e92d..4be9eb77 100644 --- a/packages/appstore/src/HOC/withCustomApplications.tsx +++ b/packages/appstore/src/HOC/withCustomApplications.tsx @@ -14,7 +14,7 @@ export default function withCustomApplications(Component: React.Component) }); React.useEffect(() => { - window.bx.applications.getPrivateApps().then(({ body }) => { + window.bxApi.applications.getPrivateApps().then(({ body }) => { setData({ privateApps: body.map(app => { return { diff --git a/packages/appstore/src/api.ts b/packages/appstore/src/api.ts index 28008291..dd3216ec 100644 --- a/packages/appstore/src/api.ts +++ b/packages/appstore/src/api.ts @@ -1,7 +1,7 @@ export const findApplicationByName = (applicationName: string) => { - if ('bx' in window) { - const bxApi = window.bx; + if ('bxApi' in window) { + const bxApi = window.bxApi; return bxApi.applications.search(applicationName).then(({ body }) => { return body || []; diff --git a/packages/appstore/src/app-request/sagas.ts b/packages/appstore/src/app-request/sagas.ts index 2c898a0d..05b92fa2 100644 --- a/packages/appstore/src/app-request/sagas.ts +++ b/packages/appstore/src/app-request/sagas.ts @@ -24,7 +24,7 @@ function* handleAppRequest(request: SubmitAppRequestAction): SagaIterator { }; try { - const { body } = yield call(window.bx.applications.requestPrivate, applicationRecipe); + const { body } = yield call(window.bxApi.applications.requestPrivate, applicationRecipe); yield put(setApiResponse(ApiResponse.Done)); yield put(setApplicationCreated({ id: body.id, bxAppManifestURL: body.bxAppManifestURL })); } catch (e) { diff --git a/packages/appstore/src/app.tsx b/packages/appstore/src/app.tsx index 18ae1939..505ba2d7 100644 --- a/packages/appstore/src/app.tsx +++ b/packages/appstore/src/app.tsx @@ -58,9 +58,9 @@ class AppImpl extends React.Component { // tslint:disable-next-line function-name async UNSAFE_componentWillMount() { - if ('bx' in window) { + if ('bxApi' in window) { // @ts-ignore : bx attached to window - const bxApi = window.bx; + const bxApi = window.bxApi; bxApi.theme.addThemeColorsChangeListener((_: any, themeColors: string[]) => { this.setState({ themeColors }) diff --git a/packages/appstore/src/components/AppStoreContent/AppStoreMyCustomApps/AppStoreMyCustomApps.tsx b/packages/appstore/src/components/AppStoreContent/AppStoreMyCustomApps/AppStoreMyCustomApps.tsx index cc803870..42038995 100644 --- a/packages/appstore/src/components/AppStoreContent/AppStoreMyCustomApps/AppStoreMyCustomApps.tsx +++ b/packages/appstore/src/components/AppStoreContent/AppStoreMyCustomApps/AppStoreMyCustomApps.tsx @@ -113,7 +113,7 @@ class AppStoreMyCustomApps extends React.PureComponent { - window.bx.applications.uninstallByManifest(app.bxAppManifestURL).then(() => { + window.bxApi.applications.uninstallByManifest(app.bxAppManifestURL).then(() => { this.exitFlow(false); location.reload(); }).catch((e) => { From 8100f7c172385ae9e9e067c85170f69e475d7b05 Mon Sep 17 00:00:00 2001 From: Victor Date: Sat, 11 May 2024 00:24:15 +0200 Subject: [PATCH 5/6] Rename bx to bxApi --- packages/app/src/static/preload/preload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/app/src/static/preload/preload.js b/packages/app/src/static/preload/preload.js index ac9a423f..948694a7 100644 --- a/packages/app/src/static/preload/preload.js +++ b/packages/app/src/static/preload/preload.js @@ -245,7 +245,7 @@ const postload = Object.keys(window); // List of allowed exposure on globals export const whitelist = new Set([ - 'bx', + 'bxApi', 'chrome', '_docs_chrome_extension_exists', '_docs_chrome_extension_features_version', From c456de295927e75509220fbc0016039695cc1dd0 Mon Sep 17 00:00:00 2001 From: Victor Date: Sat, 11 May 2024 01:25:38 +0200 Subject: [PATCH 6/6] code cleanup --- packages/app/src/app-worker.ts | 2 -- packages/app/src/applications/Application.tsx | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/app/src/app-worker.ts b/packages/app/src/app-worker.ts index b2b2e1ea..1b7e7b1e 100644 --- a/packages/app/src/app-worker.ts +++ b/packages/app/src/app-worker.ts @@ -42,8 +42,6 @@ import { AutolaunchProviderServiceImpl } from './services/services/autolaunch/au import { ManifestServiceImpl } from './services/services/manifest/main'; import { IMenuServiceObserverOnClickItemParam } from './services/services/menu/interface'; import { SDKv2ServiceImpl } from './services/services/sdkv2/worker'; -import { SessionServiceImpl } from './services/services/session/main'; -import { SessionProviderServiceImpl } from './services/services/session/worker'; import services from './services/servicesManager'; import { configureStore } from './store/configureStore.worker'; import { BasicAuthDetailsProviderServiceImpl } from './tab-webcontents/basicAuthDetailsProvider'; diff --git a/packages/app/src/applications/Application.tsx b/packages/app/src/applications/Application.tsx index 2ad9d8f8..2e76674a 100644 --- a/packages/app/src/applications/Application.tsx +++ b/packages/app/src/applications/Application.tsx @@ -7,7 +7,6 @@ import { GradientType, withGradient } from '@getstation/theme'; import ElectronWebview from '../common/components/ElectronWebview'; import * as classNames from 'classnames'; import { clipboard } from 'electron'; -// import * as remote from '@electron/remote'; // @ts-ignore no declaration file import { fetchFavicon, setFetchFaviconTimeout } from '@getstation/fetch-favicon'; import Maybe from 'graphql/tsutils/Maybe'; @@ -41,6 +40,7 @@ import { } from '../tab-webcontents/duck'; import { getTabWebcontentsById, getWebcontentsAuthInfo, getWebcontentsAuthState } from '../tab-webcontents/selectors'; import { updateLoadingState, updateTabBadge, updateTabFavicons, updateTabTitle, updateTabURL } from '../tabs/duck'; +// @ts-ignore no declaration file import { disableSslCertVerification } from '../app/duck'; import { getTabId, getTabLoadingState } from '../tabs/get'; import { StationTabImmutable } from '../tabs/types';