Skip to content

Commit 5f43758

Browse files
authored
Merge pull request #62 from wflixu/dev
fix bug
2 parents 3a18686 + 210782b commit 5f43758

File tree

8 files changed

+118
-64
lines changed

8 files changed

+118
-64
lines changed

FinderSyncExt/FinderSyncExt.swift

+18-1
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,13 @@ class FinderSyncExt: FIFinderSync {
279279
return
280280
}
281281
let target = getTargets(triggerManKind)
282+
let trigger = getTriggerKind(triggerManKind)
282283
if target.isEmpty {
283284
logger.warning("not dir when actioning")
284285
return
285286
}
286-
messager.sendMessage(name: Key.messageFromFinder, data: MessagePayload(action: "actioning", target: target, rid: rid))
287+
logger.info("actioning \(rid) , trigger:\(trigger)")
288+
messager.sendMessage(name: Key.messageFromFinder, data: MessagePayload(action: "actioning", target: target, rid: rid, trigger: trigger))
287289
}
288290

289291
func getTargets(_ kind: FIMenuKind) -> [String] {
@@ -333,4 +335,19 @@ class FinderSyncExt: FIFinderSync {
333335
logger.warning("not get target")
334336
}
335337
}
338+
339+
@objc func getTriggerKind(_ kind: FIMenuKind) -> String {
340+
switch kind {
341+
case .contextualMenuForItems:
342+
return "ctx-items"
343+
case .contextualMenuForContainer:
344+
return "ctx-container"
345+
case .contextualMenuForSidebar:
346+
return "ctx-sidebar"
347+
case .toolbarItemMenu:
348+
return "toolbar"
349+
default:
350+
return "unknown"
351+
}
352+
}
336353
}

RClick.xcodeproj/project.pbxproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@
540540
CODE_SIGN_IDENTITY = "Apple Development";
541541
CODE_SIGN_STYLE = Automatic;
542542
COMBINE_HIDPI_IMAGES = YES;
543-
CURRENT_PROJECT_VERSION = 20250405001;
543+
CURRENT_PROJECT_VERSION = 20250420001;
544544
DEAD_CODE_STRIPPING = YES;
545545
DEVELOPMENT_ASSET_PATHS = "\"RClick/Preview Content\"";
546546
DEVELOPMENT_TEAM = 4L3563XCBN;
@@ -557,7 +557,7 @@
557557
"@executable_path/../Frameworks",
558558
);
559559
MACOSX_DEPLOYMENT_TARGET = 15.0;
560-
MARKETING_VERSION = 1.6.2;
560+
MARKETING_VERSION = 1.6.3;
561561
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick;
562562
PRODUCT_NAME = "$(TARGET_NAME)";
563563
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -577,7 +577,7 @@
577577
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Developer ID Application";
578578
CODE_SIGN_STYLE = Manual;
579579
COMBINE_HIDPI_IMAGES = YES;
580-
CURRENT_PROJECT_VERSION = 20250405001;
580+
CURRENT_PROJECT_VERSION = 20250420001;
581581
DEAD_CODE_STRIPPING = YES;
582582
DEVELOPMENT_ASSET_PATHS = "\"RClick/Preview Content\"";
583583
DEVELOPMENT_TEAM = "";
@@ -595,7 +595,7 @@
595595
"@executable_path/../Frameworks",
596596
);
597597
MACOSX_DEPLOYMENT_TARGET = 15.0;
598-
MARKETING_VERSION = 1.6.2;
598+
MARKETING_VERSION = 1.6.3;
599599
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick;
600600
PRODUCT_NAME = "$(TARGET_NAME)";
601601
PROVISIONING_PROFILE_SPECIFIER = mac_app_rclick_distribution_store;
@@ -612,7 +612,7 @@
612612
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
613613
CODE_SIGN_STYLE = Automatic;
614614
COMBINE_HIDPI_IMAGES = YES;
615-
CURRENT_PROJECT_VERSION = 20250405001;
615+
CURRENT_PROJECT_VERSION = 20250420001;
616616
DEAD_CODE_STRIPPING = YES;
617617
DEVELOPMENT_TEAM = 4L3563XCBN;
618618
ENABLE_HARDENED_RUNTIME = YES;
@@ -627,7 +627,7 @@
627627
"@executable_path/../../../../Frameworks",
628628
);
629629
MACOSX_DEPLOYMENT_TARGET = 15.0;
630-
MARKETING_VERSION = 1.6.2;
630+
MARKETING_VERSION = 1.6.3;
631631
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick.FinderSyncExt;
632632
PRODUCT_NAME = "$(TARGET_NAME)";
633633
SKIP_INSTALL = YES;
@@ -644,7 +644,7 @@
644644
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Developer ID Application";
645645
CODE_SIGN_STYLE = Manual;
646646
COMBINE_HIDPI_IMAGES = YES;
647-
CURRENT_PROJECT_VERSION = 20250405001;
647+
CURRENT_PROJECT_VERSION = 20250420001;
648648
DEAD_CODE_STRIPPING = YES;
649649
DEVELOPMENT_TEAM = "";
650650
"DEVELOPMENT_TEAM[sdk=macosx*]" = 4L3563XCBN;
@@ -660,7 +660,7 @@
660660
"@executable_path/../../../../Frameworks",
661661
);
662662
MACOSX_DEPLOYMENT_TARGET = 15.0;
663-
MARKETING_VERSION = 1.6.2;
663+
MARKETING_VERSION = 1.6.3;
664664
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick.FinderSyncExt;
665665
PRODUCT_NAME = "$(TARGET_NAME)";
666666
PROVISIONING_PROFILE_SPECIFIER = "";

