This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ceb-messaging-adapter-electron): handle the
MESSAGE_TYPE
stati…
…c field of `Message`
- Loading branch information
Showing
23 changed files
with
156 additions
and
130 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
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
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
59 changes: 25 additions & 34 deletions
59
packages/ceb-messaging-adapter-electron/src/__TEST/main.ts
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 |
---|---|---|
@@ -1,41 +1,32 @@ | ||
import {ipcMain, webContents} from 'electron' | ||
import {ipcMain} from 'electron' | ||
import {assert} from "chai"; | ||
import {SimpleModule} from "@tmorin/ceb-messaging-simple"; | ||
import {IpcMainBus} from "../bus-main"; | ||
import {InMemorySimpleBus} from "@tmorin/ceb-messaging-simple"; | ||
import {CommandA, CommandB, FromMainEvent, FromRendererEvent, ResultA, ResultB} from "./fixture"; | ||
import {ElectronModule} from "../inversion"; | ||
import {ContainerBuilder} from "@tmorin/ceb-inversion"; | ||
import {Bus, BusSymbol} from "@tmorin/ceb-messaging-core"; | ||
|
||
function log(text: string) { | ||
webContents.getAllWebContents().forEach(webContent => webContent | ||
.send("main-log", `${text}`)) | ||
} | ||
const parent = new InMemorySimpleBus() | ||
const ipcBus = new IpcMainBus(parent, ipcMain) | ||
|
||
ContainerBuilder.get() | ||
.module(new SimpleModule()) | ||
.module(new ElectronModule()) | ||
.build() | ||
.initialize() | ||
.then(_container => { | ||
const ipcBus = _container.registry.resolve<Bus>(BusSymbol) | ||
// function log(text: string) { | ||
// webContents.getAllWebContents().forEach(webContent => webContent | ||
// .send("main-log", `${text}`)) | ||
// } | ||
|
||
ipcMain.on("execute-CommandB", async (event) => { | ||
try { | ||
const resultB = await ipcBus.execute(new CommandB("World"), ResultB) | ||
assert.ok(resultB) | ||
assert.equal(resultB.body, "Hello, World!") | ||
event.reply("execute-CommandB-ok") | ||
} catch (error) { | ||
event.reply("execute-CommandB-ko", error) | ||
} | ||
}) | ||
ipcMain.on("execute-CommandB", async (event) => { | ||
try { | ||
const resultB = await ipcBus.execute(new CommandB("World"), ResultB) | ||
assert.ok(resultB) | ||
assert.equal(resultB.body, "Hello, World!") | ||
event.reply("execute-CommandB-ok") | ||
} catch (error) { | ||
event.reply("execute-CommandB-ko", error) | ||
} | ||
}) | ||
|
||
ipcBus.subscribe<FromRendererEvent>(FromRendererEvent, (message) => { | ||
return ipcBus.publish(new FromMainEvent(`main[ ${message.body} ]`)) | ||
}) | ||
ipcBus.subscribe<FromRendererEvent>(FromRendererEvent, (message) => { | ||
return ipcBus.publish(new FromMainEvent(`main[ ${message.body} ]`)) | ||
}) | ||
|
||
ipcBus.handle<CommandA, ResultA>(CommandA, ResultA, async (command: CommandA): Promise<ResultA> => { | ||
return ResultA.createFromCommand(command, `Hello, ${command.body}!`) | ||
}) | ||
}) | ||
.catch(error => log(`contaier failed to start: ${error.name} ${error.message}`)) | ||
ipcBus.handle<CommandA, ResultA>(CommandA, ResultA, async (command: CommandA): Promise<ResultA> => { | ||
return ResultA.createFromCommand(command, `Hello, ${command.body}!`) | ||
}) |
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
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
Oops, something went wrong.