Remove global.ts dependency from emain (#1003)

Removes global atoms dependency from emain by moving WOS to grab the
globalAtoms from window, if present. Also removes interdependency
between wshrpcutil and wps

Also adds showmenubar setting for Windows and Linux
This commit is contained in:
Evan Simkowitz 2024-10-10 13:12:42 -04:00 committed by GitHub
parent 67a8a59b1b
commit 64084d3e27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 51 additions and 29 deletions

View File

@ -13,7 +13,6 @@ import { Readable } from "stream";
import { debounce } from "throttle-debounce";
import * as util from "util";
import winston from "winston";
import { initGlobal } from "../frontend/app/store/global";
import * as services from "../frontend/app/store/services";
import { initElectronWshrpc, shutdownWshrpc } from "../frontend/app/store/wshrpcutil";
import { WSServerEndpointVarName, WebServerEndpointVarName, getWebServerEndpoint } from "../frontend/util/endpoints";
@ -108,8 +107,6 @@ if (isDev) {
console.log("waveterm-app WAVETERM_DEV set");
}
initGlobal({ windowId: null, clientId: null, platform: unamePlatform, environment: "electron" });
function getWindowForEvent(event: Electron.IpcMainEvent): Electron.BrowserWindow {
const windowId = event.sender.id;
return electron.BrowserWindow.fromId(windowId);
@ -369,7 +366,7 @@ function createBrowserWindow(clientId: string, waveWindow: WaveWindow, fullConfi
webviewTag: true,
},
show: false,
autoHideMenuBar: true,
autoHideMenuBar: !settings?.["window:showmenubar"],
};
const isTransparent = settings?.["window:transparent"] ?? false;
const isBlur = !isTransparent && (settings?.["window:blur"] ?? false);

View File

@ -11,14 +11,14 @@ import {
import { getWebServerEndpoint } from "@/util/endpoints";
import { fetch } from "@/util/fetchutil";
import { getPrefixedSettings, isBlank } from "@/util/util";
import { atom, Atom, createStore, PrimitiveAtom, useAtomValue } from "jotai";
import { atom, Atom, PrimitiveAtom, useAtomValue } from "jotai";
import { globalStore } from "./jotaiStore";
import { modalsModel } from "./modalmodel";
import { ClientService, ObjectService } from "./services";
import * as WOS from "./wos";
import { getFileSubject, waveEventSubscribe } from "./wps";
let PLATFORM: NodeJS.Platform = "darwin";
const globalStore = createStore();
let atoms: GlobalAtomsType;
let globalEnvironment: "electron" | "renderer";
const blockComponentModelMap = new Map<string, BlockComponentModel>();

View File

@ -0,0 +1,3 @@
import { createStore } from "jotai";
export const globalStore = createStore();

View File

@ -7,7 +7,7 @@ import { getWebServerEndpoint } from "@/util/endpoints";
import { fetch } from "@/util/fetchutil";
import { atom, Atom, Getter, PrimitiveAtom, Setter, useAtomValue } from "jotai";
import { useEffect } from "react";
import { atoms, globalStore } from "./global";
import { globalStore } from "./jotaiStore";
import { ObjectService } from "./services";
type WaveObjectDataItemType<T extends WaveObj> = {
@ -79,8 +79,8 @@ function debugLogBackendCall(methodName: string, durationStr: string, args: any[
function callBackendService(service: string, method: string, args: any[], noUIContext?: boolean): Promise<any> {
const startTs = Date.now();
let uiContext: UIContext = null;
if (!noUIContext) {
uiContext = globalStore.get(atoms.uiContext);
if (!noUIContext && globalThis.window != null) {
uiContext = globalStore.get(((window as any).globalAtoms as GlobalAtomsType).uiContext);
}
const waveCall: WebCallType = {
service: service,

View File

@ -1,6 +1,6 @@
import { isBlank } from "@/util/util";
import { Subject } from "rxjs";
import { sendRawRpcMessage } from "./wshrpcutil";
import { sendRawRpcMessage } from "./ws";
type WaveEventSubject = {
handler: (event: WaveEvent) => void;

View File

@ -218,4 +218,32 @@ class WSControl {
}
}
export { WSControl, addWSReconnectHandler, removeWSReconnectHandler, type ElectronOverrideOpts };
let globalWS: WSControl;
function initGlobalWS(
baseHostPort: string,
windowId: string,
messageCallback: WSEventCallback,
electronOverrideOpts?: ElectronOverrideOpts
) {
globalWS = new WSControl(baseHostPort, windowId, messageCallback, electronOverrideOpts);
}
function sendRawRpcMessage(msg: RpcMessage) {
const wsMsg: WSRpcCommand = { wscommand: "rpc", message: msg };
sendWSCommand(wsMsg);
}
function sendWSCommand(cmd: WSCommandType) {
globalWS?.pushMessage(cmd);
}
export {
WSControl,
addWSReconnectHandler,
globalWS,
initGlobalWS,
removeWSReconnectHandler,
sendRawRpcMessage,
sendWSCommand,
type ElectronOverrideOpts,
};

View File

@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0
import { handleWaveEvent } from "@/app/store/wps";
import * as util from "@/util/util";
import debug from "debug";
import * as util from "../../util/util";
const dlog = debug("wave:router");

View File

@ -5,9 +5,8 @@ import { wpsReconnectHandler } from "@/app/store/wps";
import { WshClient } from "@/app/store/wshclient";
import { makeWindowRouteId, WshRouter } from "@/app/store/wshrouter";
import { getWSServerEndpoint } from "@/util/endpoints";
import { addWSReconnectHandler, ElectronOverrideOpts, WSControl } from "./ws";
import { addWSReconnectHandler, ElectronOverrideOpts, globalWS, initGlobalWS, WSControl } from "./ws";
let globalWS: WSControl;
let DefaultRouter: WshRouter;
let WindowRpcClient: WshClient;
@ -91,11 +90,6 @@ function sendRpcCommand(
return rtnGen;
}
function sendRawRpcMessage(msg: RpcMessage) {
const wsMsg: WSRpcCommand = { wscommand: "rpc", message: msg };
sendWSCommand(wsMsg);
}
async function consumeGenerator(gen: AsyncGenerator<any, any, any>) {
let idx = 0;
try {
@ -119,7 +113,7 @@ function initElectronWshrpc(electronClient: WshClient, eoOpts: ElectronOverrideO
const handleFn = (event: WSEventType) => {
DefaultRouter.recvRpcMessage(event.data);
};
globalWS = new WSControl(getWSServerEndpoint(), "electron", handleFn, eoOpts);
initGlobalWS(getWSServerEndpoint(), "electron", handleFn, eoOpts);
globalWS.connectNow("connectWshrpc");
DefaultRouter.registerRoute(electronClient.routeId, electronClient);
addWSReconnectHandler(() => {
@ -137,7 +131,7 @@ function initWshrpc(windowId: string): WSControl {
const handleFn = (event: WSEventType) => {
DefaultRouter.recvRpcMessage(event.data);
};
globalWS = new WSControl(getWSServerEndpoint(), windowId, handleFn);
initGlobalWS(getWSServerEndpoint(), windowId, handleFn);
globalWS.connectNow("connectWshrpc");
WindowRpcClient = new WshClient(makeWindowRouteId(windowId));
DefaultRouter.registerRoute(WindowRpcClient.routeId, WindowRpcClient);
@ -148,10 +142,6 @@ function initWshrpc(windowId: string): WSControl {
return globalWS;
}
function sendWSCommand(cmd: WSCommandType) {
globalWS?.pushMessage(cmd);
}
class UpstreamWshRpcProxy implements AbstractWshClient {
recvRpcMessage(msg: RpcMessage): void {
const wsMsg: WSRpcCommand = { wscommand: "rpc", message: msg };
@ -163,10 +153,8 @@ export {
DefaultRouter,
initElectronWshrpc,
initWshrpc,
sendRawRpcMessage,
sendRpcCommand,
sendRpcResponse,
sendWSCommand,
shutdownWshrpc,
WindowRpcClient,
};

View File

@ -74,6 +74,8 @@ const TabBar = React.memo(({ workspace }: TabBarProps) => {
const isFullScreen = useAtomValue(atoms.isFullScreen);
const settings = useAtomValue(atoms.settingsAtom);
let prevDelta: number;
let prevDragDirection: string;
@ -469,7 +471,7 @@ const TabBar = React.memo(({ workspace }: TabBarProps) => {
</div>
) : undefined;
const appMenuButton =
PLATFORM !== "darwin" ? (
PLATFORM !== "darwin" && !settings["window:showmenubar"] ? (
<div className="app-menu-button" onClick={onEllipsisClick}>
<i className="fa fa-ellipsis" />
</div>

View File

@ -2,8 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
import { getFileSubject } from "@/app/store/wps";
import { sendWSCommand } from "@/app/store/ws";
import { RpcApi } from "@/app/store/wshclientapi";
import { WindowRpcClient, sendWSCommand } from "@/app/store/wshrpcutil";
import { WindowRpcClient } from "@/app/store/wshrpcutil";
import { PLATFORM, WOS, atoms, fetchWaveFile, globalStore, openLink } from "@/store/global";
import * as services from "@/store/services";
import * as util from "@/util/util";

View File

@ -466,6 +466,7 @@ declare global {
"window:bgcolor"?: string;
"window:reducedmotion"?: boolean;
"window:tilegapsize"?: number;
"window:showmenubar"?: boolean;
"window:nativetitlebar"?: boolean;
"window:disablehardwareacceleration"?: boolean;
"telemetry:*"?: boolean;

View File

@ -55,6 +55,7 @@ const (
ConfigKey_WindowBgColor = "window:bgcolor"
ConfigKey_WindowReducedMotion = "window:reducedmotion"
ConfigKey_WindowTileGapSize = "window:tilegapsize"
ConfigKey_WindowShowMenuBar = "window:showmenubar"
ConfigKey_WindowNativeTitleBar = "window:nativetitlebar"
ConfigKey_WindowDisableHardwareAcceleration = "window:disablehardwareacceleration"

View File

@ -89,6 +89,7 @@ type SettingsType struct {
WindowBgColor string `json:"window:bgcolor,omitempty"`
WindowReducedMotion bool `json:"window:reducedmotion,omitempty"`
WindowTileGapSize *int64 `json:"window:tilegapsize,omitempty"`
WindowShowMenuBar bool `json:"window:showmenubar,omitempty"`
WindowNativeTitleBar bool `json:"window:nativetitlebar,omitempty"`
WindowDisableHardwareAcceleration bool `json:"window:disablehardwareacceleration,omitempty"`