11import * as NodeServices from "@effect/platform-node/NodeServices" ;
22import { assert , describe , it } from "@effect/vitest" ;
33import * as Deferred from "effect/Deferred" ;
4+ import { DesktopSnapShotId } from "@t3tools/contracts" ;
45import * as Effect from "effect/Effect" ;
56import * as Fiber from "effect/Fiber" ;
67import * as Layer from "effect/Layer" ;
@@ -45,7 +46,7 @@ import * as ElectronTheme from "../electron/ElectronTheme.ts";
4546import * as ElectronWindow from "../electron/ElectronWindow.ts" ;
4647import {
4748 MENU_ACTION_CHANNEL ,
48- SNAP_SHOT_READY_CHANNEL ,
49+ SNAP_SHOT_EVENT_CHANNEL ,
4950 WINDOW_FULLSCREEN_STATE_CHANNEL ,
5051} from "../ipc/channels.ts" ;
5152import * as DesktopServerExposure from "../backend/DesktopServerExposure.ts" ;
@@ -407,6 +408,9 @@ const makeSplashScenario = (createOutcomes: readonly (Electron.BrowserWindow | n
407408 return { layer, createCalls, mainWindow, revealedWindows } as const ;
408409 } ) ;
409410
411+ const captureOne = DesktopSnapShotId . make ( "11111111-1111-4111-8111-111111111111" ) ;
412+ const captureTwo = DesktopSnapShotId . make ( "22222222-2222-4222-8222-222222222222" ) ;
413+
410414describe ( "DesktopWindow" , ( ) => {
411415 it ( "leaves fullscreen before concealing a pending quit" , ( ) => {
412416 const fakeWindow = makeFakeBrowserWindow ( ) ;
@@ -1292,20 +1296,18 @@ describe("DesktopWindow", () => {
12921296 yield * Effect . gen ( function * ( ) {
12931297 const desktopWindow = yield * DesktopWindow . DesktopWindow ;
12941298 yield * desktopWindow . handleBackendReady ( new URL ( "http://127.0.0.1:3773" ) ) ;
1295- yield * desktopWindow . dispatchMenuAction ( "snap-shot- started:capture-1" ) ;
1299+ yield * desktopWindow . dispatchSnapShotEvent ( { type : " started" , id : captureOne } ) ;
12961300 assert . equal ( foreground , "T3 Code" ) ;
12971301 foreground = "Explorer" ;
1298- yield * desktopWindow . dispatchSnapShotReady ( "capture-1" ) ;
1299- yield * desktopWindow . dispatchMenuAction ( "snap-shot-failed:capture-2" , {
1300- reveal : false ,
1301- } ) ;
1302+ yield * desktopWindow . dispatchSnapShotEvent ( { type : "ready" , id : captureOne } ) ;
1303+ yield * desktopWindow . dispatchSnapShotEvent ( { type : "failed" , id : captureTwo } ) ;
13021304
13031305 assert . equal ( foreground , "Explorer" ) ;
13041306 assert . deepEqual ( operations , [ "send" , "reveal" , "send" , "send" ] ) ;
13051307 assert . deepEqual ( fakeWindow . send . mock . calls , [
1306- [ MENU_ACTION_CHANNEL , "snap-shot- started:capture-1" ] ,
1307- [ SNAP_SHOT_READY_CHANNEL , "capture-1" ] ,
1308- [ MENU_ACTION_CHANNEL , "snap-shot- failed:capture-2" ] ,
1308+ [ SNAP_SHOT_EVENT_CHANNEL , { type : " started" , id : captureOne } ] ,
1309+ [ SNAP_SHOT_EVENT_CHANNEL , { type : "ready" , id : captureOne } ] ,
1310+ [ SNAP_SHOT_EVENT_CHANNEL , { type : " failed" , id : captureTwo } ] ,
13091311 ] ) ;
13101312 } ) . pipe ( Effect . provide ( layer ) ) ;
13111313 } ) ,
@@ -1328,10 +1330,12 @@ describe("DesktopWindow", () => {
13281330 yield * Effect . gen ( function * ( ) {
13291331 const desktopWindow = yield * DesktopWindow . DesktopWindow ;
13301332 yield * desktopWindow . handleBackendReady ( new URL ( "http://127.0.0.1:3773" ) ) ;
1331- yield * Effect . exit ( desktopWindow . dispatchMenuAction ( "snap-shot-started:capture-1" ) ) ;
1333+ yield * Effect . exit (
1334+ desktopWindow . dispatchSnapShotEvent ( { type : "started" , id : captureOne } ) ,
1335+ ) ;
13321336
13331337 assert . deepEqual ( fakeWindow . send . mock . calls , [
1334- [ MENU_ACTION_CHANNEL , "snap-shot- started:capture-1" ] ,
1338+ [ SNAP_SHOT_EVENT_CHANNEL , { type : " started" , id : captureOne } ] ,
13351339 ] ) ;
13361340 } ) . pipe ( Effect . provide ( layer ) ) ;
13371341 } ) ,
@@ -1345,7 +1349,7 @@ describe("DesktopWindow", () => {
13451349 yield * Effect . gen ( function * ( ) {
13461350 const desktopWindow = yield * DesktopWindow . DesktopWindow ;
13471351 yield * desktopWindow . showConnectingSplash ;
1348- yield * desktopWindow . dispatchSnapShotReady ( "capture-1" ) ;
1352+ yield * desktopWindow . dispatchSnapShotEvent ( { type : "ready" , id : captureOne } ) ;
13491353
13501354 assert . equal ( yield * Ref . get ( scenario . createCalls ) , 1 ) ;
13511355 assert . equal ( splash . send . mock . calls . length , 0 ) ;
@@ -1367,7 +1371,7 @@ describe("DesktopWindow", () => {
13671371 yield * desktopWindow . handleBackendReady ( new URL ( "http://127.0.0.1:3773" ) ) ;
13681372 fakeWindow . isDestroyed . mockReturnValue ( true ) ;
13691373 yield * Ref . set ( mainWindow , Option . none ( ) ) ;
1370- yield * desktopWindow . dispatchSnapShotReady ( "capture-1" ) ;
1374+ yield * desktopWindow . dispatchSnapShotEvent ( { type : "ready" , id : captureOne } ) ;
13711375
13721376 assert . equal ( yield * Ref . get ( createCount ) , 1 ) ;
13731377 assert . equal ( fakeWindow . send . mock . calls . length , 0 ) ;
@@ -1389,15 +1393,17 @@ describe("DesktopWindow", () => {
13891393
13901394 yield * Effect . gen ( function * ( ) {
13911395 const desktopWindow = yield * DesktopWindow . DesktopWindow ;
1392- yield * desktopWindow . dispatchSnapShotReady ( "capture-1" ) ;
1396+ yield * desktopWindow . dispatchSnapShotEvent ( { type : "ready" , id : captureOne } ) ;
13931397 assert . equal ( fakeWindow . send . mock . calls . length , 0 ) ;
13941398 const onLoad = fakeWindow . webContentsOnce . mock . calls . find (
13951399 ( [ event ] ) => event === "did-finish-load" ,
13961400 ) ?. [ 1 ] ;
13971401 assert . isDefined ( onLoad ) ;
13981402 onLoad ?.( ) ;
13991403
1400- assert . deepEqual ( fakeWindow . send . mock . calls , [ [ SNAP_SHOT_READY_CHANNEL , "capture-1" ] ] ) ;
1404+ assert . deepEqual ( fakeWindow . send . mock . calls , [
1405+ [ SNAP_SHOT_EVENT_CHANNEL , { type : "ready" , id : captureOne } ] ,
1406+ ] ) ;
14011407 assert . equal ( onReveal . mock . calls . length , 0 ) ;
14021408 assert . equal ( yield * Ref . get ( createCount ) , 0 ) ;
14031409 } ) . pipe ( Effect . provide ( layer ) ) ;
0 commit comments