2024-05-10 05:24:24 +02:00
|
|
|
// Copyright 2024, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2024-09-12 03:03:55 +02:00
|
|
|
import { App } from "@/app/app";
|
2024-08-30 01:06:15 +02:00
|
|
|
import {
|
|
|
|
registerControlShiftStateUpdateHandler,
|
|
|
|
registerElectronReinjectKeyHandler,
|
|
|
|
registerGlobalKeys,
|
|
|
|
} from "@/app/store/keymodel";
|
2024-09-12 03:03:55 +02:00
|
|
|
import { FileService, ObjectService } from "@/app/store/services";
|
|
|
|
import { initWps } from "@/app/store/wps";
|
|
|
|
import { initWshrpc } from "@/app/store/wshrpc";
|
2024-07-18 00:24:43 +02:00
|
|
|
import { WshServer } from "@/app/store/wshserver";
|
2024-09-03 01:48:10 +02:00
|
|
|
import { loadMonaco } from "@/app/view/codeeditor/codeeditor";
|
|
|
|
import { getLayoutModelForActiveTab } from "@/layout/index";
|
2024-08-24 03:12:40 +02:00
|
|
|
import {
|
|
|
|
atoms,
|
|
|
|
countersClear,
|
|
|
|
countersPrint,
|
|
|
|
getApi,
|
|
|
|
globalStore,
|
|
|
|
initGlobal,
|
2024-09-12 03:03:55 +02:00
|
|
|
initGlobalWaveEventSubs,
|
2024-08-24 03:12:40 +02:00
|
|
|
loadConnStatus,
|
2024-09-13 01:02:18 +02:00
|
|
|
pushFlashError,
|
2024-08-24 03:12:40 +02:00
|
|
|
subscribeToConnEvents,
|
|
|
|
} from "@/store/global";
|
2024-05-28 21:12:28 +02:00
|
|
|
import * as WOS from "@/store/wos";
|
2024-09-12 03:03:55 +02:00
|
|
|
import { loadFonts } from "@/util/fontutil";
|
|
|
|
import { setKeyUtilPlatform } from "@/util/keyutil";
|
|
|
|
import { createElement } from "react";
|
2024-05-10 05:24:24 +02:00
|
|
|
import { createRoot } from "react-dom/client";
|
2024-05-24 23:08:24 +02:00
|
|
|
|
2024-07-19 22:44:32 +02:00
|
|
|
const platform = getApi().getPlatform();
|
2024-05-24 23:08:24 +02:00
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
2024-07-18 03:42:49 +02:00
|
|
|
const windowId = urlParams.get("windowid");
|
|
|
|
const clientId = urlParams.get("clientid");
|
2024-05-10 05:24:24 +02:00
|
|
|
|
2024-05-28 00:44:57 +02:00
|
|
|
console.log("Wave Starting");
|
2024-06-12 02:42:10 +02:00
|
|
|
console.log("clientid", clientId, "windowid", windowId);
|
2024-05-28 00:44:57 +02:00
|
|
|
|
2024-07-19 22:44:32 +02:00
|
|
|
initGlobal({ clientId, windowId, platform, environment: "renderer" });
|
|
|
|
|
2024-09-12 03:03:55 +02:00
|
|
|
setKeyUtilPlatform(platform);
|
2024-06-21 21:32:38 +02:00
|
|
|
|
2024-06-12 02:42:10 +02:00
|
|
|
loadFonts();
|
2024-05-28 21:18:26 +02:00
|
|
|
(window as any).WOS = WOS;
|
2024-06-04 22:05:44 +02:00
|
|
|
(window as any).globalStore = globalStore;
|
2024-07-26 22:30:11 +02:00
|
|
|
(window as any).globalAtoms = atoms;
|
2024-07-18 00:24:43 +02:00
|
|
|
(window as any).WshServer = WshServer;
|
2024-07-22 22:33:10 +02:00
|
|
|
(window as any).isFullScreen = false;
|
2024-08-22 00:49:23 +02:00
|
|
|
(window as any).countersPrint = countersPrint;
|
|
|
|
(window as any).countersClear = countersClear;
|
2024-09-03 01:48:10 +02:00
|
|
|
(window as any).getLayoutModelForActiveTab = getLayoutModelForActiveTab;
|
2024-09-13 01:02:18 +02:00
|
|
|
(window as any).pushFlashError = pushFlashError;
|
2024-05-28 21:18:26 +02:00
|
|
|
|
2024-06-20 04:10:53 +02:00
|
|
|
document.title = `The Next Wave (${windowId.substring(0, 8)})`;
|
|
|
|
|
2024-05-24 23:08:24 +02:00
|
|
|
document.addEventListener("DOMContentLoaded", async () => {
|
2024-05-28 00:44:57 +02:00
|
|
|
console.log("DOMContentLoaded");
|
2024-09-12 03:03:55 +02:00
|
|
|
|
|
|
|
// Init WPS event handlers
|
|
|
|
initWshrpc(windowId);
|
|
|
|
await loadConnStatus();
|
|
|
|
initWps();
|
|
|
|
initGlobalWaveEventSubs();
|
|
|
|
subscribeToConnEvents();
|
|
|
|
|
2024-06-03 22:43:50 +02:00
|
|
|
// ensures client/window/workspace are loaded into the cache before rendering
|
2024-06-12 02:42:10 +02:00
|
|
|
const client = await WOS.loadAndPinWaveObject<Client>(WOS.makeORef("client", clientId));
|
2024-05-27 22:59:58 +02:00
|
|
|
const waveWindow = await WOS.loadAndPinWaveObject<WaveWindow>(WOS.makeORef("window", windowId));
|
|
|
|
await WOS.loadAndPinWaveObject<Workspace>(WOS.makeORef("workspace", waveWindow.workspaceid));
|
2024-06-25 23:56:37 +02:00
|
|
|
const initialTab = await WOS.loadAndPinWaveObject<Tab>(WOS.makeORef("tab", waveWindow.activetabid));
|
2024-08-15 03:40:41 +02:00
|
|
|
await WOS.loadAndPinWaveObject<LayoutState>(WOS.makeORef("layout", initialTab.layoutstate));
|
2024-09-12 03:03:55 +02:00
|
|
|
|
2024-08-30 01:06:15 +02:00
|
|
|
registerGlobalKeys();
|
|
|
|
registerElectronReinjectKeyHandler();
|
|
|
|
registerControlShiftStateUpdateHandler();
|
2024-09-03 01:48:10 +02:00
|
|
|
setTimeout(loadMonaco, 30);
|
2024-09-12 03:03:55 +02:00
|
|
|
const fullConfig = await FileService.GetFullConfig();
|
2024-08-28 03:49:49 +02:00
|
|
|
console.log("fullconfig", fullConfig);
|
|
|
|
globalStore.set(atoms.fullConfigAtom, fullConfig);
|
2024-09-12 03:03:55 +02:00
|
|
|
const prtn = ObjectService.SetActiveTab(waveWindow.activetabid); // no need to wait
|
2024-09-05 09:21:08 +02:00
|
|
|
prtn.catch((e) => {
|
|
|
|
console.log("error on initial SetActiveTab", e);
|
|
|
|
});
|
2024-09-12 03:03:55 +02:00
|
|
|
const reactElem = createElement(App, null, null);
|
2024-06-11 22:19:29 +02:00
|
|
|
const elem = document.getElementById("main");
|
|
|
|
const root = createRoot(elem);
|
2024-05-10 05:24:24 +02:00
|
|
|
document.fonts.ready.then(() => {
|
2024-05-28 00:44:57 +02:00
|
|
|
console.log("Wave First Render");
|
2024-05-10 05:24:24 +02:00
|
|
|
root.render(reactElem);
|
|
|
|
});
|
|
|
|
});
|