Skip to content

Commit

Permalink
#278 initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor44 committed May 5, 2024
1 parent 173c630 commit fa1d69c
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 7 deletions.
7 changes: 7 additions & 0 deletions packages/app/src/app-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions packages/app/src/app/duck.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion packages/app/src/app/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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)
]);
Expand Down
25 changes: 20 additions & 5 deletions packages/app/src/applications/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -51,6 +52,7 @@ import LazyWebview from './LazyWebview';
import { withGetApplicationState } from './[email protected]';
import { getApplicationDescription } from './selectors';
import { ApplicationImmutable } from './types';
// @ts-ignore no declaration file
import { getForeFrontNavigationStateProperty } from './utils';

type WebviewMethod = (webview: ElectronWebview) => void;
Expand Down Expand Up @@ -97,6 +99,7 @@ export interface OwnProps {
loading: boolean,
manifestURL: Maybe<string>,
applicationId: string,
appstoreApplicationId: string,

applicationName: Maybe<string>,
applicationIcon: Maybe<string>,
Expand Down Expand Up @@ -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());
});
}
}
Expand All @@ -403,14 +404,27 @@ 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,
promptBasicAuth, performBasicAuth, basicAuthInfo,
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 (
<div>
<div
Expand Down Expand Up @@ -487,6 +501,7 @@ const Application = compose(

return {
manifestURL: application.manifestURL(),
appstoreApplicationId: application.appstoreApplicationId(),
applicationId: data.variables.applicationId,
applicationName: manifestData.name(),
applicationIcon: manifestData.interpretedIconURL(),
Expand Down
8 changes: 8 additions & 0 deletions packages/app/src/services/services/session/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ 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<SessionProviderService> {
// @ts-ignore
disableSslCertVerification(partition: string) : Promise<void> {}
}

@service('session')
export class SessionService extends ServiceBase implements RPC.Interface<SessionService> {
// ⚠️This class will also have to handle WhatsApp User-Agent
Expand All @@ -13,4 +19,6 @@ export class SessionService extends ServiceBase implements RPC.Interface<Session
getUserAgent(): Promise<string> {}
// @ts-ignore
getCookies(filter: Electron.CookiesGetFilter): Promise<Electron.Cookie[]> {}
// @ts-ignore
disableSslCertVerification(partition: string) : Promise<void> {}
}
7 changes: 6 additions & 1 deletion packages/app/src/services/services/session/main.ts
Original file line number Diff line number Diff line change
@@ -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<SessionService> {
private session?: Electron.Session;
private provider?: RPC.Node<SessionProviderService>;

constructor(uuid?: string, options?: SessionOptions) {
super(uuid, { ready: false });
Expand All @@ -16,6 +17,10 @@ export class SessionServiceImpl extends SessionService implements RPC.Interface<
});
}

init(provider: RPC.Node<SessionProviderService>) {
this.provider = provider;
}

async getUserAgent(): Promise<string> {
const session = await this.getSession();
return session.getUserAgent();
Expand Down
18 changes: 18 additions & 0 deletions packages/app/src/services/services/session/worker.ts
Original file line number Diff line number Diff line change
@@ -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<SessionProviderService> {
store: StationStoreWorker;

constructor(store: StationStoreWorker, uuid?: string) {
super(uuid);
this.store = store;
}

async disableSslCertVerification(partition: string) {
this.store.dispatch(disableSslCertVerification(partition));
}
}

0 comments on commit fa1d69c

Please sign in to comment.