Skip to content

Commit

Permalink
added custom menu item pref
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Feb 3, 2024
1 parent 4aeda19 commit 9453fbd
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 23 deletions.
100 changes: 93 additions & 7 deletions Profile Manifest/com.twocanoes.xcreds.plist
Expand Up @@ -5,7 +5,7 @@
<key>pfm_app_url</key>
<string>https://github.com/twocanoes/xcreds</string>
<key>pfm_description</key>
<string>XCreds 4.1 (6299) OAuth Settings</string>
<string>XCreds 4.1 (6301) OAuth Settings</string>
<key>pfm_documentation_url</key>
<string>https://twocanoes.com/knowledge-base/xcreds-admin-guide/#preferences</string>
<key>pfm_domain</key>
Expand Down Expand Up @@ -563,7 +563,7 @@ Note that Google does not support the offline_access scope so instead use the pr
<key>pfm_default</key>
<false/>
<key>pfm_description</key>
<string>Favor using XCreds' local login screen over the cloud login UI.</string>
<string>Favor using XCreds&apos; local login screen over the cloud login UI.</string>
<key>pfm_documentation_url</key>
<string>https://twocanoes.com/knowledge-base/xcreds-admin-guide/#preferences</string>
<key>pfm_name</key>
Expand Down Expand Up @@ -617,7 +617,7 @@ Note that Google does not support the offline_access scope so instead use the pr
</dict>
<dict>
<key>pfm_description</key>
<string>Don't show the UI if this key is defined and a file or folder exists at this path.</string>
<string>Don&apos;t show the UI if this key is defined and a file or folder exists at this path.</string>
<key>pfm_documentation_url</key>
<string>https://twocanoes.com/knowledge-base/xcreds-admin-guide/#preferences</string>
<key>pfm_name</key>
Expand All @@ -629,7 +629,7 @@ Note that Google does not support the offline_access scope so instead use the pr
</dict>
<dict>
<key>pfm_description</key>
<string>Name of OIDC claim that contains an alias to add to a user account. Usually this is the "upn" (eg syd@twocanoes.com) so the user can log in at the standard login window the same as the IdP login window. Adds the value to record name of the user account as an alias.</string>
<string>Name of OIDC claim that contains an alias to add to a user account. Usually this is the &quot;upn&quot; (eg syd@twocanoes.com) so the user can log in at the standard login window the same as the IdP login window. Adds the value to record name of the user account as an alias.</string>
<key>pfm_documentation_url</key>
<string>https://twocanoes.com/knowledge-base/xcreds-admin-guide/#preferences</string>
<key>pfm_name</key>
Expand Down Expand Up @@ -875,7 +875,7 @@ Note that Google does not support the offline_access scope so instead use the pr
<key>pfm_default</key>
<false/>
<key>pfm_description</key>
<string>Reset the keychain without prompting if the login password doesn't match the local password.</string>
<string>Reset the keychain without prompting if the login password doesn&apos;t match the local password.</string>
<key>pfm_documentation_url</key>
<string>https://twocanoes.com/knowledge-base/xcreds-admin-guide/#preferences</string>
<key>pfm_name</key>
Expand Down Expand Up @@ -984,9 +984,9 @@ Note that Google does not support the offline_access scope so instead use the pr
</dict>
<dict>
<key>pfm_description</key>
<string>Password element id of the html element that has the password. It is read by using JavaScript to get the value (for example, for Azure, the JavaScript document.getElementById('i0118').value is sent. If this default is not set, standard values for Azure and Google Cloud will be used. To find out this value, use a browser to inspect the source of the page that has the password on it. Find the id of the textfield that has the password. Fill in the password and then open the JavaScript console. Run:
<string>Password element id of the html element that has the password. It is read by using JavaScript to get the value (for example, for Azure, the JavaScript document.getElementById(&apos;i0118&apos;).value is sent. If this default is not set, standard values for Azure and Google Cloud will be used. To find out this value, use a browser to inspect the source of the page that has the password on it. Find the id of the textfield that has the password. Fill in the password and then open the JavaScript console. Run:
document.getElementById('passwordID').value
document.getElementById(&apos;passwordID&apos;).value
changing “passwordID” to the correct element ID. If the value you typed into the textfield is returned, this is the correct ID.</string>
<key>pfm_documentation_url</key>
Expand Down Expand Up @@ -1076,6 +1076,92 @@ changing “passwordID” to the correct element ID. If the value you typed into
<key>pfm_type</key>
<string>string</string>
</dict>
<dict>
<key>pfm_description</key>
<string>Menu Items</string>
<key>pfm_description_reference</key>
<string>Optional Array of Additional Menu Items</string>
<key>pfm_name</key>
<string>menuItems</string>
<key>pfm_subkeys</key>
<array>
<dict>
<key>pfm_description</key>
<string>Menu Item Name</string>
<key>pfm_name</key>
<string>menuItemName</string>
<key>pfm_require</key>
<string>always</string>
<key>pfm_subkeys</key>
<array>
<dict>
<key>pfm_description</key>
<string>Menu Item</string>
<key>pfm_name</key>
<string>menuItemName</string>
<key>pfm_require</key>
<string>always</string>
<key>pfm_title</key>
<string>Menu Item Name</string>
<key>pfm_type</key>
<string>string</string>
<key>pfm_value_placeholder</key>
<string>Menu Item Name</string>
</dict>
<dict>
<key>pfm_description</key>
<string>Link or App Path</string>
<key>pfm_name</key>
<string>linkOrAppPath</string>
<key>pfm_require</key>
<string>always</string>
<key>pfm_title</key>
<string>Web page URL or local path to app</string>
<key>pfm_type</key>
<string>string</string>
<key>pfm_value_placeholder</key>
<string>/System/Applications/Utilities/Keychain Access.app or http://twocanoes.com/info</string>
</dict>
<dict>
<key>pfm_default</key>
<false/>
<key>pfm_description</key>
<string>Separator line before menu item</string>
<key>pfm_description_reference</key>
<string>Add a line before menu item</string>
<key>pfm_name</key>
<string>separatorBefore</string>
<key>pfm_title</key>
<string>Separator Before</string>
<key>pfm_type</key>
<string>boolean</string>
</dict>
<dict>
<key>pfm_default</key>
<false/>
<key>pfm_description</key>
<string>Separator line after menu item</string>
<key>pfm_description_reference</key>
<string>Add a line after menu item</string>
<key>pfm_name</key>
<string>separatorAfter</string>
<key>pfm_title</key>
<string>Separator After</string>
<key>pfm_type</key>
<string>boolean</string>
</dict>
</array>
<key>pfm_title</key>
<string>Optional Menu Items</string>
<key>pfm_type</key>
<string>dictionary</string>
</dict>
</array>
<key>pfm_title</key>
<string>Menu Items</string>
<key>pfm_type</key>
<string>array</string>
</dict>
</array>
<key>pfm_targets</key>
<array>
Expand Down
1 change: 1 addition & 0 deletions XCreds/Base.lproj/MainMenu.xib
Expand Up @@ -749,6 +749,7 @@
<outlet property="quitMenuItem" destination="OM5-mb-fFV" id="M6F-cZ-LFl"/>
<outlet property="quitMenuItemSeparator" destination="op6-Hq-2li" id="zC1-TH-cF8"/>
<outlet property="signinMenuItem" destination="FH2-NT-oeX" id="een-3k-67g"/>
<outlet property="statusMenu" destination="6OK-7Y-Yf9" id="WfZ-uc-xzV"/>
</connections>
</customObject>
</objects>
Expand Down
2 changes: 1 addition & 1 deletion XCreds/PrefKeys.swift
Expand Up @@ -9,7 +9,7 @@ import Foundation

enum PrefKeys: String {
case clientID, clientSecret, password="xcreds local password",discoveryURL, redirectURI, scopes, accessToken, idToken, refreshToken, tokenEndpoint, expirationDate, invalidToken, refreshRateHours,refreshRateMinutes, showDebug, verifyPassword, shouldShowQuitMenu, shouldShowPreferencesOnStart, shouldSetGoogleAccessTypeToOffline, passwordChangeURL, shouldShowAboutMenu, username, idpHostName, passwordElementID, shouldFindPasswordElement, shouldShowVersionInfo, shouldShowSupportStatus,shouldShowConfigureWifiButton,shouldShowMacLoginButton, loginWindowBackgroundImageURL, shouldShowCloudLoginByDefault, shouldPreferLocalLoginInsteadOfCloudLogin, idpHostNames,autoRefreshLoginTimer, loginWindowWidth, loginWindowHeight, shouldShowRefreshBanner, shouldSwitchToLoginWindowWhenLocked,accounts = "Accounts",
windowSignIn = "WindowSignIn", settingsOverrideScriptPath, localAdminUserName, localAdminPassword, usernamePlaceholder, passwordPlaceholder, shouldShowLocalOnlyCheckbox, shouldShowTokenUpdateStatus, shouldDetectNetworkToDetermineLoginWindow, showLoginWindowDelaySeconds, shouldPromptForMigration, shouldAllowKeyComboForMacLoginWindow, aliasName,claimsToAddToLocalUserAccount, loadPageTitle, loadPageInfo,shouldPromptForADPasswordChange, hideIfPathExists, allowedUsersArray, allowUsersClaim, mapKerberosPrincipalName, mapFirstName = "map_firstname",mapFullName = "map_fullname", mapUserName = "map_username", mapLastName = "map_lastname",menuItemWindowBackgroundImageURL
windowSignIn = "WindowSignIn", settingsOverrideScriptPath, localAdminUserName, localAdminPassword, usernamePlaceholder, passwordPlaceholder, shouldShowLocalOnlyCheckbox, shouldShowTokenUpdateStatus, shouldDetectNetworkToDetermineLoginWindow, showLoginWindowDelaySeconds, shouldPromptForMigration, shouldAllowKeyComboForMacLoginWindow, aliasName,claimsToAddToLocalUserAccount, loadPageTitle, loadPageInfo,shouldPromptForADPasswordChange, hideIfPathExists, allowedUsersArray, allowUsersClaim, mapKerberosPrincipalName, mapFirstName = "map_firstname",mapFullName = "map_fullname", mapUserName = "map_username", mapLastName = "map_lastname",menuItemWindowBackgroundImageURL, menuItems
case shouldUseROPGForPasswordChangeChecking
case shouldUseROPGForMenuLogin
case shouldUseROPGForLoginWindowLogin
Expand Down
69 changes: 65 additions & 4 deletions XCreds/StatusMenuController.swift
Expand Up @@ -19,8 +19,19 @@ class StatusMenuController: NSObject, NSMenuItemValidation {
case ChangePasswordMenuItem=6
case SharesMenuItem=7
case QuitMenuItem=8
case Additional=9

}
enum MenuElements:String {
case linkOrAppPath
case menuItemName
case separatorAfter
case separatorBefore
}
struct StatusMenuItem {
var name:String
var path:String
}
var signedIn = false
var aboutWindowController: AboutWindowController?

Expand All @@ -40,9 +51,56 @@ class StatusMenuController: NSObject, NSMenuItemValidation {
@IBOutlet var aboutMenuItemSeparator:NSMenuItem!
@IBOutlet var nextPasswordCheckMenuItem:NSMenuItem!
@IBOutlet var credentialStatusMenuItem:NSMenuItem!



@IBOutlet var statusMenu:NSMenu!

override func awakeFromNib() {
if let menuItems = DefaultsOverride.standardOverride.value(forKey: PrefKeys.menuItems.rawValue) as? Array<Dictionary<String,Any?>> {
let insertPos = 7
var index = 0
for item in menuItems {
if let name = item[MenuElements.menuItemName.rawValue] as? String,
let path = item[MenuElements.linkOrAppPath.rawValue] as? String,
let separatorBefore = item[MenuElements.separatorBefore.rawValue] as? Bool,
let separatorAfter = item[MenuElements.separatorAfter.rawValue] as? Bool
{
let menuItem = NSMenuItem(title: name, action:#selector(additionalMenuItemSelected(_:)) , keyEquivalent: "")
menuItem.target=self
menuItem.tag=9
menuItem.representedObject=StatusMenuItem(name: name, path: path)
if separatorBefore == true {
statusMenu.insertItem(NSMenuItem.separator(), at: insertPos+index)
index+=1
}
statusMenu.insertItem(menuItem, at:insertPos+index)
index+=1
if separatorAfter == true {
statusMenu.insertItem(NSMenuItem.separator(), at:insertPos+index)
index+=1
}

}

}
}
}
@objc func additionalMenuItemSelected(_ sender:NSMenuItem){
guard let menuItemInfo = sender.representedObject as? StatusMenuItem else {
return
}

let pathString = menuItemInfo.path

if pathString.hasPrefix("http"), let url = URL(string: pathString){

NSWorkspace.shared.open(url)

}
else {
let fileUrl = URL(fileURLWithPath: pathString)
NSWorkspace.shared.openApplication(at: fileUrl, configuration: NSWorkspace.OpenConfiguration())
}

}
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
let appDelegate = NSApp.delegate as? AppDelegate
let mainController = appDelegate?.mainController
Expand Down Expand Up @@ -128,7 +186,10 @@ class StatusMenuController: NSObject, NSMenuItemValidation {
return false
case .SharesMenuItem:
return true
case .Additional:
return true
}

return true
}

Expand Down Expand Up @@ -191,7 +252,7 @@ class StatusMenuController: NSObject, NSMenuItemValidation {

let mainController = appDelegate?.mainController
mainController?.showSignInWindow(force: true)

}
}

Expand Down
12 changes: 6 additions & 6 deletions xCreds.xcodeproj/project.pbxproj
Expand Up @@ -1440,7 +1440,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6300;
CURRENT_PROJECT_VERSION = 6301;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1477,7 +1477,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6300;
CURRENT_PROJECT_VERSION = 6301;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1598,7 +1598,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6300;
CURRENT_PROJECT_VERSION = 6301;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1635,7 +1635,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6300;
CURRENT_PROJECT_VERSION = 6301;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1785,7 +1785,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6300;
CURRENT_PROJECT_VERSION = 6301;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1827,7 +1827,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6300;
CURRENT_PROJECT_VERSION = 6301;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
Binary file not shown.
Expand Up @@ -7,16 +7,16 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "CBFC9DF7-4656-42DF-A56E-B4581138BCCD"
uuid = "C3A9FE8D-3AF5-4176-9E1B-DE1421736668"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "XCreds/DesktopLoginWindowController.swift"
filePath = "XCreds/StatusMenuController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "24"
endingLineNumber = "24"
landmarkName = "windowDidLoad()"
startingLineNumber = "74"
endingLineNumber = "74"
landmarkName = "awakeFromNib()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
Expand Down

0 comments on commit 9453fbd

Please sign in to comment.