@@ -167,6 +167,17 @@ export class DesktopSnapShotError extends Schema.TaggedError<DesktopSnapShotErro
167167
168168const isDesktopSnapShotError = Schema . is ( DesktopSnapShotError ) ;
169169
170+ class SnapShotShortcutError extends Schema . TaggedError < SnapShotShortcutError > ( ) (
171+ "SnapShotShortcutError" ,
172+ { cause : Schema . Defect ( ) } ,
173+ ) {
174+ override get message ( ) : string {
175+ return "Could not register the SnapShot shortcut." ;
176+ }
177+ }
178+
179+ const shortcutFailure = ( cause : unknown ) => new SnapShotShortcutError ( { cause } ) ;
180+
170181function captureFailure ( cause : unknown , captureId ?: string ) : DesktopSnapShotError {
171182 if ( isDesktopSnapShotError ( cause ) ) return cause ;
172183 const operation = cause instanceof CaptureSetupRequiredError ? "setup-required" : "capture" ;
@@ -1068,13 +1079,15 @@ export const make = Effect.gen(function* () {
10681079 if ( mode === "portal" ) {
10691080 return { available : false , message : WAYLAND_MODIFIER_PAIR_UNAVAILABLE_MESSAGE } ;
10701081 }
1071- const available = yield * Effect . tryPromise ( ( ) =>
1072- startPairShortcutProcess (
1073- snapShotShortcutModifierPair ( shortcut ) ,
1074- ( ) => undefined ,
1075- ( ) => undefined ,
1076- ) ,
1077- ) . pipe (
1082+ const available = yield * Effect . tryPromise ( {
1083+ try : ( ) =>
1084+ startPairShortcutProcess (
1085+ snapShotShortcutModifierPair ( shortcut ) ,
1086+ ( ) => undefined ,
1087+ ( ) => undefined ,
1088+ ) ,
1089+ catch : shortcutFailure ,
1090+ } ) . pipe (
10781091 Effect . tap ( ( stop ) => Effect . sync ( stop ) ) ,
10791092 Effect . as ( true ) ,
10801093 Effect . orElseSucceed ( ( ) => false ) ,
@@ -1089,7 +1102,10 @@ export const make = Effect.gen(function* () {
10891102 const systemConflict = snapShotShortcutSystemConflict ( shortcut ) ;
10901103 if ( systemConflict ) return { available : false , message : systemConflict } ;
10911104 if ( mode === "portal" ) {
1092- return yield * Effect . try ( ( ) => portalShortcutTrigger ( shortcut ) ) . pipe (
1105+ return yield * Effect . try ( {
1106+ try : ( ) => portalShortcutTrigger ( shortcut ) ,
1107+ catch : shortcutFailure ,
1108+ } ) . pipe (
10931109 Effect . match ( {
10941110 onSuccess : ( ) => ( {
10951111 available : true ,
@@ -1199,13 +1215,16 @@ export const make = Effect.gen(function* () {
11991215 return ;
12001216 }
12011217 if ( mode === "portal" && niriSocketPath ( ) ) {
1202- const registered = yield * Effect . tryPromise ( async ( ) => {
1203- const { startNiriCaptureShortcut } = await import ( "./NiriCaptureShortcut.ts" ) ;
1204- return startNiriCaptureShortcut ( linuxAppId , onCurrentShortcut , ( ) => {
1205- void runPromise (
1206- setShortcutFailure ( "The Niri capture endpoint disconnected. Restart T3 Code." ) ,
1207- ) . catch ( ( ) => undefined ) ;
1208- } ) ;
1218+ const registered = yield * Effect . tryPromise ( {
1219+ try : async ( ) => {
1220+ const { startNiriCaptureShortcut } = await import ( "./NiriCaptureShortcut.ts" ) ;
1221+ return startNiriCaptureShortcut ( linuxAppId , onCurrentShortcut , ( ) => {
1222+ void runPromise (
1223+ setShortcutFailure ( "The Niri capture endpoint disconnected. Restart T3 Code." ) ,
1224+ ) . catch ( ( ) => undefined ) ;
1225+ } ) ;
1226+ } ,
1227+ catch : shortcutFailure ,
12091228 } ) . pipe (
12101229 Effect . tap ( ( stop ) =>
12111230 Effect . sync ( ( ) => {
@@ -1249,29 +1268,32 @@ export const make = Effect.gen(function* () {
12491268 shortcutMessage : null ,
12501269 message : null ,
12511270 } ) ;
1252- yield * Effect . tryPromise ( async ( ) => {
1253- const { PortalCaptureShortcut } = await import ( "./PortalCaptureShortcut.ts" ) ;
1254- return new PortalCaptureShortcut (
1255- linuxAppId ,
1256- isModifierPairShortcut ( shortcut )
1257- ? {
1258- key : "2" ,
1259- ctrlKey : true ,
1260- modKey : false ,
1261- altKey : false ,
1262- shiftKey : true ,
1263- metaKey : false ,
1264- }
1265- : shortcut ,
1266- onCurrentShortcut ,
1267- ( ) => {
1268- if ( generation !== shortcutGeneration ) return ;
1269- shortcutVerified = false ;
1270- void runPromise ( emit ( { type : "shortcut-changed" } ) ) . catch ( ( ) => undefined ) ;
1271- } ,
1272- undefined ,
1273- hyprland ,
1274- ) ;
1271+ yield * Effect . tryPromise ( {
1272+ try : async ( ) => {
1273+ const { PortalCaptureShortcut } = await import ( "./PortalCaptureShortcut.ts" ) ;
1274+ return new PortalCaptureShortcut (
1275+ linuxAppId ,
1276+ isModifierPairShortcut ( shortcut )
1277+ ? {
1278+ key : "2" ,
1279+ ctrlKey : true ,
1280+ modKey : false ,
1281+ altKey : false ,
1282+ shiftKey : true ,
1283+ metaKey : false ,
1284+ }
1285+ : shortcut ,
1286+ onCurrentShortcut ,
1287+ ( ) => {
1288+ if ( generation !== shortcutGeneration ) return ;
1289+ shortcutVerified = false ;
1290+ void runPromise ( emit ( { type : "shortcut-changed" } ) ) . catch ( ( ) => undefined ) ;
1291+ } ,
1292+ undefined ,
1293+ hyprland ,
1294+ ) ;
1295+ } ,
1296+ catch : shortcutFailure ,
12751297 } ) . pipe (
12761298 Effect . tap ( ( registration ) =>
12771299 Effect . sync ( ( ) => {
@@ -1293,15 +1315,21 @@ export const make = Effect.gen(function* () {
12931315
12941316 let registered = false ;
12951317 if ( isModifierPairShortcut ( shortcut ) ) {
1296- registered = yield * Effect . tryPromise ( ( ) =>
1297- startPairShortcutProcess ( snapShotShortcutModifierPair ( shortcut ) , onCurrentShortcut , ( ) => {
1298- void pipe (
1299- snapShotShortcutRegistrationFailureMessage ( shortcut , environment . platform ) ,
1300- setShortcutFailure ,
1301- runPromise ,
1302- ) . catch ( ( ) => undefined ) ;
1303- } ) ,
1304- ) . pipe (
1318+ registered = yield * Effect . tryPromise ( {
1319+ try : ( ) =>
1320+ startPairShortcutProcess (
1321+ snapShotShortcutModifierPair ( shortcut ) ,
1322+ onCurrentShortcut ,
1323+ ( ) => {
1324+ void pipe (
1325+ snapShotShortcutRegistrationFailureMessage ( shortcut , environment . platform ) ,
1326+ setShortcutFailure ,
1327+ runPromise ,
1328+ ) . catch ( ( ) => undefined ) ;
1329+ } ,
1330+ ) ,
1331+ catch : shortcutFailure ,
1332+ } ) . pipe (
13051333 Effect . tap ( ( stop ) =>
13061334 Effect . sync ( ( ) => {
13071335 stopShiftShortcut = stop ;
@@ -1489,7 +1517,10 @@ export const make = Effect.gen(function* () {
14891517 if ( action === "retry-shortcut" ) {
14901518 const currentPortal = portalShortcut ;
14911519 if ( currentPortal ?. hasSession && ! currentPortal . state . shortcutPending ) {
1492- yield * Effect . tryPromise ( ( ) => currentPortal . configure ( ) ) . pipe (
1520+ yield * Effect . tryPromise ( {
1521+ try : ( ) => currentPortal . configure ( ) ,
1522+ catch : shortcutFailure ,
1523+ } ) . pipe (
14931524 Effect . mapError (
14941525 ( error ) =>
14951526 new DesktopSnapShotSetupError ( {
@@ -1583,9 +1614,12 @@ export const make = Effect.gen(function* () {
15831614 state : Ref . get ( stateRef ) . pipe (
15841615 Effect . flatMap ( ( state ) =>
15851616 state . mode === "portal"
1586- ? Effect . tryPromise ( async ( ) => {
1587- const { getLinuxCaptureSupport } = await import ( "./LinuxSnapShot.ts" ) ;
1588- return getLinuxCaptureSupport ( linuxAppId ) ;
1617+ ? Effect . tryPromise ( {
1618+ try : async ( ) => {
1619+ const { getLinuxCaptureSupport } = await import ( "./LinuxSnapShot.ts" ) ;
1620+ return getLinuxCaptureSupport ( linuxAppId ) ;
1621+ } ,
1622+ catch : ( cause ) => new DesktopSnapShotError ( { operation : "unsupported" , cause } ) ,
15891623 } ) . pipe (
15901624 Effect . map ( ( support ) => ( { ...state , ...support } ) ) ,
15911625 Effect . catch ( ( error ) =>
0 commit comments