Skip to content

Commit

Permalink
Hide "About XCreds" menu item #18; Ability to add a custom URL and me…
Browse files Browse the repository at this point in the history
…nu item for "Change Password #18
  • Loading branch information
twocanoes committed Jun 17, 2022
1 parent db746fd commit f1c4593
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 27 deletions.
33 changes: 31 additions & 2 deletions Profile Manifest/com.twocanoes.xcreds.plist
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ A profile can consist of payloads with different version numbers. For example, c
<key>pfm_type</key>
<string>boolean</string>
<key>pfm_title</key>
<string>Quit Menu Item</string>
<string>Show Quit Menu Item</string>
<key>pfm_description</key>
<string>Show Quit Menu Item.</string>
<string>Show Quit Menu Item in the menu.</string>
<key>pfm_default</key>
<true/>
</dict>
Expand All @@ -380,6 +380,35 @@ A profile can consist of payloads with different version numbers. For example, c
<key>pfm_default</key>
<false/>
</dict>

<dict>
<key>pfm_name</key>
<string>shouldHideAboutMenu</string>
<key>pfm_type</key>
<string>boolean</string>
<key>pfm_title</key>
<string>Hide About Menu</string>
<key>pfm_description</key>
<string>Hide the about menu</string>
<key>pfm_default</key>
<false/>
</dict>
<dict>
<key>pfm_name</key>
<string>passwordChangeURL</string>
<key>pfm_type</key>
<string>string</string>
<key>pfm_title</key>
<string>Password Change URL for Menu</string>
<key>pfm_description</key>
<string>Add a menu item for changing the password that will open this URL when the menu item is selected.</string>
<!-- This value will be automatically set as the value until the user changes it. -->
<key>pfm_default</key>
<string></string>

</dict>


</array>
</dict>
</plist>
39 changes: 39 additions & 0 deletions XCreds/ChangePasswordMenuItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// ChangePasswordMenuItem.swift
// xCreds
//
// Created by Timothy Perfitt on 4/5/22.
//

import Foundation
import Cocoa

