Skip to content

Commit

Permalink
Asks user to set itself as default.
Browse files Browse the repository at this point in the history
  • Loading branch information
apexskier committed Nov 3, 2015
1 parent 27f97a9 commit eac11ec
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 72 deletions.
8 changes: 8 additions & 0 deletions Default Browser.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
</dict>
</plist>
36 changes: 26 additions & 10 deletions DefaultBrowser.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
C5A333731BDAF6EA000767B2 /* DefaultBrowser.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DefaultBrowser.app; sourceTree = BUILT_PRODUCTS_DIR; };
C5A333731BDAF6EA000767B2 /* Default Browser.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Default Browser.app"; sourceTree = BUILT_PRODUCTS_DIR; };
C5A333761BDAF6EA000767B2 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C5A333781BDAF6EA000767B2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
C5A3337B1BDAF6EA000767B2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
Expand All @@ -45,6 +45,7 @@
C5A333911BDAF6EA000767B2 /* DefaultBrowserUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultBrowserUITests.swift; sourceTree = "<group>"; };
C5A333931BDAF6EA000767B2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
C5E39DC11BE83B48004E722B /* Defaults.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Defaults.swift; sourceTree = "<group>"; };
C5E39DC31BE893EA004E722B /* Default Browser.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Default Browser.entitlements"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -75,6 +76,7 @@
C5A3336A1BDAF6EA000767B2 = {
isa = PBXGroup;
children = (
C5E39DC31BE893EA004E722B /* Default Browser.entitlements */,
C5A333751BDAF6EA000767B2 /* DefaultBrowser */,
C5A333851BDAF6EA000767B2 /* DefaultBrowserTests */,
C5A333901BDAF6EA000767B2 /* DefaultBrowserUITests */,
Expand All @@ -85,7 +87,7 @@
C5A333741BDAF6EA000767B2 /* Products */ = {
isa = PBXGroup;
children = (
C5A333731BDAF6EA000767B2 /* DefaultBrowser.app */,
C5A333731BDAF6EA000767B2 /* Default Browser.app */,
C5A333821BDAF6EA000767B2 /* DefaultBrowserTests.xctest */,
C5A3338D1BDAF6EA000767B2 /* DefaultBrowserUITests.xctest */,
);
Expand Down Expand Up @@ -125,9 +127,9 @@
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
C5A333721BDAF6EA000767B2 /* DefaultBrowser */ = {
C5A333721BDAF6EA000767B2 /* Default Browser */ = {
isa = PBXNativeTarget;
buildConfigurationList = C5A333961BDAF6EA000767B2 /* Build configuration list for PBXNativeTarget "DefaultBrowser" */;
buildConfigurationList = C5A333961BDAF6EA000767B2 /* Build configuration list for PBXNativeTarget "Default Browser" */;
buildPhases = (
C5A3336F1BDAF6EA000767B2 /* Sources */,
C5A333701BDAF6EA000767B2 /* Frameworks */,
Expand All @@ -137,9 +139,9 @@
);
dependencies = (
);
name = DefaultBrowser;
name = "Default Browser";
productName = DefaultBrowser;
productReference = C5A333731BDAF6EA000767B2 /* DefaultBrowser.app */;
productReference = C5A333731BDAF6EA000767B2 /* Default Browser.app */;
productType = "com.apple.product-type.application";
};
C5A333811BDAF6EA000767B2 /* DefaultBrowserTests */ = {
Expand Down Expand Up @@ -190,6 +192,12 @@
TargetAttributes = {
C5A333721BDAF6EA000767B2 = {
CreatedOnToolsVersion = 7.1;
DevelopmentTeam = 6D9DLTQJSN;
SystemCapabilities = {
com.apple.Sandbox = {
enabled = 1;
};
};
};
C5A333811BDAF6EA000767B2 = {
CreatedOnToolsVersion = 7.1;
Expand All @@ -214,7 +222,7 @@
projectDirPath = "";
projectRoot = "";
targets = (
C5A333721BDAF6EA000767B2 /* DefaultBrowser */,
C5A333721BDAF6EA000767B2 /* Default Browser */,
C5A333811BDAF6EA000767B2 /* DefaultBrowserTests */,
C5A3338C1BDAF6EA000767B2 /* DefaultBrowserUITests */,
);
Expand Down Expand Up @@ -278,12 +286,12 @@
/* Begin PBXTargetDependency section */
C5A333841BDAF6EA000767B2 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = C5A333721BDAF6EA000767B2 /* DefaultBrowser */;
target = C5A333721BDAF6EA000767B2 /* Default Browser */;
targetProxy = C5A333831BDAF6EA000767B2 /* PBXContainerItemProxy */;
};
C5A3338F1BDAF6EA000767B2 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = C5A333721BDAF6EA000767B2 /* DefaultBrowser */;
target = C5A333721BDAF6EA000767B2 /* Default Browser */;
targetProxy = C5A3338E1BDAF6EA000767B2 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
Expand Down Expand Up @@ -384,23 +392,31 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "Default Browser.entitlements";
CODE_SIGN_IDENTITY = "Mac Developer";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = DefaultBrowser/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.camlittle.DefaultBrowser;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
};
name = Debug;
};
C5A333981BDAF6EA000767B2 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = "Default Browser.entitlements";
CODE_SIGN_IDENTITY = "Mac Developer";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Mac Developer";
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = DefaultBrowser/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.camlittle.DefaultBrowser;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
};
name = Release;
};
Expand Down Expand Up @@ -468,7 +484,7 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
C5A333961BDAF6EA000767B2 /* Build configuration list for PBXNativeTarget "DefaultBrowser" */ = {
C5A333961BDAF6EA000767B2 /* Build configuration list for PBXNativeTarget "Default Browser" */ = {
isa = XCConfigurationList;
buildConfigurations = (
C5A333971BDAF6EA000767B2 /* Debug */,
Expand Down
57 changes: 49 additions & 8 deletions DefaultBrowser/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,38 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application

let selfBundleID = NSBundle.mainBundle().bundleIdentifier!
var selfName = getAppName(selfBundleID)
if selfName == "Unknown Application" {
selfName = "Default Browser"
}

defaults.registerDefaults(defaultSettings)

var currentlyDefault = false
if let currentDefaultBrowser = LSCopyDefaultHandlerForURLScheme("http")?.takeRetainedValue() {
if (currentDefaultBrowser as String).lowercaseString == selfBundleID.lowercaseString {
currentlyDefault = true
} else {
defaults.defaultBrowser = currentDefaultBrowser as String
}
}
if !currentlyDefault {
let notDefaultAlert = NSAlert()
notDefaultAlert.addButtonWithTitle("Set As Default")
notDefaultAlert.addButtonWithTitle("Cancel")
notDefaultAlert.messageText = "Set Default Browser"
notDefaultAlert.informativeText = "\(selfName) must be set as your default browser. Your current default will be remembered."
notDefaultAlert.alertStyle = .WarningAlertStyle
switch notDefaultAlert.runModal() {
case NSAlertFirstButtonReturn:
LSSetDefaultHandlerForURLScheme("http", selfBundleID)
LSSetDefaultHandlerForURLScheme("https", selfBundleID)
default:
break
}
}

// open window?
window.releasedWhenClosed = false
if defaults.openWindowOnLaunch {
Expand All @@ -190,8 +220,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

let menu = NSMenu()
let appName = getAppName(NSBundle.mainBundle().bundleIdentifier!)
menu.addItem(NSMenuItem(title: "About \(appName)", action: Selector("openWindow:"), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "About \(selfName)", action: Selector("openWindow:"), keyEquivalent: ""))
menu.addItem(NSMenuItem(title: "Preferences...", action: Selector("openWindow:"), keyEquivalent: ","))
let browserListTop = NSMenuItem.separatorItem()
browserListTop.tag = MenuItemTag.BrowserListTop.rawValue
Expand All @@ -207,10 +236,20 @@ class AppDelegate: NSObject, NSApplicationDelegate {
statusItem.menu = menu

// set up preferences
setUpPreferencesBrowsers()
showWindowCheckbox.state = defaults.openWindowOnLaunch ? NSOnState : NSOffState
descriptiveAppNamesCheckbox.state = defaults.detailedAppNames ? NSOnState : NSOffState

updateApps(workspace.runningApplications)
updateMenuItems()
}

func setUpPreferencesBrowsers() {
browsersPopUp.removeAllItems()
var selectedDefaultBrowser: NSMenuItem? = nil
validBrowsers.sort().forEach { bid in
let menuItem = BrowserMenuItem(title: getAppName(bid), action: nil, keyEquivalent: "")
let name = defaults.detailedAppNames ? getDetailedAppName(bid) : getAppName(bid)
let menuItem = BrowserMenuItem(title: name, action: nil, keyEquivalent: "")
menuItem.height = MENU_ITEM_HEIGHT
menuItem.bundleIdentifier = bid
if defaults.defaultBrowser == bid {
Expand All @@ -219,11 +258,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
browsersPopUp.menu?.addItem(menuItem)
}
browsersPopUp.selectItem(selectedDefaultBrowser)
showWindowCheckbox.state = defaults.openWindowOnLaunch ? NSOnState : NSOffState
descriptiveAppNamesCheckbox.state = defaults.detailedAppNames ? NSOnState : NSOffState

updateApps(workspace.runningApplications)
updateMenuItems()
}

func applicationShouldHandleReopen(sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
Expand Down Expand Up @@ -367,11 +401,18 @@ class AppDelegate: NSObject, NSApplicationDelegate {
@IBAction func descriptiveAppNamesChange(sender: NSButton) {
defaults.detailedAppNames = sender.state == NSOnState
updateMenuItems()
setUpPreferencesBrowsers()
}

@IBAction func showWindowChange(sender: NSButton) {
defaults.openWindowOnLaunch = sender.state == NSOnState
}

@IBAction func refreshBrowsersPress(sender: AnyObject) {
validBrowsers = getAllBrowsers()
runningBrowsers = []
updateApps(workspace.runningApplications)
}
}

extension Dictionary {
Expand Down
30 changes: 20 additions & 10 deletions DefaultBrowser/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,53 +1,63 @@
{
"images" : [
{
"idiom" : "mac",
"size" : "16x16",
"idiom" : "mac",
"filename" : "DefaultBrowserPlain16@1x.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "16x16",
"idiom" : "mac",
"filename" : "DefaultBrowserPlain16@2x.png",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "32x32",
"idiom" : "mac",
"filename" : "DefaultBrowserPlain32@1x.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "32x32",
"idiom" : "mac",
"filename" : "DefaultBrowserPlain32@2x.png",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "128x128",
"idiom" : "mac",
"filename" : "DefaultBrowserPlain128@1x.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "128x128",
"idiom" : "mac",
"filename" : "DefaultBrowserPlain128@2x.png",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "256x256",
"idiom" : "mac",
"filename" : "DefaultBrowserPlain256@1x.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "256x256",
"idiom" : "mac",
"filename" : "DefaultBrowserPlain256@2x.png",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "512x512",
"idiom" : "mac",
"filename" : "DefaultBrowserPlain512@1x.png",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "512x512",
"idiom" : "mac",
"filename" : "DefaultBrowserPlain512@2x.png",
"scale" : "2x"
}
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading

0 comments on commit eac11ec

Please sign in to comment.