-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
962e303
commit 449b3b7
Showing
10 changed files
with
74 additions
and
2 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
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 @@ | ||
export * from './ping'; |
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,7 @@ | ||
import type {PingParams, PingResult} from '@shared/ipc'; | ||
|
||
export async function ping({context, kubeconfig}: PingParams): Promise<PingResult> { | ||
// eslint-disable-next-line no-console | ||
console.log('fake ping for', context, kubeconfig); | ||
return {ok: false}; | ||
} |
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,4 @@ | ||
import {handleIpc} from '../../utils/ipc'; | ||
import {ping} from './handlers/ping'; | ||
|
||
handleIpc('cluster:ping', ping); |
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,15 @@ | ||
import {ipcMain} from 'electron'; | ||
|
||
import {IpcResult} from '@shared/ipc'; | ||
|
||
export async function handleIpc<Params, Result>(channel: string, handler: (params: Params) => Result) { | ||
ipcMain.handle(channel, async (_, params: Params): Promise<IpcResult> => { | ||
try { | ||
const payload = await handler(params); | ||
return {success: true, payload}; | ||
} catch (err) { | ||
const msg = err instanceof Error ? err.message : 'error_unknown'; | ||
return {success: false, reason: msg}; | ||
} | ||
}); | ||
} |
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,16 @@ | ||
import {invokeIpc} from '@utils/ipc'; | ||
|
||
import type {PingParams, PingResult} from '@shared/ipc'; | ||
|
||
/** | ||
* Example usage: | ||
* | ||
* ``` | ||
* try { | ||
* const { ok } = await ping({ context: "minikube" }) | ||
* } catch (err) { | ||
* console.log(err); | ||
* } | ||
* ``` | ||
*/ | ||
export const ping = invokeIpc<PingParams, PingResult>('cluster:ping'); |
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,8 @@ | ||
export type PingParams = { | ||
context: string; | ||
kubeconfig?: string; | ||
}; | ||
|
||
export type PingResult = { | ||
ok: boolean; | ||
}; |
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,3 @@ | ||
export type IpcResult = IpcSuccess | IpcFailure; | ||
export type IpcSuccess = {success: true; payload: any}; | ||
export type IpcFailure = {success: false; reason: string}; |
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,2 @@ | ||
export * from './cluster'; | ||
export * from './core'; |
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