class ChangePasswordMenuItem: NSMenuItem {

override var title: String {
get {

return "Change Password..."
}
set {
return
}
}

init() {
super.init(title: "", action: #selector(doAction), keyEquivalent: "")
self.target = self
}

required init(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

@objc func doAction() {
if let passwordChangeURLString = UserDefaults.standard.value(forKey: PrefKeys.passwordChangeURL.rawValue) as? String, passwordChangeURLString.count>0, let url = URL(string: passwordChangeURLString) {


NSWorkspace.shared.open(url)
}
}
}
25 changes: 19 additions & 6 deletions XCreds/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,41 @@ class MainMenu: NSObject, NSMenuDelegate {
buildMenu()
self.statusBarItem.menu = mainMenu
self.statusBarItem.button?.image=NSImage(named: "xcreds menu icon")
// self.statusBarItem.button?.title = "🔘"
mainMenu.delegate = self

}

func buildMenu() {

var firstItemShown = false
if menuOpen { return }

menuBuilt = Date()
mainMenu.removeAllItems()

// add menu items
let quitMenuItem = NSMenuItem(title: "Quit", action:#selector(NSApp.terminate(_:)), keyEquivalent: "")
if UserDefaults.standard.bool(forKey: PrefKeys.shouldHideAboutMenu.rawValue)==false{
mainMenu.addItem(AboutMenuItem())
mainMenu.addItem(NSMenuItem.separator())
firstItemShown = true
}
if let passwordChangeURLString = UserDefaults.standard.value(forKey: PrefKeys.passwordChangeURL.rawValue) as? String, passwordChangeURLString.count>0 {
if firstItemShown == false {
mainMenu.addItem(NSMenuItem.separator())
firstItemShown = true

}
mainMenu.addItem(ChangePasswordMenuItem())
mainMenu.addItem(NSMenuItem.separator())

mainMenu.addItem(AboutMenuItem())
mainMenu.addItem(NSMenuItem.separator())
}
mainMenu.addItem(SignInMenuItem())
mainMenu.addItem(CheckTokenMenuItem())
mainMenu.addItem(PrefsMenuItem())
mainMenu.addItem(NSMenuItem.separator())
if UserDefaults.standard.bool(forKey: PrefKeys.shouldShowQuit.rawValue)==true{
if UserDefaults.standard.bool(forKey: PrefKeys.shouldHideQuit.rawValue)==false{
let quitMenuItem = NSMenuItem(title: "Quit", action:#selector(NSApp.terminate(_:)), keyEquivalent: "")

mainMenu.addItem(NSMenuItem.separator())
mainMenu.addItem(quitMenuItem)
}

Expand Down
2 changes: 1 addition & 1 deletion XCreds/PrefKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import Foundation

enum PrefKeys: String {
case clientID, clientSecret, discoveryURL, redirectURI, scopes, accessToken, idToken, refreshToken, tokenEndpoint, expirationDate, invalidToken, refreshRateHours, showDebug, verifyPassword, shouldShowQuit, shouldShowPreferencesOnStart, shouldSetGoogleAccessTypeToOffline
case clientID, clientSecret, discoveryURL, redirectURI, scopes, accessToken, idToken, refreshToken, tokenEndpoint, expirationDate, invalidToken, refreshRateHours, showDebug, verifyPassword, shouldHideQuit, shouldShowPreferencesOnStart, shouldSetGoogleAccessTypeToOffline, passwordChangeURL, shouldHideAboutMenu
}
4 changes: 2 additions & 2 deletions XCreds/defaults.plist
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<true/>
<key>LogFileName</key>
<string>xcreds.log</string>
<key>shouldShowQuit</key>
<true/>
<key>shouldHideQuit</key>
<false/>
<key>shouldShowPreferencesOnStart</key>
<false/>
<key>shouldSetGoogleAccessTypeToOffline</key>
Expand Down
4 changes: 4 additions & 0 deletions xCreds.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
76D7ADFB284EB15100332EBC /* TCSUnifiedLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 76D7ADF9284EB15000332EBC /* TCSUnifiedLogger.m */; };
76D7ADFE284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 76D7ADFC284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.m */; };
76DD6D17285997F300A700ED /* OIDCLite in Frameworks */ = {isa = PBXBuildFile; productRef = 76DD6D16285997F300A700ED /* OIDCLite */; };
76EB8410285C28F0001AE215 /* ChangePasswordMenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76EB840F285C28F0001AE215 /* ChangePasswordMenuItem.swift */; };
76EE069E27FD1D00009E0F3A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76EE069D27FD1D00009E0F3A /* AppDelegate.swift */; };
76EE06A027FD1D01009E0F3A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 76EE069F27FD1D01009E0F3A /* Assets.xcassets */; };
76EE06A327FD1D01009E0F3A /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 76EE06A127FD1D01009E0F3A /* MainMenu.xib */; };
Expand Down Expand Up @@ -60,6 +61,7 @@
76D7ADFC284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+TCSRealHomeFolder.m"; sourceTree = "<group>"; };
76D7ADFD284EB18600332EBC /* NSFileManager+TCSRealHomeFolder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+TCSRealHomeFolder.h"; sourceTree = "<group>"; };
76DD6D122859978F00A700ED /* OIDCLite */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = OIDCLite; path = ../OIDCLite; sourceTree = "<group>"; };
76EB840F285C28F0001AE215 /* ChangePasswordMenuItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChangePasswordMenuItem.swift; sourceTree = "<group>"; };
76EE069A27FD1D00009E0F3A /* XCreds.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = XCreds.app; sourceTree = BUILT_PRODUCTS_DIR; };
76EE069D27FD1D00009E0F3A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
76EE069F27FD1D01009E0F3A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
Expand Down Expand Up @@ -150,6 +152,7 @@
764D812E284C06AB00B3EE54 /* defaults.plist */,
767116AE284AB5D900CCD6FF /* XCreds-Bridging-Header.h */,
76EE06B727FD1EB7009E0F3A /* PreferencesWindowController.swift */,
76EB840F285C28F0001AE215 /* ChangePasswordMenuItem.swift */,
76EE06B927FD1EE8009E0F3A /* SignInMenuItem.swift */,
767116A8284AAE2B00CCD6FF /* ScheduleManager.swift */,
76EE06BB27FD1EFE009E0F3A /* PrefsMenuItem.swift */,
Expand Down Expand Up @@ -254,6 +257,7 @@
764D8131284D11EE00B3EE54 /* AboutMenuItem.swift in Sources */,
767116B3284B045800CCD6FF /* KeychainUtil.swift in Sources */,
764D812C284BCC7400B3EE54 /* VerifyOIDCPasswordWindowController.swift in Sources */,
76EB8410285C28F0001AE215 /* ChangePasswordMenuItem.swift in Sources */,
76EE06BC27FD1EFE009E0F3A /* PrefsMenuItem.swift in Sources */,
764D8129284BCAB100B3EE54 /* Window+Shake.swift in Sources */,
76EE06B427FD1E5F009E0F3A /* WebView.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,6 @@
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "7E3586B1-2D94-4BE8-BC2E-2F3AC7FCFB14"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XCreds/ScheduleManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "51"
endingLineNumber = "51"
landmarkName = "checkToken()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
Expand Down

0 comments on commit f1c4593

Please sign in to comment.