Skip to content

Commit

Permalink
added command click login window for mac login window
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Jun 28, 2023
1 parent 2f8dd4e commit f0a5b1f
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 46 deletions.
64 changes: 39 additions & 25 deletions XCreds Login Overlay/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ import AppKit



@main

@main
class App {
static func main() {
sleep(5)
_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)
}
}

class AppDelegate: NSObject, NSApplicationDelegate {

Expand Down Expand Up @@ -66,31 +72,39 @@ class AppDelegate: NSObject, NSApplicationDelegate {
*/
func setupWindow() {
var statusWindowRect=window.frame
let screenRect = NSScreen.screens[0].visibleFrame
statusWindowRect.size.width=screenRect.size.width
statusWindowRect.origin=screenRect.origin;
window.setFrame(statusWindowRect, display: true, animate: false)
window.canBecomeVisibleWithoutLogin=true
window.hidesOnDeactivate=false
window.isOpaque=false
window.level = .modalPanel
if let ud = UserDefaults(suiteName: "com.twocanoes.xcreds"), let customTextString = ud.value(forKey: "cloudLoginText") {
cloudLoginTextField.stringValue = customTextString as! String
cloudLoginTextField.sizeToFit()

}
}
func applicationDidFinishLaunching(_ aNotification: Notification) {
// if AuthorizationDBManager.shared.rightExists(right: "loginwindow:login") == true {
//
// var statusWindowRect=window.frame
// let screenRect = NSScreen.screens[0].visibleFrame
// statusWindowRect.size.width=screenRect.size.width
// statusWindowRect.origin=screenRect.origin;
// window.setFrame(statusWindowRect, display: true, animate: false)
// window.canBecomeVisibleWithoutLogin=true
// window.hidesOnDeactivate=false
// window.isOpaque=false
// window.level = .modalPanel
// // Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { timer in
// // NSApp.activate(ignoringOtherApps: true)
// // self.window.orderFrontRegardless()
// // }
//
// NSApp.activate(ignoringOtherApps: true)
// window.orderFrontRegardless()
// if let ud = UserDefaults(suiteName: "com.twocanoes.xcreds"), let customTextString = ud.value(forKey: "cloudLoginText") {
// cloudLoginTextField.stringValue = customTextString as! String
// cloudLoginTextField.sizeToFit()
//
// }
// }
if AuthorizationDBManager.shared.rightExists(right: "loginwindow:login") == true {


Timer.scheduledTimer(withTimeInterval: 3, repeats: true) { timer in
NSApp.activate(ignoringOtherApps: true)
self.window.orderFrontRegardless()
DispatchQueue.main.async {


self.setupWindow()
}
}
setupWindow()
NSApp.activate(ignoringOtherApps: true)
window.orderFrontRegardless()
}
}

func applicationWillTerminate(_ aNotification: Notification) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class LoginWebViewWindowController: WebViewWindowController {
func setupLoginWindowAppearance() {
DispatchQueue.main.async {

NSApp.activate(ignoringOtherApps: true)

TCSLogWithMark("setting up window...")

Expand Down
6 changes: 3 additions & 3 deletions XCredsLoginPlugIn/LoginWindow/LoginWindowControls.xib
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<windowStyleMask key="styleMask" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="25" y="25" width="872" height="117"/>
<rect key="screenRect" x="0.0" y="0.0" width="1496" height="933"/>
<rect key="screenRect" x="0.0" y="0.0" width="3440" height="1415"/>
<view key="contentView" id="Tpj-ss-EMv">
<rect key="frame" x="0.0" y="0.0" width="872" height="117"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down Expand Up @@ -57,7 +57,7 @@
</gridCell>
<gridCell row="XHx-7d-YkX" column="cUX-O2-zNV" xPlacement="center" id="2Gc-hy-IjQ">
<button key="contentView" imageHugsTitle="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6f9-0z-Xqg">
<rect key="frame" x="154" y="0.0" width="65" height="48"/>
<rect key="frame" x="153" y="0.0" width="66" height="48"/>
<buttonCell key="cell" type="bevel" title="Shutdown" bezelStyle="rounded" image="ShutdownX" imagePosition="above" alignment="center" imageScaling="proportionallyDown" inset="2" id="WRj-LR-MaW">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
Expand Down Expand Up @@ -158,7 +158,7 @@ DQ
<resources>
<image name="RestartX" width="32" height="32"/>
<image name="ShutdownX" width="32" height="32"/>
<image name="loginwindow" width="41" height="31.5"/>
<image name="loginwindow" width="41" height="32"/>
<image name="refresh symbol" width="989" height="989"/>
<image name="wifi" width="32" height="32"/>
</resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,34 @@ class LoginWindowControlsWindowController: NSWindowController {
var wifiWindowController:WifiWindowController?
@IBOutlet weak var trialVersionStatusTextField: NSTextField!
var refreshTimer:Timer?
var commandKeyDown = false
func dismiss() {
if let resolutionObserver = resolutionObserver {
NotificationCenter.default.removeObserver(resolutionObserver)
}
self.window?.close()
}
func commandKey(evt: NSEvent) -> NSEvent{
TCSLogWithMark(evt.debugDescription)

let flags = evt.modifierFlags.rawValue & NSEvent.ModifierFlags.command.rawValue
TCSLogWithMark("\(flags.description)")
if flags != 0 { //key code for command is 55
commandKeyDown = true
TCSLogWithMark("command down")
}
else {
commandKeyDown=false
TCSLogWithMark("not command down")

}
return evt
}

override func windowDidLoad() {
super.windowDidLoad()
let licenseState = LicenseChecker().currentLicenseState()
NSEvent.addLocalMonitorForEvents(matching: .flagsChanged, handler: commandKey(evt:))


switch licenseState {
Expand Down Expand Up @@ -217,15 +236,19 @@ class LoginWindowControlsWindowController: NSWindowController {
}
@IBAction func resetToStandardLoginWindow(_ sender: Any) {
TCSLogWithMark("switch login window")
if commandKeyDown == false {

NotificationCenter.default.post(name: NSNotification.Name("SwitchLoginWindow"), object: self)
// guard let delegate = delegate else {
// TCSLogErrorWithMark("No delegate set for resetToStandardLoginWindow")
// return
// }
// delegate.setContextString(type: kAuthorizationEnvironmentUsername, value: SpecialUsers.standardLoginWindow.rawValue)
NotificationCenter.default.post(name: NSNotification.Name("SwitchLoginWindow"), object: self)
return
}

// delegate.allowLogin()
guard let delegate = delegate else {
TCSLogErrorWithMark("No delegate set for resetToStandardLoginWindow")
return
}
delegate.setContextString(type: kAuthorizationEnvironmentUsername, value: SpecialUsers.standardLoginWindow.rawValue)

delegate.allowLogin()
}


Expand Down
1 change: 0 additions & 1 deletion XCredsLoginPlugIn/Mechanisms/XCredsLoginDone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class XCredsLoginDone: XCredsBaseMechanism {

override init(mechanism: UnsafePointer<MechanismRecord>) {
super.init(mechanism: mechanism)

}

@objc override func run() {
Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions xCreds.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
76BEF7E5287202090013E2A1 /* RestartX@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 76BEF7E3287202080013E2A1 /* RestartX@2x.png */; };
76BEF7E8287202AF0013E2A1 /* ShutdownX.png in Resources */ = {isa = PBXBuildFile; fileRef = 76BEF7E6287202AF0013E2A1 /* ShutdownX.png */; };
76BEF7E9287202AF0013E2A1 /* ShutdownX@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 76BEF7E7287202AF0013E2A1 /* ShutdownX@2x.png */; };
76BEF7EC28724A0B0013E2A1 /* XCredsLoginMechanism.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76BEF7EA28724A0B0013E2A1 /* XCredsLoginMechanism.swift */; };
76BEF7EC28724A0B0013E2A1 /* web.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76BEF7EA28724A0B0013E2A1 /* web.swift */; };
76BEF7ED28724A0C0013E2A1 /* XCredsBaseMechanism.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76BEF7EB28724A0B0013E2A1 /* XCredsBaseMechanism.swift */; };
76BEF7F328724F120013E2A1 /* XCredsPowerControlMechanism.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76BEF7F228724F120013E2A1 /* XCredsPowerControlMechanism.swift */; };
76BEF7F628724FA80013E2A1 /* NSTaskWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76BEF7F528724FA80013E2A1 /* NSTaskWrapper.swift */; };
Expand Down Expand Up @@ -361,7 +361,7 @@
76BEF7E3287202080013E2A1 /* RestartX@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "RestartX@2x.png"; sourceTree = "<group>"; };
76BEF7E6287202AF0013E2A1 /* ShutdownX.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ShutdownX.png; sourceTree = "<group>"; };
76BEF7E7287202AF0013E2A1 /* ShutdownX@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "ShutdownX@2x.png"; sourceTree = "<group>"; };
76BEF7EA28724A0B0013E2A1 /* XCredsLoginMechanism.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCredsLoginMechanism.swift; sourceTree = "<group>"; };
76BEF7EA28724A0B0013E2A1 /* web.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = web.swift; sourceTree = "<group>"; };
76BEF7EB28724A0B0013E2A1 /* XCredsBaseMechanism.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCredsBaseMechanism.swift; sourceTree = "<group>"; };
76BEF7F228724F120013E2A1 /* XCredsPowerControlMechanism.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = XCredsPowerControlMechanism.swift; sourceTree = "<group>"; };
76BEF7F528724FA80013E2A1 /* NSTaskWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSTaskWrapper.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -560,7 +560,7 @@
7611CEBF288B75140063A644 /* XCredsCreateUser.swift */,
7632E39E287347C100E37923 /* XCredsKeychainAdd.swift */,
76BEF7F228724F120013E2A1 /* XCredsPowerControlMechanism.swift */,
76BEF7EA28724A0B0013E2A1 /* XCredsLoginMechanism.swift */,
76BEF7EA28724A0B0013E2A1 /* web.swift */,
76BEF7EB28724A0B0013E2A1 /* XCredsBaseMechanism.swift */,
);
path = Mechanisms;
Expand Down Expand Up @@ -1031,7 +1031,7 @@
761B486A28A34CC900C6A02B /* LoginProgressWindowController.swift in Sources */,
7677908628908E40004E7085 /* WifiWindowController.swift in Sources */,
76EECCFD2873E9ED00483C66 /* LoginPasswordWindowController.swift in Sources */,
76BEF7EC28724A0B0013E2A1 /* XCredsLoginMechanism.swift in Sources */,
76BEF7EC28724A0B0013E2A1 /* web.swift in Sources */,
766355CA2870DCF5002E3867 /* TCSUnifiedLogger.m in Sources */,
76CB9078287FBEEA00C70D0C /* Helper+URLDecode.swift in Sources */,
766355E328713C4A002E3867 /* LoginWindow.swift in Sources */,
Expand Down Expand Up @@ -1225,7 +1225,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5053;
CURRENT_PROJECT_VERSION = 5070;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1263,7 +1263,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5053;
CURRENT_PROJECT_VERSION = 5070;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = UXP6YEHSPW;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1383,7 +1383,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5053;
CURRENT_PROJECT_VERSION = 5070;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1420,7 +1420,7 @@
CODE_SIGN_ENTITLEMENTS = "XCreds Login Overlay/XCreds_Login_Overlay.entitlements";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5053;
CURRENT_PROJECT_VERSION = 5070;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1570,7 +1570,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5053;
CURRENT_PROJECT_VERSION = 5070;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down Expand Up @@ -1607,7 +1607,7 @@
CODE_SIGN_ENTITLEMENTS = XCreds/xCreds.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 5053;
CURRENT_PROJECT_VERSION = 5070;
DEVELOPMENT_TEAM = UXP6YEHSPW;
ENABLE_HARDENED_RUNTIME = YES;
FRAMEWORK_SEARCH_PATHS = (
Expand Down
Binary file not shown.

0 comments on commit f0a5b1f

Please sign in to comment.