Skip to content

Commit

Permalink
Merge pull request #1 from jamesmcdonald/prefs
Browse files Browse the repository at this point in the history
Add preferences
  • Loading branch information
James McDonald committed Sep 12, 2018
2 parents bbde8e1 + 57faa71 commit 33ecd55
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 21 deletions.
8 changes: 8 additions & 0 deletions Passmenu.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
1AB9CE1C2145929C00E6EF8D /* PrefsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB9CE1B2145929C00E6EF8D /* PrefsViewController.swift */; };
1AB9CE1E2148333700E6EF8D /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB9CE1D2148333700E6EF8D /* Constants.swift */; };
1AC9964F213D1A7D0003BEA6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AC9964E213D1A7D0003BEA6 /* AppDelegate.swift */; };
1AC99651213D1A7D0003BEA6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AC99650213D1A7D0003BEA6 /* ViewController.swift */; };
1AC99653213D1A7D0003BEA6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1AC99652213D1A7D0003BEA6 /* Assets.xcassets */; };
Expand All @@ -17,6 +19,8 @@

/* Begin PBXFileReference section */
1A2037022141812000B87E98 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
1AB9CE1B2145929C00E6EF8D /* PrefsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefsViewController.swift; sourceTree = "<group>"; };
1AB9CE1D2148333700E6EF8D /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
1AC9964B213D1A7D0003BEA6 /* Passmenu.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Passmenu.app; sourceTree = BUILT_PRODUCTS_DIR; };
1AC9964E213D1A7D0003BEA6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
1AC99650213D1A7D0003BEA6 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -68,6 +72,8 @@
1AC99654213D1A7D0003BEA6 /* Main.storyboard */,
1AC99657213D1A7D0003BEA6 /* Info.plist */,
1AC99658213D1A7D0003BEA6 /* Passmenu.entitlements */,
1AB9CE1B2145929C00E6EF8D /* PrefsViewController.swift */,
1AB9CE1D2148333700E6EF8D /* Constants.swift */,
);
path = Passmenu;
sourceTree = "<group>";
Expand Down Expand Up @@ -166,9 +172,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1AB9CE1E2148333700E6EF8D /* Constants.swift in Sources */,
1AC99651213D1A7D0003BEA6 /* ViewController.swift in Sources */,
1AC99661213D33F30003BEA6 /* PassFacade.swift in Sources */,
1AC9964F213D1A7D0003BEA6 /* AppDelegate.swift in Sources */,
1AB9CE1C2145929C00E6EF8D /* PrefsViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
34 changes: 30 additions & 4 deletions Passmenu/AppDelegate.swift
Expand Up @@ -14,21 +14,33 @@ class AppDelegate: NSObject, NSApplicationDelegate {


var searchController: NSWindowController
var prefsController: NSWindowController

let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
let hotkey = HotKey(key: .p, modifiers: [.command, .option])

override init() {
// Load the popup window
let storyboard = NSStoryboard(name: NSStoryboard.Name(rawValue: "Main"), bundle: nil)
let identifier = NSStoryboard.SceneIdentifier(rawValue: "WindowController")
guard let viewcontroller = storyboard.instantiateController(withIdentifier: identifier) as? NSWindowController else {
guard let searchController = storyboard.instantiateController(withIdentifier: identifier) as? NSWindowController else {
fatalError("Can't seem to find WindowController in Storyboard")
}
self.searchController = viewcontroller
self.searchController = searchController

let prefsid = NSStoryboard.SceneIdentifier(rawValue: "PrefsWindowController")
guard let prefsController = storyboard.instantiateController(withIdentifier: prefsid) as? NSWindowController else {
fatalError("Can't seem to find PrefsWindowController in Storyboard")
}
self.prefsController = prefsController

super.init()
}

@objc func showPrefs(_ sender: Any?) {
NSApp.activate(ignoringOtherApps: true)
prefsController.window?.makeKeyAndOrderFront(sender)
}

@objc func toggleSearch(_ sender: Any?) {
if (searchController.window?.isVisible)! {
hideSearch(sender)
Expand All @@ -52,13 +64,27 @@ class AppDelegate: NSObject, NSApplicationDelegate {

let lookupitem = NSMenuItem(title: "Look up pass", action: #selector(AppDelegate.toggleSearch(_:)), keyEquivalent: "")
menu.addItem(lookupitem)
let prefsitem = NSMenuItem(title: "Preferences...", action: #selector(AppDelegate.showPrefs(_:)), keyEquivalent: "")
menu.addItem(prefsitem)
menu.addItem(NSMenuItem.separator())
menu.addItem(NSMenuItem(title: "Quit Passmenu", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q"))
menu.addItem(NSMenuItem(title: "Quit Passmenu", action: #selector(NSApplication.terminate(_:)), keyEquivalent: ""))

statusItem.menu = menu
}

func applicationDidFinishLaunching(_ aNotification: Notification) {
// Set default UserDefaults
let ud = UserDefaults.standard
if ud.string(forKey: Constants.prefNamePassBinary) == nil {
ud.set(Constants.defaultPassBinary, forKey: Constants.prefNamePassBinary)
}
if ud.string(forKey: Constants.prefNamePath) == nil {
ud.set(Constants.defaultPath, forKey: Constants.prefNamePath)
}
if ud.string(forKey: Constants.prefNameStorePath) == nil {
ud.set(Constants.defaultStorePath, forKey: Constants.prefNameStorePath)
}

if let button = statusItem.button {
button.image = NSImage(named: NSImage.Name("StatusBarButtonImage"))
}
Expand Down

0 comments on commit 33ecd55

Please sign in to comment.