add desktop api to front
This commit is contained in:
+11
-10
@@ -3,25 +3,26 @@ import electronIsDev from "electron-is-dev";
|
||||
import { createAndShowNotification } from "./notification";
|
||||
import { Server } from "./preload-local-app/types";
|
||||
import settings, { SettingsData } from "./settings";
|
||||
import { loadShortcuts, saveShortcut, setShortcutsEnabled } from "./shortcuts";
|
||||
import { getWindow, hideAppView, showAppView } from "./window";
|
||||
import { loadShortcuts, setShortcutsEnabled } from "./shortcuts";
|
||||
import { getAppView, getWindow, hideAppView, showAppView } from "./window";
|
||||
// import fetch from "node-fetch";
|
||||
|
||||
export function emitMuteToggle() {
|
||||
const mainWindow = getWindow();
|
||||
if (!mainWindow) {
|
||||
const appView = getAppView();
|
||||
if (!appView) {
|
||||
throw new Error("Main window not found");
|
||||
}
|
||||
|
||||
mainWindow.webContents.send("app:on-camera-toggle");
|
||||
appView.webContents.send("app:on-camera-toggle");
|
||||
}
|
||||
|
||||
export function emitCameraToggle() {
|
||||
const mainWindow = getWindow();
|
||||
if (!mainWindow) {
|
||||
const appView = getAppView();
|
||||
if (!appView) {
|
||||
throw new Error("Main window not found");
|
||||
}
|
||||
|
||||
mainWindow.webContents.send("app:on-mute-toggle");
|
||||
appView.webContents.send("app:on-mute-toggle");
|
||||
}
|
||||
|
||||
export default () => {
|
||||
@@ -68,7 +69,7 @@ export default () => {
|
||||
|
||||
try {
|
||||
// TODO: add proper test to see if server url is valid and points to a real WA server
|
||||
await fetch(`${server.url}/iframe_api.js`);
|
||||
// await fetch(`${server.url}/iframe_api.js`);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return new Error("Invalid server url");
|
||||
@@ -76,7 +77,7 @@ export default () => {
|
||||
|
||||
const newServer = {
|
||||
...server,
|
||||
_id: `${servers.length + 1}`,
|
||||
_id: `${Date.now()}-${servers.length + 1}`,
|
||||
};
|
||||
servers.push(newServer);
|
||||
settings.set("servers", servers);
|
||||
|
||||
@@ -10,4 +10,4 @@ const api: WorkAdventureDesktopApi = {
|
||||
onCameraToggle: (callback) => ipcRenderer.on("app:on-camera-toggle", callback),
|
||||
};
|
||||
|
||||
contextBridge.exposeInMainWorld("WorkAdventureDesktopApi", api);
|
||||
contextBridge.exposeInMainWorld("WAD", api);
|
||||
|
||||
@@ -16,4 +16,4 @@ const api: WorkAdventureLocalAppApi = {
|
||||
setShortcutsEnabled: (enabled) => ipcRenderer.invoke("local-app:setShortcutsEnabled", enabled),
|
||||
};
|
||||
|
||||
contextBridge.exposeInMainWorld("WorkAdventureDesktopApi", api);
|
||||
contextBridge.exposeInMainWorld("WAD", api);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { globalShortcut } from "electron";
|
||||
import settings, { SettingsData } from "./settings";
|
||||
import { emitCameraToggle, emitMuteToggle } from "./ipc";
|
||||
import { createAndShowNotification } from "./notification";
|
||||
|
||||
export function setShortcutsEnabled(enabled: boolean) {
|
||||
if (enabled) {
|
||||
@@ -16,18 +15,15 @@ export function loadShortcuts() {
|
||||
|
||||
const shortcuts = settings.get("shortcuts");
|
||||
|
||||
// // mute key
|
||||
if (shortcuts?.mute_toggle && shortcuts.mute_toggle.length > 0) {
|
||||
globalShortcut.register(shortcuts.mute_toggle, () => {
|
||||
emitMuteToggle();
|
||||
createAndShowNotification({ body: "Toggled mute" }); // TODO
|
||||
});
|
||||
}
|
||||
|
||||
if (shortcuts?.camera_toggle && shortcuts.camera_toggle.length > 0) {
|
||||
globalShortcut.register(shortcuts.camera_toggle, () => {
|
||||
emitCameraToggle();
|
||||
createAndShowNotification({ body: "Toggled camera" }); // TODO
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,19 @@ export function getAppView() {
|
||||
return appView;
|
||||
}
|
||||
|
||||
function resizeAppView() {
|
||||
if (!mainWindow || !appView) {
|
||||
return;
|
||||
}
|
||||
|
||||
appView.setBounds({
|
||||
x: sidebarWidth,
|
||||
y: 0,
|
||||
width: mainWindow.getBounds().width - sidebarWidth,
|
||||
height: mainWindow.getBounds().height,
|
||||
});
|
||||
}
|
||||
|
||||
export async function createWindow() {
|
||||
// do not re-create window if still existing
|
||||
if (mainWindow) {
|
||||
@@ -41,6 +54,7 @@ export async function createWindow() {
|
||||
preload: path.resolve(__dirname, "..", "dist", "preload-local-app", "preload.js"),
|
||||
},
|
||||
});
|
||||
mainWindow.setMenu(null);
|
||||
|
||||
// Let us register listeners on the window, so we can update the state
|
||||
// automatically (the listeners will be removed when the window is closed)
|
||||
@@ -74,16 +88,8 @@ export async function createWindow() {
|
||||
preload: path.resolve(__dirname, "..", "dist", "preload-app", "preload.js"),
|
||||
},
|
||||
});
|
||||
appView.setBounds({
|
||||
x: sidebarWidth,
|
||||
y: 0,
|
||||
width: mainWindow.getBounds().width - sidebarWidth,
|
||||
height: mainWindow.getBounds().height,
|
||||
});
|
||||
appView.setAutoResize({
|
||||
width: true,
|
||||
height: true,
|
||||
});
|
||||
resizeAppView();
|
||||
mainWindow.on("resize", resizeAppView);
|
||||
|
||||
mainWindow.once("ready-to-show", () => {
|
||||
mainWindow?.show();
|
||||
@@ -91,7 +97,7 @@ export async function createWindow() {
|
||||
// appView?.webContents.openDevTools({
|
||||
// mode: "detach",
|
||||
// });
|
||||
mainWindow?.webContents.openDevTools({ mode: "detach" });
|
||||
// mainWindow?.webContents.openDevTools({ mode: "detach" });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user