refactor: workspace senders

This commit is contained in:
tiddlygit-test 2021-02-05 00:07:53 +08:00
parent 005f163475
commit 96c2ebc986
20 changed files with 74 additions and 125 deletions

View file

@ -1,7 +1,8 @@
import { app, ipcMain, session } from 'electron';
import { app, ipcMain, session, dialog } from 'electron';
import { injectable, inject } from 'inversify';
import serviceIdentifier from '@services/serviceIdentifier';
import i18n from '@services/libs/i18n';
import type { IViewService } from '@services/view/interface';
import type { IWorkspaceService, IWorkspace } from '@services/workspaces/interface';
import type { IWindowService } from '@services/windows/interface';
@ -22,10 +23,6 @@ export class WorkspaceView implements IWorkspaceViewService {
}
private initIPCHandlers(): void {
ipcMain.handle('request-create-workspace', async (_event, workspaceOptions: IWorkspace) => {
await this.createWorkspaceView(workspaceOptions);
this.menuService.buildMenu();
});
ipcMain.handle('request-set-active-workspace', async (_event, id) => {
if (this.workspaceService.get(id) !== undefined) {
await this.setActiveWorkspaceView(id);
@ -169,6 +166,25 @@ export class WorkspaceView implements IWorkspaceViewService {
this.viewService.removeView(id);
}
public async clearBrowsingDataWithConfirm(): Promise<void> {
const availableWindowToShowDialog = this.windowService.get(WindowNames.preferences) ?? this.windowService.get(WindowNames.main);
if (availableWindowToShowDialog !== undefined) {
await dialog
.showMessageBox(availableWindowToShowDialog, {
type: 'question',
buttons: [i18n.t('Preference.ResetNow'), i18n.t('Cancel')],
message: i18n.t('Preference.ClearBrowsingDataMessage'),
cancelId: 1,
})
.then(({ response }) => {
if (response === 0) {
return this.clearBrowsingData();
}
})
.catch(console.error);
}
}
public async clearBrowsingData(): Promise<void> {
await session.defaultSession.clearStorageData();
const workspaces = this.workspaceService.getWorkspaces();

View file

@ -15,6 +15,7 @@ export interface IWorkspaceViewService {
setActiveWorkspaceView(id: string): Promise<void>;
removeWorkspaceView(id: string): Promise<void>;
clearBrowsingData(): Promise<void>;
clearBrowsingDataWithConfirm(): Promise<void>;
/**
* Try load url, if no id or no active workspace, then nothing will happened
* @param url url to load
@ -34,6 +35,7 @@ export const WorkspaceViewServiceIPCDescriptor = {
setActiveWorkspaceView: ProxyPropertyType.Function,
removeWorkspaceView: ProxyPropertyType.Function,
clearBrowsingData: ProxyPropertyType.Function,
clearBrowsingDataWithConfirm: ProxyPropertyType.Function,
loadURL: ProxyPropertyType.Function,
realignActiveWorkspace: ProxyPropertyType.Function,
},