mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
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:
parent
67a8a59b1b
commit
64084d3e27
@ -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);
|
||||||
|
@ -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>();
|
||||||
|
3
frontend/app/store/jotaiStore.ts
Normal file
3
frontend/app/store/jotaiStore.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { createStore } from "jotai";
|
||||||
|
|
||||||
|
export const globalStore = createStore();
|
@ -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,
|
||||||
|
@ -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;
|
||||||
|
@ -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,
|
||||||
|
};
|
||||||
|
@ -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");
|
||||||
|
|
||||||
|
@ -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,
|
||||||
};
|
};
|
||||||
|
@ -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>
|
||||||
|
@ -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";
|
||||||
|
1
frontend/types/gotypes.d.ts
vendored
1
frontend/types/gotypes.d.ts
vendored
@ -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;
|
||||||
|
@ -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"
|
||||||
|
|
||||||
|
@ -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"`
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user