mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 00:02:28 +00:00
Finished implenting custom browser support
With this change, another localized string for OTHER_BROWSER will be needed as well. I've also set the project to use 2 spaces for tabs by default since that is the coding style you use in the project.
This commit is contained in:
@@ -1510,7 +1510,9 @@
|
|||||||
4C77E36515B84A240093A587 /* Frameworks */,
|
4C77E36515B84A240093A587 /* Frameworks */,
|
||||||
4C77E36315B84A240093A587 /* Products */,
|
4C77E36315B84A240093A587 /* Products */,
|
||||||
);
|
);
|
||||||
|
indentWidth = 2;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
|
tabWidth = 2;
|
||||||
};
|
};
|
||||||
4C77E36315B84A240093A587 /* Products */ = {
|
4C77E36315B84A240093A587 /* Products */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="5056" systemVersion="13E28" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<deployment defaultVersion="1080" identifier="macosx"/>
|
<deployment defaultVersion="1080" identifier="macosx"/>
|
||||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
|
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="5056"/>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<objects>
|
<objects>
|
||||||
<customObject id="-2" userLabel="File's Owner" customClass="MPWorkflowSettingsController">
|
<customObject id="-2" userLabel="File's Owner" customClass="MPWorkflowSettingsController">
|
||||||
@@ -91,7 +91,7 @@
|
|||||||
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ehI-gq-lsb">
|
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ehI-gq-lsb">
|
||||||
<rect key="frame" x="116" y="113" width="134" height="26"/>
|
<rect key="frame" x="116" y="113" width="134" height="26"/>
|
||||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
<popUpButtonCell key="cell" type="push" title="Default Browser" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" enabled="NO" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="7YX-EA-9KA" id="7Ip-sU-sAK">
|
<popUpButtonCell key="cell" type="push" title="Default Browser" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="7YX-EA-9KA" id="7Ip-sU-sAK">
|
||||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||||
<font key="font" metaFont="menu"/>
|
<font key="font" metaFont="menu"/>
|
||||||
<menu key="menu" title="OtherViews" id="XgO-Tj-QjO">
|
<menu key="menu" title="OtherViews" id="XgO-Tj-QjO">
|
||||||
@@ -129,4 +129,4 @@
|
|||||||
</constraints>
|
</constraints>
|
||||||
</customView>
|
</customView>
|
||||||
</objects>
|
</objects>
|
||||||
</document>
|
</document>
|
||||||
|
|||||||
@@ -621,9 +621,17 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell";
|
|||||||
if(!scheme) {
|
if(!scheme) {
|
||||||
webURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", [selectedEntry.url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
|
webURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@", [selectedEntry.url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
|
||||||
}
|
}
|
||||||
[[NSWorkspace sharedWorkspace] openURL:webURL];
|
|
||||||
/* Add custom browser support */
|
NSString *browserBundleID = [[NSUserDefaults standardUserDefaults] objectForKey:kMPSettingsKeyBrowserBundleId];
|
||||||
//[[NSWorkspace sharedWorkspace] openURLs:@[webURL] withAppBundleIdentifier:@"org.mozilla.firefox" options:NSWorkspaceLaunchAsync additionalEventParamDescriptor:nil launchIdentifiers:NULL];
|
BOOL launched = NO;
|
||||||
|
|
||||||
|
if (browserBundleID) {
|
||||||
|
launched = [[NSWorkspace sharedWorkspace] openURLs:@[webURL] withAppBundleIdentifier:browserBundleID options:NSWorkspaceLaunchAsync additionalEventParamDescriptor:nil launchIdentifiers:NULL];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!launched) {
|
||||||
|
[[NSWorkspace sharedWorkspace] openURL:webURL];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,13 +44,26 @@
|
|||||||
#pragma mark Actions
|
#pragma mark Actions
|
||||||
- (void)selectBrowser:(id)sender {
|
- (void)selectBrowser:(id)sender {
|
||||||
NSString *browserBundleId = [sender representedObject];
|
NSString *browserBundleId = [sender representedObject];
|
||||||
NSLog(@"New default Browser: %@", browserBundleId);
|
|
||||||
[[NSUserDefaults standardUserDefaults] setObject:browserBundleId forKey:kMPSettingsKeyBrowserBundleId];
|
[[NSUserDefaults standardUserDefaults] setObject:browserBundleId forKey:kMPSettingsKeyBrowserBundleId];
|
||||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||||
|
[self _updateBrowserSelection];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)showCustomBrowserSelection:(id)sender {
|
- (void)showCustomBrowserSelection:(id)sender {
|
||||||
NSAssert(NO,@"Not implemented!");
|
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
|
||||||
|
[openPanel setDirectoryURL:[NSURL URLWithString:@"/Applications"]];
|
||||||
|
[openPanel setAllowsMultipleSelection:NO];
|
||||||
|
[openPanel setCanChooseDirectories:NO];
|
||||||
|
[openPanel setCanChooseFiles:YES];
|
||||||
|
[openPanel setAllowedFileTypes:@[@"app"]];
|
||||||
|
|
||||||
|
[openPanel beginSheetModalForWindow:[[self view] window] completionHandler:^(NSInteger result) {
|
||||||
|
if(result == NSFileHandlingPanelOKButton) {
|
||||||
|
NSMenuItem *customBrowser = [[NSMenuItem alloc] init];
|
||||||
|
[customBrowser setRepresentedObject:[[NSBundle bundleWithPath:[[openPanel URL] path]] bundleIdentifier]];
|
||||||
|
[self selectBrowser:customBrowser];
|
||||||
|
}
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark Helper
|
#pragma mark Helper
|
||||||
@@ -58,8 +71,15 @@
|
|||||||
/* Use a delegate ? */
|
/* Use a delegate ? */
|
||||||
NSMenu *browserMenu = [[NSMenu alloc] init];
|
NSMenu *browserMenu = [[NSMenu alloc] init];
|
||||||
[self.browserPopup setMenu:browserMenu];
|
[self.browserPopup setMenu:browserMenu];
|
||||||
|
|
||||||
[browserMenu addItemWithTitle:NSLocalizedString(@"DEFAULT_BROWSER", "Default Browser") action:NULL keyEquivalent:@""];
|
NSMenuItem *defaultItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"DEFAULT_BROWSER", "Default Browser") action:@selector(selectBrowser:) keyEquivalent:@""];
|
||||||
|
[defaultItem setRepresentedObject:nil];
|
||||||
|
[defaultItem setTarget:self];
|
||||||
|
[browserMenu addItem:defaultItem];
|
||||||
|
|
||||||
|
NSString *currentDefaultBrowser = [[NSUserDefaults standardUserDefaults] objectForKey:kMPSettingsKeyBrowserBundleId];
|
||||||
|
NSMenuItem *selectedItem = defaultItem;
|
||||||
|
|
||||||
[browserMenu addItem:[NSMenuItem separatorItem]];
|
[browserMenu addItem:[NSMenuItem separatorItem]];
|
||||||
|
|
||||||
for(NSString *bundleIdentifier in [self _bundleIdentifierForHTTPS]) {
|
for(NSString *bundleIdentifier in [self _bundleIdentifierForHTTPS]) {
|
||||||
@@ -69,16 +89,36 @@
|
|||||||
[browserItem setRepresentedObject:bundleIdentifier];
|
[browserItem setRepresentedObject:bundleIdentifier];
|
||||||
[browserItem setTarget:self];
|
[browserItem setTarget:self];
|
||||||
[browserMenu addItem:browserItem];
|
[browserMenu addItem:browserItem];
|
||||||
|
|
||||||
|
if ([bundleIdentifier isEqualToString:currentDefaultBrowser]) {
|
||||||
|
selectedItem = browserItem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if([[browserMenu itemArray] count] > 2) {
|
if([[browserMenu itemArray] count] > 2) {
|
||||||
[browserMenu addItem:[NSMenuItem separatorItem]];
|
[browserMenu addItem:[NSMenuItem separatorItem]];
|
||||||
}
|
}
|
||||||
NSMenuItem *selectOtherBrowserItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"OTHER_BROWSER", "Selecte Browser")
|
|
||||||
|
if (currentDefaultBrowser != nil && selectedItem == defaultItem) {
|
||||||
|
NSString *bundlePath = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:currentDefaultBrowser];
|
||||||
|
if (bundlePath != nil) {
|
||||||
|
NSString *browserName = [[NSFileManager defaultManager] displayNameAtPath:bundlePath];
|
||||||
|
NSMenuItem *browserItem = [[NSMenuItem alloc] initWithTitle:browserName action:@selector(selectBrowser:) keyEquivalent:@""];
|
||||||
|
[browserItem setRepresentedObject:currentDefaultBrowser];
|
||||||
|
[browserItem setTarget:self];
|
||||||
|
[browserMenu addItem:browserItem];
|
||||||
|
|
||||||
|
selectedItem = browserItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NSMenuItem *selectOtherBrowserItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"OTHER_BROWSER", "Select Browser")
|
||||||
action:@selector(showCustomBrowserSelection:)
|
action:@selector(showCustomBrowserSelection:)
|
||||||
keyEquivalent:@""];
|
keyEquivalent:@""];
|
||||||
[selectOtherBrowserItem setTarget:self];
|
[selectOtherBrowserItem setTarget:self];
|
||||||
|
|
||||||
[browserMenu addItem:selectOtherBrowserItem];
|
[browserMenu addItem:selectOtherBrowserItem];
|
||||||
|
[self.browserPopup selectItem:selectedItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray *)_bundleIdentifierForHTTPS {
|
- (NSArray *)_bundleIdentifierForHTTPS {
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user