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
],
45 kPrefPhpPath
: @
"/usr/bin/php",
47 kPrefFileAccessBookmarks
: [NSMutableDictionary dictionary
],
49 kPrefBreakOnFirstLine
: @YES,
50 kPrefDebuggerAttached
: @YES,
51 kPrefSelectedDebuggerSegment
: @1,
53 [[NSUserDefaults standardUserDefaults
] registerDefaults
:defaults
];
57 + (AppDelegate
*)instance
59 return (AppDelegate
*)[NSApp delegate
];
62 - (PreferencesController
*)prefsController
64 if (!_prefsController
)
65 _prefsController
= [[PreferencesController alloc
] init
];
66 return _prefsController
;
69 - (void)applicationDidFinishLaunching
:(NSNotification
*)notification
71 [[SUUpdater sharedUpdater
] setDelegate
:self];
74 [FileAccessController maybeShowFileAccessDialog
];
76 [self _activateSecureFileAccess
];
77 #endif // USE_APP_SANDBOX
80 - (void)applicationWillTerminate
:(NSNotification
*)notification
82 [[NSUserDefaults standardUserDefaults
] setBool
:self.debugger.connection.autoAttach
83 forKey
:kPrefDebuggerAttached
];
87 * Shows the debugger window
89 - (IBAction
)showDebuggerWindow
:(id)sender
91 [[debugger window
] makeKeyAndOrderFront
:self];
92 [debugger.segmentControl setSelectedSegment
:1];
96 * Shows the breakpoints window
98 - (IBAction
)showBreakpointWindow
:(id)sender
100 [[debugger window
] makeKeyAndOrderFront
:sender
];
101 [debugger.segmentControl setSelectedSegment
:2];
105 * Shows the preferences window. Lazily loads the PreferencesController.
107 - (IBAction
)showPreferences
:(id)sender
109 [self.prefsController showPreferencesWindow
];
113 * Opens the URL to the help page
115 - (IBAction
)openHelpPage
:(id)sender
117 [[NSWorkspace sharedWorkspace
] openURL
:[NSURL URLWithString
:@
"https://www.bluestatic.org/software/macgdbp/help/"]];
122 * Activates any secure file access bookmarks stored in preferences.
124 - (void)_activateSecureFileAccess
126 NSDictionary
* prefs
= [NSUserDefaults.standardUserDefaults objectForKey
:kPrefFileAccessBookmarks
];
127 NSMutableDictionary
<NSString
*, NSData
*>* bookmarks
= [NSMutableDictionary dictionaryWithDictionary
:prefs
];
128 for (NSString
* path
in bookmarks
) {
129 NSURL
* url
= [NSURL URLWithString
:path
];
133 url
= [NSURL URLByResolvingBookmarkData
:bookmarks
[path
]
134 options
:NSURLBookmarkResolutionWithSecurityScope
136 bookmarkDataIsStale
:&isStale
139 NSLog(@
"Failed to resolve secure bookmark for path %@: %@", path
, error
);
143 NSData
* newBookmark
= [PreferencesController secureBookmarkDataForURL
:url
];
144 bookmarks
[url.absoluteString
] = newBookmark
;
145 [bookmarks removeObjectForKey
:path
];
148 if (![url startAccessingSecurityScopedResource
]) {
149 NSLog(@
"Failed to start accessing resource %@", path
);
154 [NSUserDefaults.standardUserDefaults setObject
:bookmarks forKey
:kPrefFileAccessBookmarks
];
156 #endif // USE_APP_SANDBOX
158 ////////////////////////////////////////////////////////////////////////////////
159 #pragma mark SUUpdater Delegate
161 - (nullable NSString
*)feedURLStringForUpdater
:(SUUpdater
*)updater
163 // Record whether this user ever used the beta appcast feed.
164 NSUserDefaults
* defaults
= [NSUserDefaults standardUserDefaults
];
165 NSURL
* feedURL
= [NSURL URLWithString
:[[[NSBundle mainBundle
] infoDictionary
] objectForKey
:@
"SUFeedURL"]];
167 BOOL usesUnstable
= [defaults boolForKey
:kPrefUnstableVersionCast
] ||
168 [[feedURL absoluteString
] hasSuffix
:kAppcastUnstable
];
169 [defaults setBool
:usesUnstable forKey
:kPrefUnstableVersionCast
];
174 feedURL
= [[feedURL URLByDeletingLastPathComponent
] URLByAppendingPathComponent
:kAppcastUnstable
];
175 return [feedURL absoluteString
];