1- // Copyright 2025 , Command Line
1+ // Copyright 2026 , Command Line Inc.
22// SPDX-License-Identifier: Apache-2.0
33
4+ import { useWaveEnv , WaveEnv , WaveEnvSubset } from "@/app/waveenv/waveenv" ;
45import {
56 ExpandableMenu ,
67 ExpandableMenuItem ,
@@ -18,13 +19,23 @@ import { OverlayScrollbarsComponent } from "overlayscrollbars-react";
1819import { CSSProperties , forwardRef , useCallback , useEffect } from "react" ;
1920import WorkspaceSVG from "../asset/workspace.svg" ;
2021import { IconButton } from "../element/iconbutton" ;
21- import { atoms , getApi } from "../store/global" ;
2222import { WorkspaceService } from "../store/services" ;
2323import { getObjectValue , makeORef } from "../store/wos" ;
2424import { waveEventSubscribeSingle } from "../store/wps" ;
2525import { WorkspaceEditor } from "./workspaceeditor" ;
2626import "./workspaceswitcher.scss" ;
2727
28+ export type WorkspaceSwitcherEnv = WaveEnvSubset < {
29+ electron : {
30+ deleteWorkspace : WaveEnv [ "electron" ] [ "deleteWorkspace" ] ;
31+ createWorkspace : WaveEnv [ "electron" ] [ "createWorkspace" ] ;
32+ switchWorkspace : WaveEnv [ "electron" ] [ "switchWorkspace" ] ;
33+ } ;
34+ atoms : {
35+ workspace : WaveEnv [ "atoms" ] [ "workspace" ] ;
36+ } ;
37+ } > ;
38+
2839type WorkspaceListEntry = {
2940 windowId : string ;
3041 workspace : Workspace ;
@@ -35,8 +46,9 @@ const workspaceMapAtom = atom<WorkspaceList>([]);
3546const workspaceSplitAtom = splitAtom ( workspaceMapAtom ) ;
3647const editingWorkspaceAtom = atom < string > ( ) ;
3748const WorkspaceSwitcher = forwardRef < HTMLDivElement > ( ( _ , ref ) => {
49+ const env = useWaveEnv < WorkspaceSwitcherEnv > ( ) ;
3850 const setWorkspaceList = useSetAtom ( workspaceMapAtom ) ;
39- const activeWorkspace = useAtomValueSafe ( atoms . workspace ) ;
51+ const activeWorkspace = useAtomValueSafe ( env . atoms . workspace ) ;
4052 const workspaceList = useAtomValue ( workspaceSplitAtom ) ;
4153 const setEditingWorkspace = useSetAtom ( editingWorkspaceAtom ) ;
4254
@@ -71,7 +83,7 @@ const WorkspaceSwitcher = forwardRef<HTMLDivElement>((_, ref) => {
7183 } , [ ] ) ;
7284
7385 const onDeleteWorkspace = useCallback ( ( workspaceId : string ) => {
74- getApi ( ) . deleteWorkspace ( workspaceId ) ;
86+ env . electron . deleteWorkspace ( workspaceId ) ;
7587 } , [ ] ) ;
7688
7789 const isActiveWorkspaceSaved = ! ! ( activeWorkspace . name && activeWorkspace . icon ) ;
@@ -118,7 +130,7 @@ const WorkspaceSwitcher = forwardRef<HTMLDivElement>((_, ref) => {
118130
119131 < div className = "actions" >
120132 { isActiveWorkspaceSaved ? (
121- < ExpandableMenuItem onClick = { ( ) => getApi ( ) . createWorkspace ( ) } >
133+ < ExpandableMenuItem onClick = { ( ) => env . electron . createWorkspace ( ) } >
122134 < ExpandableMenuItemLeftElement >
123135 < i className = "fa-sharp fa-solid fa-plus" > </ i >
124136 </ ExpandableMenuItemLeftElement >
@@ -145,7 +157,8 @@ const WorkspaceSwitcherItem = ({
145157 entryAtom : PrimitiveAtom < WorkspaceListEntry > ;
146158 onDeleteWorkspace : ( workspaceId : string ) => void ;
147159} ) => {
148- const activeWorkspace = useAtomValueSafe ( atoms . workspace ) ;
160+ const env = useWaveEnv < WorkspaceSwitcherEnv > ( ) ;
161+ const activeWorkspace = useAtomValueSafe ( env . atoms . workspace ) ;
149162 const [ workspaceEntry , setWorkspaceEntry ] = useAtom ( entryAtom ) ;
150163 const [ editingWorkspace , setEditingWorkspace ] = useAtom ( editingWorkspaceAtom ) ;
151164
@@ -200,7 +213,7 @@ const WorkspaceSwitcherItem = ({
200213 >
201214 < ExpandableMenuItemGroupTitle
202215 onClick = { ( ) => {
203- getApi ( ) . switchWorkspace ( workspace . oid ) ;
216+ env . electron . switchWorkspace ( workspace . oid ) ;
204217 // Create a fake escape key event to close the popover
205218 document . dispatchEvent ( new KeyboardEvent ( "keydown" , { key : "Escape" } ) ) ;
206219 } }
0 commit comments