-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from boscojwho/bosco/open-at-login
Bosco/open at login
- Loading branch information
Showing
8 changed files
with
187 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// AppDelegate.swift | ||
// Chinotto | ||
// | ||
// Created by Bosco Ho on 2023-12-04. | ||
// | ||
|
||
import Foundation | ||
import AppKit | ||
|
||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
|
||
func applicationDidFinishLaunching(_ notification: Notification) { | ||
LoginItemBehaviour.hideWindowsOnDidFinishLaunching( | ||
NSApplication.shared.windows, | ||
notification | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// LoginItemBehaviour.swift | ||
// Chinotto | ||
// | ||
// Created by Bosco Ho on 2023-12-04. | ||
// | ||
|
||
import Foundation | ||
import AppKit | ||
|
||
#if os(macOS) | ||
struct LoginItemBehaviour { | ||
private static var openAtLogin: Bool { | ||
UserDefaults.standard.bool(forKey: "openAtLogin") | ||
} | ||
|
||
private static var hideWindowsOnLaunch: Bool { | ||
UserDefaults.standard.bool(forKey: "hideWindowsOnLaunch") | ||
} | ||
|
||
static func hideWindowsOnDidFinishLaunching(_ windows: [NSWindow], _ notification: Notification) { | ||
for window in windows { | ||
if openAtLogin == true, | ||
hideWindowsOnLaunch == true, | ||
let isDefaultLaunch = notification.userInfo?[NSApplication.launchIsDefaultUserInfoKey] as? Bool, | ||
isDefaultLaunch == false { | ||
/// Menu bar app window and menu bar item window aren't restorable. | ||
if window.isRestorable { | ||
window.close() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters