mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-26 19:14:32 +02:00
Add toasts & terminal funcs to electron app
Attach functions to the window object so that the wrapper can executeJs to display messages to the player
This commit is contained in:
@@ -22,6 +22,9 @@ import { Server } from "./Server/Server";
|
||||
import { Router } from "./ui/GameRoot";
|
||||
import { Page } from "./ui/Router";
|
||||
import { removeLeadingSlash } from "./Terminal/DirectoryHelpers";
|
||||
import { Terminal } from './Terminal';
|
||||
import { SnackbarEvents } from "./ui/React/Snackbar";
|
||||
import { IMap } from "./types";
|
||||
|
||||
interface Achievement {
|
||||
ID: string;
|
||||
@@ -417,6 +420,7 @@ export function initElectron(): void {
|
||||
setAchievements([]);
|
||||
initWebserver();
|
||||
setInterval(calculateAchievements, 5000);
|
||||
initAppNotifier();
|
||||
}
|
||||
|
||||
function initWebserver(): void {
|
||||
@@ -451,3 +455,27 @@ function initWebserver(): void {
|
||||
return "not a script file";
|
||||
};
|
||||
}
|
||||
|
||||
// Expose certain alert functions to allow the wrapper to sends message to the game
|
||||
function initAppNotifier(): void {
|
||||
const funcs = {
|
||||
terminal: (message: string, type?: string) => {
|
||||
const typesFn: IMap<(s: string) => void> = {
|
||||
info: Terminal.info,
|
||||
warn: Terminal.warn,
|
||||
error: Terminal.error,
|
||||
success: Terminal.success
|
||||
};
|
||||
let fn;
|
||||
if (type) fn = typesFn[type];
|
||||
if (!fn) fn = Terminal.print;
|
||||
fn.bind(Terminal)(message);
|
||||
},
|
||||
toast: (message: string, type: "info" | "success" | "warning" | "error" , duration = 2000) =>
|
||||
SnackbarEvents.emit(message, type, duration),
|
||||
}
|
||||
|
||||
// Will be consumud by the electron wrapper.
|
||||
// @ts-ignore
|
||||
window.appNotifier = funcs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user