RClick.xcodeproj/xcshareddata/xcschemes/RClick.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
<EnvironmentVariable
8181
key = "IDEPreferLogStreaming"
8282
value = "YES"
83-
isEnabled = "NO">
83+
isEnabled = "YES">
8484
</EnvironmentVariable>
8585
</EnvironmentVariables>
8686
</LaunchAction>

RClick/Localizable.xcstrings

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
"zh-Hans" : {
308308
"stringUnit" : {
309309
"state" : "translated",
310-
"value" : "文件类型"
310+
"value" : "新建文件"
311311
}
312312
}
313313
}

RClick/RClickApp.swift

+63-38
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
6262
case "open":
6363
self.openApp(rid: payload.rid, target: payload.target)
6464
case "actioning":
65-
self.actionHandler(rid: payload.rid, target: payload.target)
65+
self.actionHandler(rid: payload.rid, target: payload.target, trigger: payload.trigger ?? "unknown")
6666
case "Create File":
6767
self.createFile(rid: payload.rid, target: payload.target)
6868
case "common-dirs":
@@ -80,15 +80,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
8080

8181
func openCommonDirs(target: [String]) {
8282
logger.info("开始打开常用目录,目标路径: \(target)")
83-
83+
8484
for dirPath in target {
8585
let path = dirPath.removingPercentEncoding ?? dirPath
8686
let url = URL(fileURLWithPath: path, isDirectory: true)
87-
87+
8888
logger.info("正在打开目录: \(path)")
8989
NSWorkspace.shared.open(url)
9090
}
91-
91+
9292
logger.info("常用目录打开操作完成")
9393
}
9494

@@ -128,7 +128,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
128128
return filePath
129129
}
130130

