Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move core to main #62

Merged
merged 1 commit into from
Feb 20, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/main/services/core.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ipcMain } from 'electron';
import { Client } from 'qusly-core';

import { AppWindow } from '../windows';
import { ISite } from '~/interfaces';

export class Core {
public clients = new Map<number, Client>();

constructor(public appWindow: AppWindow) {
ipcMain.handle('core-create', (e, id: number) => {
if (!this.clients.has(id)) {
this.clients.set(id, new Client());
}
});

ipcMain.handle('core-connect', (e, site: ISite) => {
return this.clients.get(site.id).connect(site);
});

ipcMain.handle('core-read-dir', (e, id: number, path: string) => {
return this.clients.get(id).readDir(path);
});

ipcMain.handle('core-pwd', (e, id: number) => {
return this.clients.get(id).pwd();
});
}
}
4 changes: 3 additions & 1 deletion src/main/windows/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import { getPath } from '~/utils';
import { runAutoUpdaterService } from '../services/auto-updater';
import { runMessagingService } from '../services/messaging';
import storage from '../services/storage';
import { ConcurrentClient } from 'qusly-core';
import { Core } from '../services/core';

export class AppWindow {
public instance: BrowserWindow;

public core = new Core(this);

constructor() {
this.instance = new BrowserWindow({
// frame: false,
Expand Down
35 changes: 35 additions & 0 deletions src/renderer/app/models/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ipcRenderer } from 'electron';

import { ISite } from '~/interfaces';

export class Client {
public config: ISite;

protected created = false;

protected get id() {
return this.config.id;
}

protected async create() {
if (!this.created) {
await ipcRenderer.invoke('core-create', this.id);
this.created = true;
}
}

public async connect(config: ISite) {
this.config = config;

await this.create();
await ipcRenderer.invoke('core-connect', this.config);
}

public readDir(path: string) {
return ipcRenderer.invoke('core-read-dir', this.id, path);
}

public pwd() {
return ipcRenderer.invoke('core-pwd', this.id);
}
}
1 change: 1 addition & 0 deletions src/renderer/app/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './session';
export * from './page';
export * from './tab';
export * from './history';
export * from './client';
10 changes: 4 additions & 6 deletions src/renderer/app/models/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ export class Page {

@action
public async prepare() {
setTimeout(async () => {
await this.session.connect();
await this.fetch();
}, 100);
await this.session.connect();
await this.fetch();
}

@action
Expand All @@ -48,8 +46,8 @@ export class Page {
const path = this.history.path;

const files = await this.session.client.readDir(path);
console.log(files);
// this.files = files;

this.files = files;
this.loading = false;
}

Expand Down
5 changes: 2 additions & 3 deletions src/renderer/app/models/session.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { action } from 'mobx';
import { ConcurrentClient } from 'qusly-core';

import { ISite } from '~/interfaces';
import { Page } from './page';
import { Client } from './client';

export class Session {
public client = new ConcurrentClient(1);
public client = new Client();

public status: 'disconnected' | 'connecting' | 'connected' = 'disconnected';

Expand All @@ -18,7 +18,6 @@ export class Session {

try {
await this.client.connect(this.config);
console.log('connected');
} catch (error) {
console.log(error);
}
Expand Down