Skip to content

Commit

Permalink
Merge pull request #19 from wflixu/dev
Browse files Browse the repository at this point in the history
v1.3.2
  • Loading branch information
wflixu authored Sep 1, 2024
2 parents 6991e9a + 91443ac commit ff769ae
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 78 deletions.
131 changes: 74 additions & 57 deletions FinderSyncExt/FinderOpen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class FinderOpen: FIFinderSync {

var bookmarkItems: [BookmarkFolderItem] = []

var triggerManKind = FIMenuKind.contextualMenuForContainer

override init() {
super.init()
logger.info("---- finderOpen init")
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -97,46 +94,71 @@ 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")
}

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)
Expand All @@ -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)!
Expand All @@ -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
}
Expand All @@ -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

Expand All @@ -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()

Expand All @@ -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
Expand All @@ -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))
Expand Down
16 changes: 8 additions & 8 deletions RClick.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = "";
Expand All @@ -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 = "";
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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 = "";
Expand Down
13 changes: 7 additions & 6 deletions RClick/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 启动后执行的函数
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion RClick/MenuBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])

}
}
Expand Down
5 changes: 0 additions & 5 deletions RClick/RClickApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ struct RClickApp: App {
Settings {
SettingsView()
}

.defaultAppStorage(.group)

MenuBarExtra(
Expand All @@ -37,10 +36,6 @@ struct RClickApp: App {
}
}





// https://stackoverflow.com/a/76714125/19625526
private let kAppMenuInternalIdentifier = "app"
private let kSettingsLocalizedStringKey = "Settings\\U2026"
Expand Down
2 changes: 1 addition & 1 deletion RClick/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct SettingsView: View {
.tag(Tabs.about)
}
.padding(20)
.frame(minWidth: 600, minHeight: 450)
.frame(width: 600, height: 450)
}
}

Expand Down

0 comments on commit ff769ae

Please sign in to comment.