/
accounts.service.ts
68 lines (55 loc) · 1.91 KB
/
accounts.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Injectable } from '@angular/core';
import {
IPCConnect,
IPCCheckConnection
} from '../../../shared/ipc/accounts.ipc';
import { ipcRenderer } from 'electron-better-ipc';
import { IAccount } from '../../../shared/interfaces/accounts.interface';
import { LogConsoleService } from '../log-console.service';
import { ConsoleLogItemType } from '../../../shared/interfaces/log-console.interface';
import getCurrentLine from 'get-current-line';
@Injectable({
providedIn: 'root'
})
export class AccountsIPCService {
constructor(private logConsoleService:LogConsoleService) { }
public async checkConnection(account: IAccount): Promise<IPCCheckConnection.IResponse> {
const req: IPCCheckConnection.Request = new IPCCheckConnection.Request({
server: account.server,
ssh: account.ssh
});
this.logConsoleService.addItem(
ConsoleLogItemType.info,
req.toJsonValue(),
getCurrentLine().method
)
const rawRes:any = await ipcRenderer.invoke(IPCCheckConnection.CHANNEL, req.toJsonValue());
console.log("rawRes", rawRes);
this.logConsoleService.addItem(
ConsoleLogItemType.info,
rawRes,
getCurrentLine().method
)
return new IPCCheckConnection.Response(rawRes).toMessage()
}
public async connect(account: IAccount): Promise<IPCConnect.IResponse> {
console.log("connect: ", account)
const req: IPCConnect.Request = new IPCConnect.Request({
server: account.server,
ssh: account.ssh
});
this.logConsoleService.addItem(
ConsoleLogItemType.info,
req.toJsonValue(),
getCurrentLine().method
)
const rawRes:any = await ipcRenderer.invoke(IPCConnect.CHANNEL, req.toJsonValue());
this.logConsoleService.addItem(
ConsoleLogItemType.info,
rawRes,
getCurrentLine().method
)
console.log("rawRes", rawRes);
return new IPCConnect.Response(rawRes).toMessage()
}
}