@@ -3,7 +3,7 @@ import * as NodeHttp from "node:http";
33import * as NodePath from "@effect/platform-node/NodePath" ;
44import { codexAuthHandoffUrl , readCodexAuthDelivery } from "@t3tools/shared/codexAuthHandoff" ;
55import { EnvironmentId , ProviderInstanceId } from "@t3tools/contracts" ;
6- import { HostProcessArguments } from "@t3tools/shared/hostProcess " ;
6+ import * as HostProcess from "@t3tools/shared/HostProcess " ;
77import { assert , describe , it } from "@effect/vitest" ;
88import * as Cause from "effect/Cause" ;
99import * as Effect from "effect/Effect" ;
@@ -35,9 +35,16 @@ import * as ElectronApp from "../electron/ElectronApp.ts";
3535import * as ElectronShell from "../electron/ElectronShell.ts" ;
3636import * as ElectronWindow from "../electron/ElectronWindow.ts" ;
3737import * as DesktopClerk from "./DesktopClerk.ts" ;
38+ import * as DesktopWebLinks from "./DesktopWebLinks.ts" ;
3839import * as DesktopEnvironment from "./DesktopEnvironment.ts" ;
3940import * as DesktopPreReadyFileSystem from "./DesktopPreReadyFileSystem.ts" ;
4041
42+ /** Clerk forwards web links; tests that are not about links ignore them. */
43+ const ignoreWebLinks = DesktopWebLinks . DesktopWebLinks . of ( {
44+ receive : ( ) => Effect . void ,
45+ setRendererReady : ( ) => Effect . void ,
46+ } ) ;
47+
4148const layerDesktopClerk = (
4249 isDevelopment = true ,
4350 events : string [ ] = [ ] ,
@@ -220,11 +227,12 @@ describe("DesktopClerk", () => {
220227
221228 assert . isTrue ( Exit . isSuccess ( exit ) ) ;
222229 assert . equal ( quit . mock . calls . length , 0 ) ;
223- assert . deepEqual ( registeredEvents , [ "open-url" , "second-instance" ] ) ;
230+ assert . deepEqual ( registeredEvents , [ "open-url" , "open-file" , " second-instance"] ) ;
224231 } ) . pipe (
225232 Effect . provide ( layerDesktopClerk ( ) ) ,
226233 Effect . provideService ( ElectronApp . ElectronApp , electronApp ) ,
227234 Effect . provideService ( ElectronWindow . ElectronWindow , electronWindow ) ,
235+ Effect . provideService ( DesktopWebLinks . DesktopWebLinks , ignoreWebLinks ) ,
228236 ) ;
229237 } ) ;
230238
@@ -253,6 +261,7 @@ describe("DesktopClerk", () => {
253261 Effect . provide ( layerDesktopClerk ( ) ) ,
254262 Effect . provideService ( ElectronApp . ElectronApp , electronApp ) ,
255263 Effect . provideService ( ElectronWindow . ElectronWindow , electronWindow ) ,
264+ Effect . provideService ( DesktopWebLinks . DesktopWebLinks , ignoreWebLinks ) ,
256265 ) ;
257266 } ) ;
258267} ) ;
@@ -299,6 +308,7 @@ it.effect(
299308 Effect . provide ( layerDesktopClerk ( ) ) ,
300309 Effect . provideService ( ElectronApp . ElectronApp , electronApp ) ,
301310 Effect . provideService ( ElectronWindow . ElectronWindow , electronWindow ) ,
311+ Effect . provideService ( DesktopWebLinks . DesktopWebLinks , ignoreWebLinks ) ,
302312 ) ;
303313 } ,
304314) ;
@@ -375,12 +385,60 @@ it.effect.each(["startup", "open-url"] as const)(
375385 assert . strictEqual ( delivery ?. returnUrl , request . returnUrl ) ;
376386 } ) . pipe (
377387 Effect . provide ( layerDesktopClerk ( true , [ ] , "darwin" , undefined , shell ) ) ,
378- Effect . provideService ( HostProcessArguments , entry === "startup" ? [ "t3" , link ] : [ "t3" ] ) ,
388+ Effect . provideService ( HostProcess . Arguments , entry === "startup" ? [ "t3" , link ] : [ "t3" ] ) ,
379389 Effect . provideService ( ElectronApp . ElectronApp , electronApp ) ,
380390 Effect . provideService (
381391 ElectronWindow . ElectronWindow ,
382392 { } as ElectronWindow . ElectronWindow [ "Service" ] ,
383393 ) ,
394+ Effect . provideService ( DesktopWebLinks . DesktopWebLinks , ignoreWebLinks ) ,
384395 ) ;
385396 } ) . pipe ( Effect . scoped ) ,
386397) ;
398+
399+ it . effect ( "hands a web link to the renderer and leaves other links alone" , ( ) =>
400+ Effect . gen ( function * ( ) {
401+ storageMock . mockReturnValue ( storageAdapter ) ;
402+ createClerkBridgeMock . mockReturnValue ( { cleanup : vi . fn ( ) , isPrimaryInstance : true } ) ;
403+ const listeners = new Map < string , ( ...args : unknown [ ] ) => void > ( ) ;
404+ const electronApp = {
405+ whenReady : Effect . void ,
406+ on : ( name : string , listener : ( ...args : unknown [ ] ) => void ) =>
407+ Effect . sync ( ( ) => {
408+ listeners . set ( name , listener ) ;
409+ } ) ,
410+ } as unknown as ElectronApp . ElectronApp [ "Service" ] ;
411+ const received : Array < string > = [ ] ;
412+ yield * Effect . gen ( function * ( ) {
413+ const clerk = yield * DesktopClerk . DesktopClerk ;
414+ yield * clerk . configure ;
415+ const open = ( url : string ) => {
416+ const event = { preventDefault : vi . fn ( ) } ;
417+ listeners . get ( "open-url" ) ! ( event , url ) ;
418+ return event . preventDefault . mock . calls . length ;
419+ } ;
420+ // macOS hands the default browser every web link.
421+ assert . strictEqual ( open ( "https://example.com/page" ) , 1 ) ;
422+ assert . strictEqual ( open ( "http://localhost:3000/" ) , 1 ) ;
423+ // Anything else is not a web page; Electron keeps its own handling.
424+ assert . strictEqual ( open ( "mailto:[email protected] " ) , 0 ) ; 425+ yield * Effect . yieldNow ;
426+ assert . deepStrictEqual ( received , [ "https://example.com/page" , "http://localhost:3000/" ] ) ;
427+ } ) . pipe (
428+ Effect . provide ( layerDesktopClerk ( true , [ ] , "darwin" ) ) ,
429+ Effect . provideService ( HostProcess . Arguments , [ "t3" ] ) ,
430+ Effect . provideService ( ElectronApp . ElectronApp , electronApp ) ,
431+ Effect . provideService (
432+ ElectronWindow . ElectronWindow ,
433+ { } as ElectronWindow . ElectronWindow [ "Service" ] ,
434+ ) ,
435+ Effect . provideService (
436+ DesktopWebLinks . DesktopWebLinks ,
437+ DesktopWebLinks . DesktopWebLinks . of ( {
438+ receive : ( url ) => Effect . sync ( ( ) => void received . push ( url ) ) ,
439+ setRendererReady : ( ) => Effect . void ,
440+ } ) ,
441+ ) ,
442+ ) ;
443+ } ) . pipe ( Effect . scoped ) ,
444+ ) ;
0 commit comments