131-
func actionHandler(rid: String, target: [String]) {
131+
func actionHandler(rid: String, target: [String], trigger: String) {
132132
guard let rcitem = appState.getActionItem(rid: rid) else {
133133
logger.warning("when createFile,but not have fileType ")
134134
return
@@ -138,24 +138,25 @@ class AppDelegate: NSObject, NSApplicationDelegate {
138138
case "copy-path":
139139
copyPath(target)
140140
case "delete-direct":
141-
deleteFoldorFile(target)
141+
deleteFoldorFile(target, trigger)
142142
case "unhide":
143-
unhideFilesAndDirs(target)
143+
unhideFilesAndDirs(target, trigger)
144144
case "hide":
145-
hideFilesAndDirs(target)
145+
hideFilesAndDirs(target, trigger)
146146
default:
147147
logger.warning("no action id matched")
148148
}
149149
}
150+
150151
// 显示目标文件夹下的隐藏的所有文件和文件夹
151-
func unhideFilesAndDirs(_ target:[String]) {
152+
func unhideFilesAndDirs(_ target: [String], _ trigger: String) {
152153
logger.info("开始取消隐藏文件和目录,目标路径: \(target)")
153154
if let dirPath = target.first {
154155
let fileManager = FileManager.default
155156
let path = dirPath.removingPercentEncoding ?? dirPath
156157
logger.info("处理主目录: \(path)")
157158
var url = URL(fileURLWithPath: path)
158-
159+
159160
// 仅处理目录下一级的内容
160161
do {
161162
let contents = try fileManager.contentsOfDirectory(at: url, includingPropertiesForKeys: [.isHiddenKey], options: [.skipsPackageDescendants])
@@ -172,7 +173,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
172173
} catch {
173174
logger.error("获取目录内容失败: \(error)")
174175
}
175-
176+
176177
// 处理目录本身
177178
do {
178179
var resourceValues = URLResourceValues()
@@ -185,19 +186,22 @@ class AppDelegate: NSObject, NSApplicationDelegate {
185186
logger.info("取消隐藏操作完成,共处理目录: \(path)")
186187
}
187188
}
189+
188190
// 隐藏目标文件或文件夹
189-
func hideFilesAndDirs(_ target:[String]) {
190-
logger.info("开始隐藏文件和目录,目标路径: \(target)")
191-
if let dirPath = target.first {
192-
let fileManager = FileManager.default
191+
func hideFilesAndDirs(_ target: [String], _ trigger: String) {
192+
logger.info("开始隐藏文件和目录,目标路径: \(target), 触发器: \(trigger)")
193+
let fileManager = FileManager.default
194+
195+
if trigger == "ctx-container", let dirPath = target.first {
193196
let path = dirPath.removingPercentEncoding ?? dirPath
194197
logger.info("处理主目录: \(path)")
195198
var url = URL(fileURLWithPath: path)
196-
197-
// 递归处理目录下的所有内容
198-
if let enumerator = fileManager.enumerator(at: url, includingPropertiesForKeys: [.isHiddenKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) {
199-
for case var fileURL as URL in enumerator {
200-
// 如果是受保护的文件路径,跳过
199+
200+
// 仅处理目录下一级的内容
201+
do {
202+
let contents = try fileManager.contentsOfDirectory(at: url, includingPropertiesForKeys: [.isDirectoryKey], options: [.skipsPackageDescendants])
203+
for case var fileURL in contents {
204+
// 如果是受保护的文件路径,跳过
201205
if Utils.isProtectedFolder(fileURL.path) {
202206
logger.warning("跳过受保护的文件路径: \(fileURL.path)")
203207
continue
@@ -211,19 +215,31 @@ class AppDelegate: NSObject, NSApplicationDelegate {
211215
logger.error("隐藏失败: \(fileURL.path): \(error)")
212216
}
213217
}
214-
}
215-
216-
// 处理目录本身
217-
do {
218-
var resourceValues = URLResourceValues()
219-
resourceValues.isHidden = true
220-
try url.setResourceValues(resourceValues)
221-
logger.info("成功隐藏主目录: \(path)")
222218
} catch {
223-
logger.error("隐藏主目录失败: \(path): \(error)")
219+
logger.error("获取目录内容失败: \(error)")
220+
}
221+
} else if trigger == "ctx-items" {
222+
for dirPath in target {
223+
let path = dirPath.removingPercentEncoding ?? dirPath
224+
logger.info("处理路径: \(path)")
225+
var url = URL(fileURLWithPath: path)
226+
227+
// 处理单个文件或目录
228+
if Utils.isProtectedFolder(path) {
229+
logger.warning("跳过受保护的文件路径: \(path)")
230+
continue
231+
}
232+
do {
233+
var resourceValues = URLResourceValues()
234+
resourceValues.isHidden = true
235+
try url.setResourceValues(resourceValues)
236+
logger.info("成功隐藏: \(path)")
237+
} catch {
238+
logger.error("隐藏失败: \(path): \(error)")
239+
}
224240
}
225-
logger.info("隐藏操作完成,共处理目录: \(path)")
226241
}
242+
logger.info("隐藏操作完成")
227243
}
228244

229245
func copyPath(_ target: [String]) {
@@ -236,13 +252,24 @@ class AppDelegate: NSObject, NSApplicationDelegate {
236252
}
237253
}
238254

239-
func deleteFoldorFile(_ target: [String]) {
240-
logger.info("---- deleteFoldorFile")
255+
func deleteFoldorFile(_ target: [String], _ trigger: String) {
256+
logger.info("---- deleteFoldorFile trigger:\( trigger)")
241257
let fm = FileManager.default
258+
// 如果是容器,无法删除
259+
if trigger == "ctx-container" {
260+
// 显示警告对话框
261+
let alert = NSAlert()
262+
alert.messageText = "警告"
263+
alert.informativeText = "无法删除当前文件夹,请选择文件或子文件夹进行删除。"
264+
alert.alertStyle = .warning
265+
alert.addButton(withTitle: "确定")
266+
alert.runModal()
267+
return
268+
}
242269

243270
for item in target {
244271
let decodedPath = item.removingPercentEncoding ?? item
245-
272+
246273
if Utils.isProtectedFolder(decodedPath) {
247274
// 显示警告对话框
248275
let alert = NSAlert()
@@ -251,11 +278,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
251278
alert.alertStyle = .warning
252279
alert.addButton(withTitle: "确定")
253280
alert.runModal()
254-
281+
255282
logger.warning("试图删除受保护的系统文件夹,操作已被阻止: \(decodedPath)")
256283
continue
257284
}
258-
285+
259286
if let permDir = appState.dirs.first(where: { permd in
260287
item.contains(permd.url.path())
261288
}) {
@@ -362,8 +389,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
362389
config.environment = rcitem.environment
363390

364391
if appUrl.path.hasSuffix("WezTerm.app") {
365-
366-
367392
// 创建一个 Process 实例
368393
let process = Process()
369394

@@ -411,7 +436,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
411436
}
412437

413438
func applicationWillTerminate(_ notification: Notification) {
414-
messager.sendMessage(name: "quit", data: MessagePayload(action: "quit"))
439+
messager.sendMessage(name: "quit", data: MessagePayload(action: "quit", target: [], trigger: "unknown"))
415440
logger.info("applicationWillTerminate")
416441
}
417442
}

RClick/Settings/NewFileSettingsTabView.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
// Created by 李旭 on 2024/11/18.
66
//
77

8-
import SwiftUI
98
import AppKit
9+
import SwiftUI
1010

1111
struct NewFileSettingsTabView: View {
1212
@EnvironmentObject var appState: AppState
@@ -28,7 +28,6 @@ struct NewFileSettingsTabView: View {
2828
ZStack {
2929
VStack {
3030
HStack {
31-
3231
Spacer()
3332
Button {
3433
isAddingNew = true
@@ -45,7 +44,7 @@ struct NewFileSettingsTabView: View {
4544
.font(.body)
4645
}
4746
}
48-
// TODO 编辑 Button 和 Toggle 放在列表的右边
47+
// TODO: 编辑 Button 和 Toggle 放在列表的右边
4948
List {
5049
ForEach($appState.newFiles) { $item in
5150
HStack(spacing: 12) {
@@ -249,7 +248,8 @@ struct NewFileSettingsTabView: View {
249248
}
250249
appState.addNewFile(newFile)
251250
} else if let file = editingFile,
252-
let index = appState.newFiles.firstIndex(where: { $0.id == file.id }) {
251+
let index = appState.newFiles.firstIndex(where: { $0.id == file.id })
252+
{
253253
var updatedFile = file
254254
updatedFile.name = editingName
255255
updatedFile.ext = editingExt

0 commit comments

Comments
 (0)