2022-02-17 19:48:08 +01:00
|
|
|
import { ipcMain } from "electron";
|
|
|
|
import { createAndShowNotification } from "./notification";
|
2022-02-18 01:51:35 +01:00
|
|
|
import settings from "./settings";
|
2022-02-19 01:08:33 +01:00
|
|
|
import { getAppView, getWindow, showAppView } from "./window";
|
2022-02-17 19:48:08 +01:00
|
|
|
|
|
|
|
export function emitMutedKeyPress() {
|
2022-02-18 23:03:05 +01:00
|
|
|
const mainWindow = getWindow();
|
|
|
|
if (!mainWindow) {
|
|
|
|
throw new Error("Main window not found");
|
|
|
|
}
|
2022-02-17 19:48:08 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
mainWindow.webContents.send("app:on-muted-key-press");
|
2022-02-17 19:48:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default () => {
|
2022-02-18 23:03:05 +01:00
|
|
|
ipcMain.on("app:notify", (event, txt) => {
|
|
|
|
createAndShowNotification({ body: txt });
|
|
|
|
});
|
2022-02-18 01:51:35 +01:00
|
|
|
|
2022-02-19 01:08:33 +01:00
|
|
|
ipcMain.handle("local-app:getServers", () => {
|
2022-02-18 23:03:05 +01:00
|
|
|
// TODO: remove
|
|
|
|
if (!settings.get("servers")) {
|
|
|
|
settings.set("servers", [
|
|
|
|
{
|
|
|
|
_id: "1",
|
|
|
|
name: "WA Demo",
|
|
|
|
url: "https://play.staging.workadventu.re/@/tcm/workadventure/wa-village",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
_id: "2",
|
|
|
|
name: "My Server",
|
|
|
|
url: "http://play.workadventure.localhost/",
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
}
|
2022-02-18 01:51:35 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
return settings.get("servers", []);
|
|
|
|
});
|
2022-02-18 01:51:35 +01:00
|
|
|
|
2022-02-19 01:08:33 +01:00
|
|
|
ipcMain.handle("local-app:selectServer", (event, serverId: string) => {
|
2022-02-18 23:03:05 +01:00
|
|
|
const appView = getAppView();
|
|
|
|
if (!appView) {
|
|
|
|
throw new Error("App view not found");
|
|
|
|
}
|
2022-02-18 01:51:35 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
const servers = settings.get("servers", []);
|
|
|
|
const selectedServer = servers.find((s) => s._id === serverId);
|
2022-02-18 01:51:35 +01:00
|
|
|
|
2022-02-18 23:03:05 +01:00
|
|
|
if (!selectedServer) {
|
|
|
|
return new Error("Server not found");
|
|
|
|
}
|
2022-02-18 01:51:35 +01:00
|
|
|
|
2022-02-19 01:08:33 +01:00
|
|
|
showAppView(selectedServer.url);
|
2022-02-18 23:03:05 +01:00
|
|
|
return true;
|
|
|
|
});
|
2022-02-18 01:51:35 +01:00
|
|
|
|
2022-02-19 01:08:33 +01:00
|
|
|
ipcMain.handle("local-app:addServer", (event, serverName: string, serverUrl: string) => {
|
2022-02-18 23:03:05 +01:00
|
|
|
const servers = settings.get("servers", []);
|
|
|
|
servers.push({
|
|
|
|
_id: `${servers.length + 1}`,
|
|
|
|
name: serverName,
|
|
|
|
url: serverUrl,
|
|
|
|
});
|
|
|
|
settings.set("servers", servers);
|
|
|
|
return true;
|
|
|
|
});
|
2022-02-17 19:48:08 +01:00
|
|
|
};
|