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

View File

@ -11,14 +11,14 @@ import {
import { getWebServerEndpoint } from "@/util/endpoints"; import { getWebServerEndpoint } from "@/util/endpoints";
import { fetch } from "@/util/fetchutil"; import { fetch } from "@/util/fetchutil";
import { getPrefixedSettings, isBlank } from "@/util/util"; 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 { modalsModel } from "./modalmodel";
import { ClientService, ObjectService } from "./services"; import { ClientService, ObjectService } from "./services";
import * as WOS from "./wos"; import * as WOS from "./wos";
import { getFileSubject, waveEventSubscribe } from "./wps"; import { getFileSubject, waveEventSubscribe } from "./wps";
let PLATFORM: NodeJS.Platform = "darwin"; let PLATFORM: NodeJS.Platform = "darwin";
const globalStore = createStore();
let atoms: GlobalAtomsType; let atoms: GlobalAtomsType;
let globalEnvironment: "electron" | "renderer"; let globalEnvironment: "electron" | "renderer";
const blockComponentModelMap = new Map<string, BlockComponentModel>(); 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 { fetch } from "@/util/fetchutil";
import { atom, Atom, Getter, PrimitiveAtom, Setter, useAtomValue } from "jotai"; import { atom, Atom, Getter, PrimitiveAtom, Setter, useAtomValue } from "jotai";
import { useEffect } from "react"; import { useEffect } from "react";
import { atoms, globalStore } from "./global"; import { globalStore } from "./jotaiStore";
import { ObjectService } from "./services"; import { ObjectService } from "./services";
type WaveObjectDataItemType<T extends WaveObj> = { 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> { function callBackendService(service: string, method: string, args: any[], noUIContext?: boolean): Promise<any> {
const startTs = Date.now(); const startTs = Date.now();
let uiContext: UIContext = null; let uiContext: UIContext = null;
if (!noUIContext) { if (!noUIContext && globalThis.window != null) {
uiContext = globalStore.get(atoms.uiContext); uiContext = globalStore.get(((window as any).globalAtoms as GlobalAtomsType).uiContext);
} }
const waveCall: WebCallType = { const waveCall: WebCallType = {
service: service, service: service,

View File

@ -1,6 +1,6 @@
import { isBlank } from "@/util/util"; import { isBlank } from "@/util/util";
import { Subject } from "rxjs"; import { Subject } from "rxjs";
import { sendRawRpcMessage } from "./wshrpcutil"; import { sendRawRpcMessage } from "./ws";
type WaveEventSubject = { type WaveEventSubject = {
handler: (event: WaveEvent) => void; 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 // SPDX-License-Identifier: Apache-2.0
import { handleWaveEvent } from "@/app/store/wps"; import { handleWaveEvent } from "@/app/store/wps";
import * as util from "@/util/util";
import debug from "debug"; import debug from "debug";
import * as util from "../../util/util";
const dlog = debug("wave:router"); const dlog = debug("wave:router");

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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