3 * Copyright (c) 2007 - 2011, Blue Static <http://www.bluestatic.org>
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17 #import "AppDelegate.h"
19 #import <Sparkle/Sparkle.h>
21 #import "FileAccessController.h"
22 #import "PreferenceNames.h"
24 static NSString
* const kAppcastUnstable
= @
"appcast-unstable.xml";
26 @implementation AppDelegate
{
27 PreferencesController
* _prefsController
;
31 @synthesize breakpoint
;
32 @synthesize loggingController
= loggingController_
;
35 * Initialize method that is called before all other messages. This will set the default
41 NSDictionary
* defaults
= @
{
43 kPrefInspectorWindowVisible
: @YES,
44 kPrefPathReplacements
: [NSMutableArray array
],
46 kPrefFileAccessBookmarks
: [NSMutableDictionary dictionary
],
48 kPrefBreakOnFirstLine
: @YES,
49 kPrefDebuggerAttached
: @YES,
50 kPrefSelectedDebuggerSegment
: @1,
52 [[NSUserDefaults standardUserDefaults
] registerDefaults
:defaults
];
56 + (AppDelegate
*)instance
58 return (AppDelegate
*)[NSApp delegate
];
61 - (PreferencesController
*)prefsController
63 if (!_prefsController
)
64 _prefsController
= [[PreferencesController alloc
] init
];
65 return _prefsController
;
68 - (void)applicationDidFinishLaunching
:(NSNotification
*)notification
70 [[SUUpdater sharedUpdater
] setDelegate
:self];
73 [FileAccessController maybeShowFileAccessDialog
];
75 [self _activateSecureFileAccess
];
76 #endif // USE_APP_SANDBOX
79 - (void)applicationWillTerminate
:(NSNotification
*)notification
81 [[NSUserDefaults standardUserDefaults
] setBool
:self.debugger.connection.autoAttach
82 forKey
:kPrefDebuggerAttached
];
86 * Shows the debugger window
88 - (IBAction
)showDebuggerWindow
:(id)sender
90 [[debugger window
] makeKeyAndOrderFront
:self];
91 [debugger.segmentControl setSelectedSegment
:1];
95 * Shows the breakpoints window
97 - (IBAction
)showBreakpointWindow
:(id)sender
99 [[debugger window
] makeKeyAndOrderFront
:sender
];
100 [debugger.segmentControl setSelectedSegment
:2];
104 * Shows the preferences window. Lazily loads the PreferencesController.
106 - (IBAction
)showPreferences
:(id)sender
108 [self.prefsController showPreferencesWindow
];
112 * Opens the URL to the help page
114 - (IBAction
)openHelpPage
:(id)sender
116 [[NSWorkspace sharedWorkspace
] openURL
:[NSURL URLWithString
:@
"https://www.bluestatic.org/software/macgdbp/help/"]];
121 * Activates any secure file access bookmarks stored in preferences.
123 - (void)_activateSecureFileAccess
125 NSDictionary
* prefs
= [NSUserDefaults.standardUserDefaults objectForKey
:kPrefFileAccessBookmarks
];
126 NSMutableDictionary
<NSString
*, NSData
*>* bookmarks
= [NSMutableDictionary dictionaryWithDictionary
:prefs
];
127 for (NSString
* path
in bookmarks
) {
128 NSURL
* url
= [NSURL URLWithString
:path
];
132 url
= [NSURL URLByResolvingBookmarkData
:bookmarks
[path
]
133 options
:NSURLBookmarkResolutionWithSecurityScope
135 bookmarkDataIsStale
:&isStale
138 NSLog(@
"Failed to resolve secure bookmark for path %@: %@", path
, error
);
142 NSData
* newBookmark
= [PreferencesController secureBookmarkDataForURL
:url
];
143 bookmarks
[url.absoluteString
] = newBookmark
;
144 [bookmarks removeObjectForKey
:path
];
147 if (![url startAccessingSecurityScopedResource
]) {
148 NSLog(@
"Failed to start accessing resource %@", path
);
153 [NSUserDefaults.standardUserDefaults setObject
:bookmarks forKey
:kPrefFileAccessBookmarks
];
155 #endif // USE_APP_SANDBOX
157 ////////////////////////////////////////////////////////////////////////////////
158 #pragma mark SUUpdater Delegate
160 - (nullable NSString
*)feedURLStringForUpdater
:(SUUpdater
*)updater
162 // Record whether this user ever used the beta appcast feed.
163 NSUserDefaults
* defaults
= [NSUserDefaults standardUserDefaults
];
164 NSURL
* feedURL
= [NSURL URLWithString
:[[[NSBundle mainBundle
] infoDictionary
] objectForKey
:@
"SUFeedURL"]];
166 BOOL usesUnstable
= [defaults boolForKey
:kPrefUnstableVersionCast
] ||
167 [[feedURL absoluteString
] hasSuffix
:kAppcastUnstable
];
168 [defaults setBool
:usesUnstable forKey
:kPrefUnstableVersionCast
];
173 feedURL
= [[feedURL URLByDeletingLastPathComponent
] URLByAppendingPathComponent
:kAppcastUnstable
];
174 return [feedURL absoluteString
];