Skip to content

Commit 332fedb

Browse files
committed
save
1 parent ddf4825 commit 332fedb

File tree

13 files changed

+104
-182
lines changed

13 files changed

+104
-182
lines changed

frontend/app/app-bg.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
// Copyright 2025, Command Line Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
import { PLATFORM, PlatformMacOS } from "@/util/platformutil";
45
import { computeBgStyleFromMeta } from "@/util/waveutil";
56
import useResizeObserver from "@react-hook/resize-observer";
67
import { useAtomValue } from "jotai";
78
import { CSSProperties, useCallback, useLayoutEffect, useRef } from "react";
89
import { debounce } from "throttle-debounce";
9-
import { atoms, getApi, PLATFORM, WOS } from "./store/global";
10+
import { atoms, getApi, WOS } from "./store/global";
1011
import { useWaveObjectValue } from "./store/wos";
1112

1213
export function AppBackground() {
@@ -18,7 +19,7 @@ export function AppBackground() {
1819
debounce(30, () => {
1920
if (
2021
bgRef.current &&
21-
PLATFORM !== "darwin" &&
22+
PLATFORM !== PlatformMacOS &&
2223
bgRef.current &&
2324
"windowControlsOverlay" in window.navigator
2425
) {

frontend/app/app.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@
33

44
import { Workspace } from "@/app/workspace/workspace";
55
import { ContextMenuModel } from "@/store/contextmenu";
6-
import {
7-
atoms,
8-
createBlock,
9-
getSettingsPrefixAtom,
10-
globalStore,
11-
isDev,
12-
PLATFORM,
13-
removeFlashError,
14-
} from "@/store/global";
6+
import { atoms, createBlock, getSettingsPrefixAtom, globalStore, isDev, removeFlashError } from "@/store/global";
157
import { appHandleKeyDown, keyboardMouseDownHandler } from "@/store/keymodel";
168
import { getElemAsStr } from "@/util/focusutil";
179
import * as keyutil from "@/util/keyutil";
@@ -30,6 +22,7 @@ import { NotificationBubbles } from "./notification/notificationbubbles";
3022
import "./app.scss";
3123

3224
// this should come after app.scss (don't remove the newline above otherwise prettier will reorder these imports)
25+
import { PLATFORM } from "@/util/platformutil";
3326
import "../tailwindsetup.css";
3427

3528
const dlog = debug("wave:app");

frontend/app/element/quicktips.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { MagnifyIcon } from "@/app/element/magnify";
5-
import { PLATFORM } from "@/app/store/global";
5+
import { PLATFORM, PlatformMacOS } from "@/util/platformutil";
66
import "./quicktips.scss";
77

88
const KeyBinding = ({ keyDecl }: { keyDecl: string }) => {
99
const parts = keyDecl.split(":");
1010
const elems: React.ReactNode[] = [];
1111
for (let part of parts) {
1212
if (part === "Cmd") {
13-
if (PLATFORM === "darwin") {
13+
if (PLATFORM === PlatformMacOS) {
1414
elems.push(
1515
<div key="cmd" className="keybinding">
1616
⌘ Cmd

frontend/app/store/global.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
} from "@/layout/lib/types";
1818
import { getWebServerEndpoint } from "@/util/endpoints";
1919
import { fetch } from "@/util/fetchutil";
20+
import { setPlatform } from "@/util/platformutil";
2021
import { deepCompareReturnPrev, getPrefixedSettings, isBlank } from "@/util/util";
2122
import { atom, Atom, PrimitiveAtom, useAtomValue } from "jotai";
2223
import { globalStore } from "./jotaiStore";
@@ -25,7 +26,6 @@ import { ClientService, ObjectService } from "./services";
2526
import * as WOS from "./wos";
2627
import { getFileSubject, waveEventSubscribe } from "./wps";
2728

28-
let PLATFORM: NodeJS.Platform = "darwin";
2929
let atoms: GlobalAtomsType;
3030
let globalEnvironment: "electron" | "renderer";
3131
const blockComponentModelMap = new Map<string, BlockComponentModel>();
@@ -46,10 +46,6 @@ function initGlobal(initOpts: GlobalInitOptions) {
4646
initGlobalAtoms(initOpts);
4747
}
4848

49-
function setPlatform(platform: NodeJS.Platform) {
50-
PLATFORM = platform;
51-
}
52-
5349
function initGlobalAtoms(initOpts: GlobalInitOptions) {
5450
const windowIdAtom = atom(initOpts.windowId) as PrimitiveAtom<string>;
5551
const clientIdAtom = atom(initOpts.clientId) as PrimitiveAtom<string>;
@@ -790,7 +786,6 @@ export {
790786
isDev,
791787
loadConnStatus,
792788
openLink,
793-
PLATFORM,
794789
pushFlashError,
795790
pushNotification,
796791
recordTEvent,

frontend/app/tab/tabbar.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { Button } from "@/app/element/button";
55
import { modalsModel } from "@/app/store/modalmodel";
66
import { WindowDrag } from "@/element/windowdrag";
77
import { deleteLayoutModelForTab } from "@/layout/index";
8-
import { atoms, createTab, getApi, globalStore, isDev, PLATFORM, setActiveTab } from "@/store/global";
8+
import { atoms, createTab, getApi, globalStore, isDev, setActiveTab } from "@/store/global";
9+
import { PLATFORM, PlatformMacOS } from "@/util/platformutil";
910
import { fireAndForget } from "@/util/util";
1011
import { useAtomValue } from "jotai";
1112
import { OverlayScrollbars } from "overlayscrollbars";
@@ -641,7 +642,7 @@ const TabBar = memo(({ workspace }: TabBarProps) => {
641642
</div>
642643
) : undefined;
643644
const appMenuButton =
644-
PLATFORM !== "darwin" && !settings["window:showmenubar"] ? (
645+
PLATFORM !== PlatformMacOS && !settings["window:showmenubar"] ? (
645646
<div ref={appMenuButtonRef} className="app-menu-button" onClick={onEllipsisClick}>
646647
<i className="fa fa-ellipsis" />
647648
</div>

frontend/app/view/preview/directorypreview.tsx

Lines changed: 9 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { CopyButton } from "@/app/element/copybutton";
66
import { Input } from "@/app/element/input";
77
import { useDimensionsWithCallbackRef } from "@/app/hook/useDimensions";
88
import { ContextMenuModel } from "@/app/store/contextmenu";
9-
import { PLATFORM, atoms, createBlock, getApi, globalStore } from "@/app/store/global";
9+
import { atoms, createBlock, getApi, globalStore } from "@/app/store/global";
1010
import { RpcApi } from "@/app/store/wshclientapi";
1111
import { TabRpcClient } from "@/app/store/wshrpcutil";
1212
import { type PreviewModel } from "@/app/view/preview/preview";
1313
import { checkKeyPressed, isCharacterKeyEvent } from "@/util/keyutil";
14-
import { fireAndForget, isBlank, makeNativeLabel } from "@/util/util";
14+
import { PLATFORM, PlatformMacOS } from "@/util/platformutil";
15+
import { fireAndForget, isBlank } from "@/util/util";
1516
import { formatRemoteUri } from "@/util/waveutil";
1617
import { offset, useDismiss, useFloating, useInteractions } from "@floating-ui/react";
1718
import {
@@ -33,6 +34,7 @@ import React, { Fragment, memo, useCallback, useEffect, useMemo, useRef, useStat
3334
import { useDrag, useDrop } from "react-dnd";
3435
import { quote as shellQuote } from "shell-quote";
3536
import { debounce } from "throttle-debounce";
37+
import { addOpenMenuItems } from "../../../util/previewutil";
3638
import "./directorypreview.scss";
3739

3840
const PageJumpSize = 20;
@@ -595,43 +597,7 @@ function TableBody({
595597
}),
596598
},
597599
];
598-
if (!conn) {
599-
menu.push(
600-
{
601-
type: "separator",
602-
},
603-
// TODO: resolve correct host path if connection is WSL
604-
{
605-
label: makeNativeLabel(PLATFORM, finfo.isdir, false),
606-
click: () => {
607-
getApi().openNativePath(normPath);
608-
},
609-
},
610-
{
611-
label: makeNativeLabel(PLATFORM, true, true),
612-
click: () => {
613-
getApi().openNativePath(finfo.dir);
614-
},
615-
}
616-
);
617-
}
618-
if (finfo.mimetype == "directory") {
619-
menu.push({
620-
label: "Open Terminal in New Block",
621-
click: () =>
622-
fireAndForget(async () => {
623-
const termBlockDef: BlockDef = {
624-
meta: {
625-
controller: "shell",
626-
view: "term",
627-
"cmd:cwd": await model.formatRemoteUri(finfo.path, globalStore.get),
628-
connection: conn,
629-
},
630-
};
631-
await createBlock(termBlockDef);
632-
}),
633-
});
634-
}
600+
addOpenMenuItems(menu, conn, finfo);
635601
menu.push(
636602
{
637603
type: "separator",
@@ -787,7 +753,8 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) {
787753
const [refreshVersion, setRefreshVersion] = useAtom(model.refreshVersion);
788754
const conn = useAtomValue(model.connection);
789755
const blockData = useAtomValue(model.blockAtom);
790-
const dirPath = useAtomValue(model.normFilePath);
756+
const finfo = useAtomValue(model.statFile);
757+
const dirPath = finfo?.path;
791758
const [copyStatus, setCopyStatus] = useState<FileCopyStatus>(null);
792759

793760
useEffect(() => {
@@ -875,7 +842,7 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) {
875842
if (
876843
checkKeyPressed(waveEvent, "Space") &&
877844
searchText == "" &&
878-
PLATFORM == "darwin" &&
845+
PLATFORM == PlatformMacOS &&
879846
!blockData?.meta?.connection
880847
) {
881848
getApi().onQuicklook(selectedPath);
@@ -1034,29 +1001,7 @@ function DirectoryPreview({ model }: DirectoryPreviewProps) {
10341001
type: "separator",
10351002
},
10361003
];
1037-
if (!conn) {
1038-
// TODO: resolve correct host path if connection is WSL
1039-
menu.push({
1040-
label: makeNativeLabel(PLATFORM, true, true),
1041-
click: () => {
1042-
getApi().openNativePath(dirPath);
1043-
},
1044-
});
1045-
}
1046-
menu.push({
1047-
label: "Open Terminal in New Block",
1048-
click: async () => {
1049-
const termBlockDef: BlockDef = {
1050-
meta: {
1051-
controller: "shell",
1052-
view: "term",
1053-
"cmd:cwd": dirPath,
1054-
connection: conn,
1055-
},
1056-
};
1057-
await createBlock(termBlockDef);
1058-
},
1059-
});
1004+
addOpenMenuItems(menu, conn, finfo);
10601005

10611006
ContextMenuModel.showContextMenu(menu, e);
10621007
},

frontend/app/view/preview/preview.tsx

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,19 @@ import { CodeEditor } from "@/app/view/codeeditor/codeeditor";
1515
import { Markdown } from "@/element/markdown";
1616
import {
1717
atoms,
18-
createBlock,
19-
getApi,
2018
getConnStatusAtom,
2119
getOverrideConfigAtom,
2220
getSettingsKeyAtom,
2321
globalStore,
24-
PLATFORM,
2522
refocusNode,
2623
} from "@/store/global";
2724
import * as services from "@/store/services";
2825
import * as WOS from "@/store/wos";
2926
import { getWebServerEndpoint } from "@/util/endpoints";
3027
import { goHistory, goHistoryBack, goHistoryForward } from "@/util/historyutil";
3128
import { adaptFromReactOrNativeKeyEvent, checkKeyPressed, keydownWrapper } from "@/util/keyutil";
32-
import {
33-
base64ToString,
34-
fireAndForget,
35-
isBlank,
36-
jotaiLoadableValue,
37-
makeConnRoute,
38-
makeNativeLabel,
39-
stringToBase64,
40-
} from "@/util/util";
29+
import { addOpenMenuItems } from "@/util/previewutil";
30+
import { base64ToString, fireAndForget, isBlank, jotaiLoadableValue, makeConnRoute, stringToBase64 } from "@/util/util";
4131
import { formatRemoteUri } from "@/util/waveutil";
4232
import { Monaco } from "@monaco-editor/react";
4333
import clsx from "clsx";
@@ -742,47 +732,8 @@ export class PreviewModel implements ViewModel {
742732
await navigator.clipboard.writeText(fileInfo.name);
743733
}),
744734
});
745-
const mimeType = jotaiLoadableValue(globalStore.get(this.fileMimeTypeLoadable), "");
746-
if (mimeType == "directory") {
747-
menuItems.push({
748-
label: "Open Terminal in New Block",
749-
click: () =>
750-
fireAndForget(async () => {
751-
const conn = await globalStore.get(this.connection);
752-
const fileInfo = await globalStore.get(this.statFile);
753-
const termBlockDef: BlockDef = {
754-
meta: {
755-
view: "term",
756-
controller: "shell",
757-
"cmd:cwd": fileInfo.path,
758-
connection: conn,
759-
},
760-
};
761-
await createBlock(termBlockDef);
762-
}),
763-
});
764-
const conn = globalStore.get(this.connectionImmediate);
765-
if (!conn) {
766-
menuItems.push({
767-
label: makeNativeLabel(PLATFORM, true, true),
768-
click: async () => {
769-
const fileInfo = await globalStore.get(this.statFile);
770-
getApi().openNativePath(fileInfo.path);
771-
},
772-
});
773-
}
774-
} else {
775-
const conn = globalStore.get(this.connectionImmediate);
776-
if (!conn) {
777-
menuItems.push({
778-
label: makeNativeLabel(PLATFORM, false, false),
779-
click: async () => {
780-
const fileInfo = await globalStore.get(this.statFile);
781-
getApi().openNativePath(fileInfo.path);
782-
},
783-
});
784-
}
785-
}
735+
const finfo = jotaiLoadableValue(globalStore.get(this.loadableFileInfo), null);
736+
addOpenMenuItems(menuItems, globalStore.get(this.connectionImmediate), finfo);
786737
const loadableSV = globalStore.get(this.loadableSpecializedView);
787738
const wordWrapAtom = getOverrideConfigAtom(this.blockId, "editor:wordwrap");
788739
const wordWrap = globalStore.get(wordWrapAtom) ?? false;

frontend/app/view/term/termwrap.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { getFileSubject } from "@/app/store/wps";
55
import { sendWSCommand } from "@/app/store/ws";
66
import { RpcApi } from "@/app/store/wshclientapi";
77
import { TabRpcClient } from "@/app/store/wshrpcutil";
8-
import { PLATFORM, WOS, atoms, fetchWaveFile, getSettingsKeyAtom, globalStore, openLink } from "@/store/global";
8+
import { WOS, atoms, fetchWaveFile, getSettingsKeyAtom, globalStore, openLink } from "@/store/global";
99
import * as services from "@/store/services";
10+
import { PLATFORM, PlatformMacOS } from "@/util/platformutil";
1011
import { base64ToArray, fireAndForget } from "@/util/util";
1112
import { SearchAddon } from "@xterm/addon-search";
1213
import { SerializeAddon } from "@xterm/addon-serialize";
@@ -166,7 +167,7 @@ export class TermWrap {
166167
this.hasResized = false;
167168
this.terminal = new Terminal(options);
168169
this.fitAddon = new FitAddon();
169-
this.fitAddon.noScrollbar = PLATFORM == "darwin";
170+
this.fitAddon.noScrollbar = PLATFORM === PlatformMacOS;
170171
this.serializeAddon = new SerializeAddon();
171172
this.searchAddon = new SearchAddon();
172173
this.terminal.loadAddon(this.searchAddon);
@@ -176,7 +177,7 @@ export class TermWrap {
176177
new WebLinksAddon((e, uri) => {
177178
e.preventDefault();
178179
switch (PLATFORM) {
179-
case "darwin":
180+
case PlatformMacOS:
180181
if (e.metaKey) {
181182
fireAndForget(() => openLink(uri));
182183
}

frontend/app/view/vdom/vdom-model.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { BlockNodeModel } from "@/app/block/blocktypes";
5-
import { getBlockMetaKeyAtom, globalStore, PLATFORM, WOS } from "@/app/store/global";
5+
import { getBlockMetaKeyAtom, globalStore, WOS } from "@/app/store/global";
66
import { makeORef } from "@/app/store/wos";
77
import { waveEventSubscribe } from "@/app/store/wps";
88
import { RpcResponseHelper, WshClient } from "@/app/store/wshclient";
@@ -13,6 +13,7 @@ import { VDomView } from "@/app/view/vdom/vdom";
1313
import { applyCanvasOp, mergeBackendUpdates, restoreVDomElems } from "@/app/view/vdom/vdom-utils";
1414
import { getWebServerEndpoint } from "@/util/endpoints";
1515
import { adaptFromReactOrNativeKeyEvent, checkKeyPressed } from "@/util/keyutil";
16+
import { PLATFORM, PlatformMacOS } from "@/util/platformutil";
1617
import debug from "debug";
1718
import * as jotai from "jotai";
1819

@@ -73,7 +74,7 @@ function annotateEvent(event: VDomEvent, propName: string, reactEvent: React.Syn
7374
movementx: mouseEvent.movementX,
7475
movementy: mouseEvent.movementY,
7576
};
76-
if (PLATFORM == "darwin") {
77+
if (PLATFORM == PlatformMacOS) {
7778
event.mousedata.cmd = event.mousedata.meta;
7879
event.mousedata.option = event.mousedata.alt;
7980
} else {

0 commit comments

Comments
 (0)