@@ -10,26 +10,37 @@ let contentTypes = [
1010] . compactMap { $0} // removes nil
1111
1212struct SettingsView : View {
13+ @State private var isDefault : Bool = false
14+ let timer = Timer . publish ( every: 1 , on: . main, in: . common) . autoconnect ( )
15+
1316 var body : some View {
1417 Form {
1518 LabeledContent ( " Version: " , value: Bundle . main. infoDictionary ? [ " CFBundleShortVersionString " ] as? String ?? " 0.0.0 " )
1619 . padding ( 1 )
1720
1821 LabeledContent ( " Default: " ) {
1922 VStack ( alignment: . leading) {
20- if ( isDefaultHandler ( for : contentTypes ) ) {
23+ if ( isDefault ) {
2124 Text ( " guppy is the default app " )
2225 } else {
2326 Text ( " guppy is not the default app " )
2427 }
2528 Button ( " Set as default " ) {
2629 setDefaultHandler ( for: contentTypes)
27- } . disabled ( isDefaultHandler ( for : contentTypes ) )
30+ } . disabled ( isDefault )
2831 }
2932 }
3033 }
3134 . padding ( )
3235 . frame ( width: 300 , height: 200 )
36+ . onAppear {
37+ // Check initial state
38+ isDefault = isDefaultHandler ( for: contentTypes)
39+ }
40+ . onReceive ( timer) { _ in
41+ // Periodically check if status has changed
42+ isDefault = isDefaultHandler ( for: contentTypes)
43+ }
3344 }
3445}
3546
@@ -57,9 +68,9 @@ func setDefaultHandler(for contentTypes: [UTType]) {
5768 for contentType in contentTypes {
5869 NSWorkspace . shared. setDefaultApplication ( at: appURL, toOpen: contentType) { error in
5970 if let error = error {
60- print ( " Failed to set default handler: \( error. localizedDescription) " )
71+ NSLog ( " Failed to set default handler: \( error. localizedDescription) " )
6172 } else {
62- print ( " Default application request sent successfully. \( contentType. identifier) " )
73+ NSLog ( " Default application request sent successfully. \( contentType. identifier) " )
6374 }
6475 }
6576 }
0 commit comments