diff --git a/FinderSyncExt/FinderOpen.swift b/FinderSyncExt/FinderOpen.swift index 29c9ddb..7f4b13c 100644 --- a/FinderSyncExt/FinderOpen.swift +++ b/FinderSyncExt/FinderOpen.swift @@ -23,6 +23,8 @@ class FinderOpen: FIFinderSync { var bookmarkItems: [BookmarkFolderItem] = [] + var triggerManKind = FIMenuKind.contextualMenuForContainer + override init() { super.init() logger.info("---- finderOpen init") @@ -57,11 +59,6 @@ class FinderOpen: FIFinderSync { override func requestBadgeIdentifier(for url: URL) { NSLog("requestBadgeIdentifierForURL: %@", url.path as NSString) - - // For demonstration purposes, this picks one of our two badges, or no badge at all, based on the filename. -// let whichBadge = abs(url.path.hash) % 3 -// let badgeIdentifier = ["", "One", "Two"][whichBadge] -// FIFinderSyncController.default().setBadgeIdentifier(badgeIdentifier, for: url) } // MARK: - Menu and toolbar item support @@ -75,7 +72,7 @@ class FinderOpen: FIFinderSync { } override var toolbarItemImage: NSImage { - return NSImage(systemSymbolName: "computermouse", accessibilityDescription: "RClick Menu")! + return NSImage(named: "MenuBarIcon")! } @MainActor func initMenuDirs() throws { @@ -97,32 +94,27 @@ class FinderOpen: FIFinderSync { @MainActor override func menu(for menuKind: FIMenuKind) -> NSMenu { // Produce a menu for the extension. + triggerManKind = menuKind let applicationMenu = NSMenu(title: "RClick") guard isHostAppOpen else { return applicationMenu } switch menuKind { + // finder 中my选中文件或文件夹 case .contextualMenuForContainer: - for nsmenu in createAppItems() { - applicationMenu.addItem(nsmenu) - } + createMenuForContainer(applicationMenu) - if let fileMenuItem = createFileCreateMenuItem() { - applicationMenu.addItem(fileMenuItem) - } - + // finder 中 有选中文件或文件夹 case .contextualMenuForItems: NSLog("contextualMenuForItems") + + createMenuForItems(applicationMenu) + + case .toolbarItemMenu: - for nsmenu in createAppItems() { - applicationMenu.addItem(nsmenu) - } - - for item in createActionMenuItems() { - applicationMenu.addItem(item) - } - + createMenuForToolbar(applicationMenu) + default: print("Some other character") } @@ -130,13 +122,43 @@ class FinderOpen: FIFinderSync { return applicationMenu } + @objc func createMenuForContainer(_ applicationMenu: NSMenu) { + for nsmenu in createAppItems() { + applicationMenu.addItem(nsmenu) + } + + if let fileMenuItem = createFileCreateMenuItem() { + applicationMenu.addItem(fileMenuItem) + } + } + + @objc func createMenuForItems(_ applicationMenu: NSMenu) { + for nsmenu in createAppItems() { + applicationMenu.addItem(nsmenu) + } + + for item in createActionMenuItems() { + applicationMenu.addItem(item) + } + } + + @objc func createMenuForToolbar(_ applicationMenu: NSMenu) { + for nsmenu in createAppItems() { + applicationMenu.addItem(nsmenu) + } + + if let fileMenuItem = createFileCreateMenuItem() { + applicationMenu.addItem(fileMenuItem) + } + } + @objc func createAppItems() -> [NSMenuItem] { var appMenuItems: [NSMenuItem] = [] for item in menuStore.appItems { let menuItem = NSMenuItem() menuItem.target = self menuItem.title = String(localized: "Open With \(item.name)") - menuItem.action = #selector(itemAction(_:)) + menuItem.action = #selector(appOpen(_:)) menuItem.toolTip = "\(item.name)" menuItem.tag = 0 menuItem.image = NSWorkspace.shared.icon(forFile: item.url.path) @@ -152,7 +174,7 @@ class FinderOpen: FIFinderSync { let menuItem = NSMenuItem() menuItem.target = self menuItem.title = String(localized: String.LocalizationValue(item.key)) - menuItem.action = #selector(itemAction(_:)) + menuItem.action = #selector(actioning(_:)) menuItem.toolTip = "\(item.name)" menuItem.tag = 1 menuItem.image = NSImage(systemSymbolName: item.iconName, accessibilityDescription: item.iconName)! @@ -162,22 +184,10 @@ class FinderOpen: FIFinderSync { return actionMenuitems } - @MainActor @objc func itemAction(_ menuItem: NSMenuItem) { - switch menuItem.tag { - case 0: - appOpen(menuItem, isContainer: false) - case 1: - actioning(menuItem, isContainer: false) - case 2: - createFile(menuItem, isContainer: false) - default: - break - } - } // 创建文件菜单容器 @objc func createFileCreateMenuItem() -> NSMenuItem? { - let enabledFiletypeItems = menuStore.filetypeItems.filter(\.enabled) + let enabledFiletypeItems = menuStore.filetypeItems.filter(\.enabled) if enabledFiletypeItems.isEmpty { return nil } @@ -189,7 +199,7 @@ class FinderOpen: FIFinderSync { let menuItem = NSMenuItem() menuItem.target = self menuItem.title = item.name - menuItem.action = #selector(itemAction(_:)) + menuItem.action = #selector(createFile(_:)) menuItem.toolTip = "\(item.name)" menuItem.tag = 2 @@ -205,17 +215,7 @@ class FinderOpen: FIFinderSync { return menuItem } - @MainActor @objc func ContainerAction(_ menuItem: NSMenuItem) { - switch menuItem.tag { - case 0: - appOpen(menuItem, isContainer: true) - - default: - break - } - } - - @MainActor @objc func createFile(_ menuItem: NSMenuItem, isContainer: Bool) { + @MainActor @objc func createFile(_ menuItem: NSMenuItem) { let item = menuStore.getFileCreateItem(name: menuItem.title) let url = FIFinderSyncController.default().targetedURL() @@ -224,7 +224,7 @@ class FinderOpen: FIFinderSync { } } - @MainActor @objc func actioning(_ menuItem: NSMenuItem, isContainer: Bool) { + @MainActor @objc func actioning(_ menuItem: NSMenuItem) { guard let item = menuStore.getActionItem(name: menuItem.title) else { logger.info("not item ad ") return @@ -236,24 +236,41 @@ class FinderOpen: FIFinderSync { } let urlstr = urls.map { $0.path } - logger.info("test \(String(localized: String.LocalizationValue(item.key)))") messager.sendMessage(name: Key.messageFromFinder, data: MessagePayload(action: item.key, target: urlstr)) } - @objc func appOpen(_ menuItem: NSMenuItem, isContainer: Bool) { + @objc func appOpen(_ menuItem: NSMenuItem) { + var target: String - if isContainer { - guard let targetURL = FIFinderSyncController.default().targetedURL() - else { return } - target = targetURL.path - - } else { + switch triggerManKind { + case FIMenuKind.contextualMenuForItems: let urls = FIFinderSyncController.default().selectedItemURLs() guard let targetURL = urls?.first else { return } target = targetURL.path + case FIMenuKind.toolbarItemMenu: + let selectedURLs = FIFinderSyncController.default().selectedItemURLs() + + if let targetURL = selectedURLs?.first { + target = targetURL.path + } else { + + if let targetURL2 = FIFinderSyncController.default().targetedURL() { + target = targetURL2.path + } else { + logger.warning("no target URL") + return + } + } + + default: + guard let targetURL = FIFinderSyncController.default().targetedURL() + else { return } + target = targetURL.path } + + let item = menuStore.getAppItem(name: menuItem.title) if let appUrl = item?.url { messager.sendMessage(name: Key.messageFromFinder, data: MessagePayload(action: "open", target: [target], app: appUrl.path)) diff --git a/RClick.xcodeproj/project.pbxproj b/RClick.xcodeproj/project.pbxproj index 9b289a9..552cb73 100644 --- a/RClick.xcodeproj/project.pbxproj +++ b/RClick.xcodeproj/project.pbxproj @@ -549,7 +549,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 8.21.1; + CURRENT_PROJECT_VERSION = 9.1.1; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = "\"RClick/Preview Content\""; DEVELOPMENT_TEAM = 4L3563XCBN; @@ -566,7 +566,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 1.3.1; + MARKETING_VERSION = 1.3.2; PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -586,7 +586,7 @@ CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 8.21.1; + CURRENT_PROJECT_VERSION = 9.1.1; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = "\"RClick/Preview Content\""; DEVELOPMENT_TEAM = ""; @@ -604,7 +604,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 1.3.1; + MARKETING_VERSION = 1.3.2; PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = mac_app_rclick_distribution_store; @@ -621,7 +621,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 8.21.1; + CURRENT_PROJECT_VERSION = 9.1.1; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = 4L3563XCBN; ENABLE_HARDENED_RUNTIME = YES; @@ -636,7 +636,7 @@ "@executable_path/../../../../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 1.3.1; + MARKETING_VERSION = 1.3.2; PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick.FinderSyncExt; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -653,7 +653,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "3rd Party Mac Developer Application"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 8.21.1; + CURRENT_PROJECT_VERSION = 9.1.1; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = ""; "DEVELOPMENT_TEAM[sdk=macosx*]" = 4L3563XCBN; @@ -669,7 +669,7 @@ "@executable_path/../../../../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 1.3.1; + MARKETING_VERSION = 1.3.2; PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick.FinderSyncExt; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/RClick/AppDelegate.swift b/RClick/AppDelegate.swift index 2317a2c..65e71b6 100644 --- a/RClick/AppDelegate.swift +++ b/RClick/AppDelegate.swift @@ -18,6 +18,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { let messager = Messager.shared var folderItemStore = FolderItemStore() var showDockIcon = UserDefaults.group.bool(forKey: Key.showDockIcon) + var settingsWindow: NSWindow! func applicationDidFinishLaunching(_ aNotification: Notification) { // 在 app 启动后执行的函数 @@ -30,12 +31,12 @@ class AppDelegate: NSObject, NSApplicationDelegate { messager.start(name: Key.messageFromFinder) messager.sendMessage(name: "running", data: MessagePayload(action: "running")) - // 根据某种逻辑设置应用是否显示在 Dock 中 - if showDockIcon { - NSApp.setActivationPolicy(.regular) - } else { - NSApp.setActivationPolicy(.prohibited) - } +// // 根据某种逻辑设置应用是否显示在 Dock 中 +// if showDockIcon { +// NSApp.setActivationPolicy(.regular) +// } else { +// NSApp.setActivationPolicy(.prohibited) +// } } func applicationDidBecomeActive(_ notification: Notification) { diff --git a/RClick/MenuBarView.swift b/RClick/MenuBarView.swift index b5d00ee..c1ad91e 100644 --- a/RClick/MenuBarView.swift +++ b/RClick/MenuBarView.swift @@ -15,12 +15,13 @@ struct MenuBarView: View { SettingsLink { Image(systemName: "gearshape") Text("Settings") - } + }.keyboardShortcut(",", modifiers: [.command]) Button(action: actionQuit) { Image(systemName: "xmark.square") Text("Quit") } + .keyboardShortcut("q", modifiers: [.command]) } } diff --git a/RClick/RClickApp.swift b/RClick/RClickApp.swift index ae5cde3..4ce42a4 100644 --- a/RClick/RClickApp.swift +++ b/RClick/RClickApp.swift @@ -26,7 +26,6 @@ struct RClickApp: App { Settings { SettingsView() } - .defaultAppStorage(.group) MenuBarExtra( @@ -37,10 +36,6 @@ struct RClickApp: App { } } - - - - // https://stackoverflow.com/a/76714125/19625526 private let kAppMenuInternalIdentifier = "app" private let kSettingsLocalizedStringKey = "Settings\\U2026" diff --git a/RClick/SettingsView.swift b/RClick/SettingsView.swift index f7e52ec..eb6a4e4 100644 --- a/RClick/SettingsView.swift +++ b/RClick/SettingsView.swift @@ -41,7 +41,7 @@ struct SettingsView: View { .tag(Tabs.about) } .padding(20) - .frame(minWidth: 600, minHeight: 450) + .frame(width: 600, height: 450) } }