77import { parseKeybindingShortcut } from "@t3tools/shared/keybindings" ;
88import { FileDiff } from "@pierre/diffs/react" ;
99import { parseDiffFromFile } from "@pierre/diffs" ;
10- import { useMemo , useState } from "react" ;
10+ import { settlePromise } from "@t3tools/client-runtime/state/runtime" ;
11+ import * as Cause from "effect/Cause" ;
12+ import { useState } from "react" ;
1113import { getDesktopSnapShotBridge } from "../../lib/desktopSnapShot" ;
1214import { resolveDiffThemeName } from "../../lib/diffRendering" ;
1315import { useTheme } from "../../hooks/useTheme" ;
@@ -69,16 +71,13 @@ export function CaptureShortcutConfig({
6971 } ,
7072 } ) ;
7173 const actionBusy = busy || recorder . recording ;
72- const diff = useMemo (
73- ( ) =>
74- preview && changed
75- ? parseDiffFromFile (
76- { name : preview . path , contents : preview . before } ,
77- { name : preview . path , contents : preview . after } ,
78- )
79- : null ,
80- [ preview , changed ] ,
81- ) ;
74+ const diff =
75+ preview && changed
76+ ? parseDiffFromFile (
77+ { name : preview . path , contents : preview . before } ,
78+ { name : preview . path , contents : preview . after } ,
79+ )
80+ : null ;
8281 const begin = ( phase : "reading" | "writing" ) => {
8382 setWorking ( phase ) ;
8483 onBusyChange ?.( true ) ;
@@ -94,28 +93,29 @@ export function CaptureShortcutConfig({
9493 setPreview ( null ) ;
9594 setResult ( null ) ;
9695 setCustomFile ( chooseFile ) ;
97- try {
98- setPreview (
99- await bridge . previewSnapShotConfig ( {
100- operation,
101- chooseFile,
102- ...( keys ?. trim ( ) ? { shortcut : keys . trim ( ) } : { } ) ,
103- } ) ,
104- ) ;
105- } catch ( cause ) {
96+ const previewed = await settlePromise ( ( ) =>
97+ bridge . previewSnapShotConfig ! ( {
98+ operation,
99+ chooseFile,
100+ ...( keys ?. trim ( ) ? { shortcut : keys . trim ( ) } : { } ) ,
101+ } ) ,
102+ ) ;
103+ if ( previewed . _tag === "Success" ) {
104+ setPreview ( previewed . value ) ;
105+ } else {
106+ const cause = Cause . squash ( previewed . cause ) ;
106107 setError ( {
107108 message : "Couldn't prepare the changes. Check Advanced for help." ,
108109 ...( cause instanceof Error ? { detail : cause . message } : { } ) ,
109110 } ) ;
110- } finally {
111- end ( ) ;
112111 }
112+ end ( ) ;
113113 } ;
114114 const apply = async ( ) => {
115115 if ( actionBusy || ! preview || ! bridge ?. applySnapShotConfig ) return ;
116116 begin ( "writing" ) ;
117- try {
118- const applied = await bridge . applySnapShotConfig ( preview . id ) ;
117+ const saved = await settlePromise ( async ( ) => {
118+ const applied = await bridge . applySnapShotConfig ! ( preview . id ) ;
119119 setResult ( applied ) ;
120120 await onSaved ?.( ) ;
121121 if ( ! applied . warning && preview . operation === "install" && onComplete ) {
@@ -126,15 +126,16 @@ export function CaptureShortcutConfig({
126126 } ) ;
127127 await onComplete ( ) ;
128128 }
129- } catch ( cause ) {
129+ } ) ;
130+ if ( saved . _tag === "Failure" ) {
131+ const cause = Cause . squash ( saved . cause ) ;
130132 setError ( {
131133 message : "Couldn't save your shortcut. Review the changes and try again." ,
132134 ...( cause instanceof Error ? { detail : cause . message } : { } ) ,
133135 } ) ;
134136 setPreview ( null ) ;
135- } finally {
136- end ( ) ;
137137 }
138+ end ( ) ;
138139 } ;
139140
140141 return (
0 commit comments