Skip to content

Commit

Permalink
fix: open /bin error, hidden window at login
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-ge committed Feb 24, 2023
1 parent 68dbe9f commit c9fc8b6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
4 changes: 2 additions & 2 deletions dock shortcut.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
PRODUCT_BUNDLE_IDENTIFIER = "com.yige.dock-shortcut";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -400,7 +400,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
PRODUCT_BUNDLE_IDENTIFIER = "com.yige.dock-shortcut";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
Binary file not shown.
49 changes: 31 additions & 18 deletions dock shortcut/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ func openAPP(bundleIdentifier: String) {
lastOpen = bundleIdentifier
guard let url = NSWorkspace.shared.urlForApplication(withBundleIdentifier: bundleIdentifier) else { return }

let path = "/bin"
// let path = "/bin"
let configuration = NSWorkspace.OpenConfiguration()
configuration.arguments = [path]
// configuration.arguments = [path]
NSWorkspace.shared.openApplication(at: url,
configuration: configuration,
completionHandler: nil)
Expand Down Expand Up @@ -126,24 +126,38 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var plist = [String:AnyObject]()
var window: NSWindow?

func applicationDidFinishLaunching(_: Notification) {
window = NSApplication.shared.windows.first
window?.title = NSLocalizedString("CFBundleDisplayName", comment: "Dock Shortcut")


statusBarItem = NSStatusBar.system.statusItem(
withLength: NSStatusItem.squareLength)
func applicationDidFinishLaunching(_ aNotification: Notification) {
// 获取应用程序启动选项
guard let options = aNotification.userInfo else {
// 如果无法获取启动选项,则假定应用程序是从用户主动点击启动的
print("Application launched by user.")
return
}

if let showMenuBarIcon = UserDefaults.standard.string(forKey: "preference_showMenuBarIcon") {
if window != nil && showMenuBarIcon == "1" {
window?.close() // Close main app window
}
// 检查启动选项中是否包含 NSApplicationLaunchUserNotificationKey 键
if let isUserNotification = options[NSApplication.launchUserNotificationUserInfoKey] as? Bool, isUserNotification {
print("Application launched from a user notification.")
window?.close() // Close main app window
} else {
print("Application launched by user.")
window = NSApplication.shared.windows.first
window?.title = NSLocalizedString("CFBundleDisplayName", comment: "Dock Shortcut")


if showMenuBarIcon == "0" {
statusBarItem.isVisible = false
statusBarItem = NSStatusBar.system.statusItem(
withLength: NSStatusItem.squareLength)

if let showMenuBarIcon = UserDefaults.standard.string(forKey: "preference_showMenuBarIcon") {
if window != nil && showMenuBarIcon == "1" {
window?.close() // Close main app window
}

if showMenuBarIcon == "0" {
statusBarItem.isVisible = false
}
} else if window != nil {
window?.close() // Close main app window
}
} else if window != nil {
window?.close() // Close main app window
}

if let finderIsFirstApp = UserDefaults.standard.string(forKey: "preference_finderIsFirstApp") {
Expand Down Expand Up @@ -206,7 +220,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}


if let shotcutOption = UserDefaults.standard.string(forKey: "preference_shotcutOption") {
initHotKey(cocoaFlagsStr: ShotcutOption(rawValue: shotcutOption) ?? ShotcutOption.option)
} else {
Expand Down

0 comments on commit c9fc8b6

Please sign in to comment.