@@ -7,7 +7,7 @@ import { AllServiceTypes } from "@/app/store/services";
77import { handleWaveEvent } from "@/app/store/wps" ;
88import { RpcApiType } from "@/app/store/wshclientapi" ;
99import { WaveEnv } from "@/app/waveenv/waveenv" ;
10- import { PlatformMacOS , PlatformWindows } from "@/util/platformutil" ;
10+ import { PlatformLinux , PlatformMacOS , PlatformWindows } from "@/util/platformutil" ;
1111import { Atom , atom , PrimitiveAtom , useAtomValue } from "jotai" ;
1212import { DefaultFullConfig } from "./defaultconfig" ;
1313import { DefaultMockFilesystem } from "./mockfilesystem" ;
@@ -20,8 +20,13 @@ import { previewElectronApi } from "./preview-electron-api";
2020// - rpc.EventPublishCommand -- dispatches to handleWaveEvent(); works when the subscriber
2121// is purely FE-based (registered via WPS on the frontend)
2222// - rpc.GetMetaCommand -- reads .meta from the mock WOS atom for the given oref
23+ // - rpc.GetSecretsCommand -- reads secrets from an in-memory mock secret store
24+ // - rpc.GetSecretsLinuxStorageBackendCommand
25+ // returns "libsecret" on Linux previews and "" elsewhere
26+ // - rpc.GetSecretsNamesCommand -- lists secret names from the in-memory mock secret store
2327// - rpc.SetMetaCommand -- writes .meta to the mock WOS atom (null values delete keys)
2428// - rpc.SetConfigCommand -- merges settings into fullConfigAtom (null values delete keys)
29+ // - rpc.SetSecretsCommand -- writes/deletes secrets in the in-memory mock secret store
2530// - rpc.UpdateTabNameCommand -- updates .name on the Tab WaveObj in the mock WOS
2631// - rpc.UpdateWorkspaceTabIdsCommand -- updates .tabids on the Workspace WaveObj in the mock WOS
2732//
@@ -172,11 +177,13 @@ type MockWosFns = {
172177 getWaveObjectAtom : < T extends WaveObj > ( oref : string ) => PrimitiveAtom < T > ;
173178 mockSetWaveObj : < T extends WaveObj > ( oref : string , obj : T ) => void ;
174179 fullConfigAtom : PrimitiveAtom < FullConfigType > ;
180+ platform : NodeJS . Platform ;
175181} ;
176182
177183export function makeMockRpc ( overrides : RpcOverrides , wos : MockWosFns ) : RpcApiType {
178184 const callDispatchMap = new Map < string , ( ...args : any [ ] ) => Promise < any > > ( ) ;
179185 const streamDispatchMap = new Map < string , ( ...args : any [ ] ) => AsyncGenerator < any , void , boolean > > ( ) ;
186+ const secrets = new Map < string , string > ( ) ;
180187 const setCallHandler = ( command : string , fn : ( ...args : any [ ] ) => Promise < any > ) => {
181188 callDispatchMap . set ( command , fn ) ;
182189 } ;
@@ -230,6 +237,35 @@ export function makeMockRpc(overrides: RpcOverrides, wos: MockWosFns): RpcApiTyp
230237 globalStore . set ( wos . fullConfigAtom , { ...current , settings : updatedSettings as SettingsType } ) ;
231238 return null ;
232239 } ) ;
240+ setCallHandler ( "getsecretslinuxstoragebackend" , async ( ) => {
241+ if ( wos . platform !== PlatformLinux ) {
242+ return "" ;
243+ }
244+ return "libsecret" ;
245+ } ) ;
246+ setCallHandler ( "getsecretsnames" , async ( ) => {
247+ return Array . from ( secrets . keys ( ) ) . sort ( ) ;
248+ } ) ;
249+ setCallHandler ( "getsecrets" , async ( _client , data : string [ ] ) => {
250+ const foundSecrets : Record < string , string > = { } ;
251+ for ( const name of data ?? [ ] ) {
252+ const value = secrets . get ( name ) ;
253+ if ( value != null ) {
254+ foundSecrets [ name ] = value ;
255+ }
256+ }
257+ return foundSecrets ;
258+ } ) ;
259+ setCallHandler ( "setsecrets" , async ( _client , data : Record < string , string > ) => {
260+ for ( const [ name , value ] of Object . entries ( data ?? { } ) ) {
261+ if ( value == null ) {
262+ secrets . delete ( name ) ;
263+ continue ;
264+ }
265+ secrets . set ( name , value ) ;
266+ }
267+ return null ;
268+ } ) ;
233269 setCallHandler ( "updateworkspacetabids" , async ( _client , data : { args : [ string , string [ ] ] } ) => {
234270 const [ workspaceId , tabIds ] = data . args ;
235271 const wsORef = "workspace:" + workspaceId ;
@@ -319,6 +355,7 @@ export function makeMockWaveEnv(mockEnv?: MockEnv): MockWaveEnv {
319355 const mockWosFns : MockWosFns = {
320356 getWaveObjectAtom,
321357 fullConfigAtom : atoms . fullConfigAtom ,
358+ platform,
322359 mockSetWaveObj : < T extends WaveObj > ( oref : string , obj : T ) => {
323360 if ( ! waveObjectValueAtomCache . has ( oref ) ) {
324361 waveObjectValueAtomCache . set ( oref , atom ( null as WaveObj ) ) ;
0 commit comments