-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from qusly/core-main
feat: move core to main
- Loading branch information
Showing
6 changed files
with
74 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters