@@ -26,8 +26,11 @@ interface RecordedRegistration {
2626 readonly files : Array < { readonly path : string ; readonly content : string } > ;
2727 readonly commands : Array < { readonly command : string ; readonly args : ReadonlyArray < string > } > ;
2828 readonly copies : Array < { readonly source : string ; readonly destination : string } > ;
29+ readonly icons : Array < { readonly path : string ; readonly bytes : ReadonlyArray < number > } > ;
2930}
3031
32+ const ICON_BYTES = new Uint8Array ( [ 137 , 80 , 78 , 71 , 13 , 10 , 26 , 10 ] ) ;
33+
3134const makeEnvironment = ( path : Path . Path , overrides : Record < string , unknown > = { } ) =>
3235 DesktopEnvironment . DesktopEnvironment . of ( {
3336 platform : "linux" ,
@@ -69,7 +72,7 @@ const layerHandler = (
6972 readonly writeError ?: PlatformError . PlatformError ;
7073 readonly existingEntry ?: string ;
7174 readonly iconSource ?: string ;
72- readonly iconCopyError ?: PlatformError . PlatformError ;
75+ readonly iconWriteError ?: PlatformError . PlatformError ;
7376 } = { } ,
7477) =>
7578 DesktopLinuxUrlHandler . layer . pipe (
@@ -92,10 +95,25 @@ const layerHandler = (
9295 } ) ,
9396 FileSystem . layerNoop ( {
9497 copyFile : ( source , destination ) =>
95- input . iconCopyError
96- ? Effect . fail ( input . iconCopyError )
98+ Effect . sync ( ( ) => {
99+ recorded . copies . push ( { source, destination } ) ;
100+ } ) ,
101+ readFile : ( path ) =>
102+ path === input . iconSource
103+ ? Effect . succeed ( ICON_BYTES )
104+ : Effect . fail (
105+ PlatformError . systemError ( {
106+ _tag : "NotFound" ,
107+ module : "FileSystem" ,
108+ method : "readFile" ,
109+ pathOrDescriptor : path ,
110+ } ) ,
111+ ) ,
112+ writeFile : ( path , bytes ) =>
113+ input . iconWriteError
114+ ? Effect . fail ( input . iconWriteError )
97115 : Effect . sync ( ( ) => {
98- recorded . copies . push ( { source , destination } ) ;
116+ recorded . icons . push ( { path , bytes : [ ... bytes ] } ) ;
99117 } ) ,
100118 readFileString : ( ) => Effect . succeed ( input . existingEntry ?? "" ) ,
101119 makeDirectory : ( path ) =>
@@ -162,6 +180,7 @@ const emptyRecording = (): RecordedRegistration => ({
162180 files : [ ] ,
163181 commands : [ ] ,
164182 copies : [ ] ,
183+ icons : [ ] ,
165184} ) ;
166185
167186describe ( "DesktopLinuxUrlHandler" , ( ) => {
@@ -290,22 +309,21 @@ describe("DesktopLinuxUrlHandler", () => {
290309 } ) ,
291310 } ) ;
292311 assert . deepEqual ( recorded . files , [ ] ) ;
293- assert . deepEqual ( recorded . copies , [
294- { source : "/tmp/.mount_T3/resources/icon.png" , destination : iconPath } ,
295- ] ) ;
312+ assert . deepEqual ( recorded . copies , [ ] , "icon must not be copied out of the app bundle" ) ;
313+ assert . deepEqual ( recorded . icons , [ { path : iconPath , bytes : [ ...ICON_BYTES ] } ] ) ;
296314 assert . equal ( recorded . commands . at ( - 1 ) ?. command , "xdg-mime" ) ;
297315 } ) ;
298316 } ) ;
299317
300- it . effect ( "still registers the handler when copying its icon fails" , ( ) => {
318+ it . effect ( "still registers the handler when installing its icon fails" , ( ) => {
301319 const recorded = emptyRecording ( ) ;
302320 return Effect . gen ( function * ( ) {
303321 yield * runRegister ( recorded , {
304322 iconSource : "/tmp/.mount_T3/resources/icon.png" ,
305- iconCopyError : PlatformError . systemError ( {
323+ iconWriteError : PlatformError . systemError ( {
306324 _tag : "PermissionDenied" ,
307325 module : "FileSystem" ,
308- method : "copyFile " ,
326+ method : "writeFile " ,
309327 description : "read-only icon directory" ,
310328 } ) ,
311329 } ) ;
0 commit comments