Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ jobs:

# --- 9. 创建 GitHub Release ---
- name: Create Release
uses: softprops/action-gh-release@v2
uses: softprops/action-gh-release@v3
with:
files: |
${{ env.ZIP_NAME }}
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
## [Unreleased]

### Changed
- Copy Path now copies every selected item, one path per line, and writes file URLs so Finder can paste the files themselves. Copy File Name copies every selected item's name the same way
- Keep Finder workspace icon caches warm with background preloading and main-thread image resizing
- Use lightweight heartbeat replies and reconnect from the last peer activity
- Direct Delete now always asks for confirmation before permanently removing files. Hold Option while choosing it to skip the prompt
Expand All @@ -21,6 +22,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
- Settings open on manual launch/reopen while hint-triggered and detected login launches stay quiet

### Fixed
- Updates no longer report success when the install failed. Installation errors are surfaced, the staged bundle's version is checked before it replaces the old app, and a failed relaunch keeps the current app running instead of quitting
- Updating from outside /Applications installs the new version and moves the old copy to the Trash, and an older RClick instance now quits itself as soon as a newer one starts. Two copies used to stay on disk and handle every Finder click twice
- External disks and mounted disk images no longer wear RClick's app icon in the Finder sidebar. RClick declares the `externaldrive` symbol, so those entries keep a drive icon instead
- Reset All Settings now restores apps, actions, file types, common folders and preferences instead of only writing a log line
- New-file auto-rename no longer depends on fixed delays: it waits for Finder to become active, so it stops missing the rename step on slow folders
- Auto-rename now explains the missing Accessibility permission once (granted to the RClick app, not the Finder extension) instead of failing silently
Expand Down
8 changes: 3 additions & 5 deletions FinderSyncExt/FinderSyncExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,10 @@ class FinderSyncExt: FIFinderSync, @unchecked Sendable {
sendClickEvent(event)
}

/// 快链路:复制路径(与主程序 ActionService.copyPath 语义一致,取第一项)
/// 快链路:复制全部选中项的路径(每行一个),同时写入文件 URL。
/// 与主程序 ActionService.copyPath 共用 Clipboard 实现,语义不会分叉。
private func copyPathsLocally(_ itemPaths: [String]) {
guard let first = itemPaths.first else { return }
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(first.removingPercentEncoding ?? first, forType: .string)
Clipboard.copyPaths(itemPaths)
}

@objc private func handleAppClick(_ sender: NSMenuItem) {
Expand Down
26 changes: 18 additions & 8 deletions RClick.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@
);
target = 5C8A29172F83D74A00FE687C /* FinderSyncExt */;
};
5C96A3902F8A9E2B00D022F8 /* Exceptions for "RClick" folder in "RClick" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
Info.plist,
);
target = 5C8A28D92F83D65900FE687C /* RClick */;
};
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */

/* Begin PBXFileSystemSynchronizedRootGroup section */
Expand All @@ -84,6 +91,7 @@
exceptions = (
5C96A3872F8A9E2B00D022F8 /* Exceptions for "RClick" folder in "RClickTests" target */,
5C96A3892F8A9E2B00D022F8 /* Exceptions for "RClick" folder in "FinderSyncExt" target */,
5C96A3902F8A9E2B00D022F8 /* Exceptions for "RClick" folder in "RClick" target */,
);
path = RClick;
sourceTree = "<group>";
Expand Down Expand Up @@ -489,13 +497,14 @@
CODE_SIGN_ENTITLEMENTS = RClick/RClickDebug.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20261107001;
CURRENT_PROJECT_VERSION = 20261114001;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 4L3563XCBN;
ENABLE_APP_SANDBOX = YES;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = RClick/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = RClick;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity";
INFOPLIST_KEY_LSUIElement = YES;
Expand All @@ -505,7 +514,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.6;
MARKETING_VERSION = 2.3.3;
MARKETING_VERSION = 2.3.4;
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick;
PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES;
Expand All @@ -527,13 +536,14 @@
CODE_SIGN_ENTITLEMENTS = RClick/RClick.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20261107001;
CURRENT_PROJECT_VERSION = 20261114001;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 4L3563XCBN;
ENABLE_APP_SANDBOX = YES;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = RClick/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = RClick;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity";
INFOPLIST_KEY_LSUIElement = YES;
Expand All @@ -543,7 +553,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.6;
MARKETING_VERSION = 2.3.3;
MARKETING_VERSION = 2.3.4;
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick;
PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES;
Expand Down Expand Up @@ -606,7 +616,7 @@
CODE_SIGN_ENTITLEMENTS = FinderSyncExt/FinderSyncExt.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20261107001;
CURRENT_PROJECT_VERSION = 20261114001;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 4L3563XCBN;
ENABLE_APP_SANDBOX = YES;
Expand All @@ -622,7 +632,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.6;
MARKETING_VERSION = 2.3.3;
MARKETING_VERSION = 2.3.4;
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick.FinderSyncExt;
PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES;
Expand All @@ -641,7 +651,7 @@
CODE_SIGN_ENTITLEMENTS = FinderSyncExt/FinderSyncExt.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20261107001;
CURRENT_PROJECT_VERSION = 20261114001;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 4L3563XCBN;
ENABLE_APP_SANDBOX = YES;
Expand All @@ -657,7 +667,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.6;
MARKETING_VERSION = 2.3.3;
MARKETING_VERSION = 2.3.4;
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick.FinderSyncExt;
PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES;
Expand Down
21 changes: 12 additions & 9 deletions RClick/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<!--
Finder draws this symbol on the sidebar entries of every root the Finder Sync
extension observes (#158). Without it, the sidebar shows RClick's app icon on
every external disk and mounted disk image instead of a drive icon.
See specs/external-volumes-observation.md.
-->
<key>CFBundleIcons</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleSymbolName</key>
<string>externaldrive</string>
</dict>
</dict>
<key>NSApplicationSupportsIndirectInputEvents</key>
<true/>
<key>NSServices</key>
<array>
<dict/>
</array>
</dict>
</plist>
35 changes: 35 additions & 0 deletions RClick/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -6933,6 +6933,41 @@
}
}
},
"The updated application could not be opened. Please start RClick manually." : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "The updated application could not be opened. Please start RClick manually."
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "No se pudo abrir la aplicación actualizada. Inicia RClick manualmente."
}
},
"fr" : {
"stringUnit" : {
"state" : "translated",
"value" : "Impossible d’ouvrir l’application mise à jour. Veuillez lancer RClick manuellement."
}
},
"ja" : {
"stringUnit" : {
"state" : "translated",
"value" : "更新後のアプリを開けませんでした。RClick を手動で起動してください。"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "无法打开更新后的应用,请手动启动 RClick。"
}
}
}
},
"The user cancelled authorization." : {
"extractionState" : "manual",
"localizations" : {
Expand Down
5 changes: 5 additions & 0 deletions RClick/RClickApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
logger.info("applicationDidFinishLaunching called")

// 更新后 /Applications 里是新副本,废纸篓或原位置可能还留着旧副本,两者
// 可以同时运行,并且都会响应 Finder 扩展的点击。在注册任何消息处理器之前
// 先收敛成一个;如果另一个副本更该留下,这里直接退出。
guard SingleInstanceGuard.enforceTermination() else { return }

// 设置窗口打开策略。注意 RClick 是 LSUIElement 应用,启动时系统不会
// 激活它(NSApp.isActive 恒为 false),无法用激活状态区分启动来源,
// 改用两个显式信号:
Expand Down
19 changes: 5 additions & 14 deletions RClick/Runtime/ActionService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,15 @@ final class ActionService {
// MARK: - SystemActions

/// 复制路径到剪贴板
/// 复制全部选中项的路径到剪贴板(一行一个),并写入文件 URL。
/// 与扩展内的离线快链路共用 Clipboard 实现。
func copyPath(_ target: [String]) {
if let dirPath = target.first {
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(dirPath.removingPercentEncoding ?? dirPath, forType: .string)
}
Clipboard.copyPaths(target)
}

/// 复制文件名(不含路径)到剪贴板
/// 复制全部选中项的文件名(不含路径)到剪贴板,一行一个。
func copyFileName(_ target: [String]) {
guard let path = target.first else { return }
let decoded = path.removingPercentEncoding ?? path
let name = URL(fileURLWithPath: decoded).lastPathComponent
guard !name.isEmpty else { return }

let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(name, forType: .string)
Clipboard.copyFileNames(target)
}

// MARK: - AppActions
Expand Down
109 changes: 109 additions & 0 deletions RClick/Shared/SingleInstanceGuard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import AppKit

/// 同一个 bundle id 的多个副本可以同时运行:它们的路径不同(更新后 /Applications
/// 里是新副本,废纸篓、下载目录或挂载的 DMG 里还留着旧副本),LaunchServices
/// 不会把它们当成同一个实例。Finder 扩展的点击走全局 DistributedNotificationCenter,
/// 两个进程都会收到并各执行一次——打开、删除这类操作会被重复执行。
///
/// 沙盒应用**不能终止其他进程**:`NSRunningApplication.terminate()` /
/// `forceTerminate()` 在 App Sandbox 里返回 false(Apple 文档明确说明)。所以收敛
/// 只能由落败者自己完成:每个实例启动时检查一次,之后每 2 秒再查一次,发现自己
/// 不该留下就 `NSApp.terminate`。这一条对之后的所有版本都成立;已经发布的旧版本
/// 没有这段逻辑,只能靠更新流程在安装后重启来避免残留。
@MainActor
enum SingleInstanceGuard {
struct InstanceInfo: Equatable {
let version: String
let launchDate: Date
let pid: pid_t
}

private static var monitorTask: Task<Void, Never>?

/// 两个实例之间谁留下。
///
/// 版本高者留下;版本相同时后启动的留下——用户刚打开的副本才是他要用的那个
/// (从 Xcode 跑 Debug 构建也会正确接管,而不是被已经在跑的正式版挤掉)。
/// 启动时间相同(极罕见)时按 PID 决胜,保证同时启动的两个进程不会互相退出。
static func shouldKeepSelf(current: InstanceInfo, other: InstanceInfo) -> Bool {
let versionOrder = Version.compare(current.version, other.version)
if versionOrder != .orderedSame {
return versionOrder == .orderedDescending
}
if current.launchDate != other.launchDate {
return current.launchDate > other.launchDate
}
return current.pid < other.pid
}

/// 启动早期调用。如果已经有更该留下的实例,当前进程直接退出并返回 `false`。
///
/// 必须在注册 DistributedNotificationCenter 处理器之前调用,否则在收敛前
/// 已经有两个进程同时响应 Finder 扩展的点击了。
@discardableResult
static func enforceTermination() -> Bool {
// 单元测试的宿主进程用的是同一个 bundle id,但它不是用户打开的副本:
// 让它把自己退掉会让测试跑不起来。
guard !isRunningTests, let bundleID = Bundle.main.bundleIdentifier else { return true }

let current = currentInstanceInfo()
if let winner = peers(bundleID: bundleID, excluding: current.pid)
.first(where: { !shouldKeepSelf(current: current, other: $0) })
{
print("Another RClick instance (pid=\(winner.pid) version=\(winner.version)) should keep running; quitting this one")
NSApp.terminate(nil)
return false
}

startMonitoring(bundleID: bundleID)
return true
}

/// 另一份副本可能在当前进程启动之后才出现(用户从废纸篓、下载目录或第二份
/// 安装位置打开它)。每 2 秒复查一次,发现自己该让位就退出。
private static func startMonitoring(bundleID: String) {
guard monitorTask == nil else { return }
monitorTask = Task { @MainActor in
while !Task.isCancelled {
try? await Task.sleep(for: .seconds(2))
let current = currentInstanceInfo()
let hasWinner = peers(bundleID: bundleID, excluding: current.pid)
.contains { !shouldKeepSelf(current: current, other: $0) }
if hasWinner {
print("A newer RClick instance appeared; quitting this one")
NSApp.terminate(nil)
return
}
}
}
}

private static func currentInstanceInfo() -> InstanceInfo {
InstanceInfo(
version: version(of: Bundle.main.bundleURL),
launchDate: NSRunningApplication.current.launchDate ?? .distantPast,
pid: ProcessInfo.processInfo.processIdentifier
)
}

private static func peers(bundleID: String, excluding pid: pid_t) -> [InstanceInfo] {
NSRunningApplication.runningApplications(withBundleIdentifier: bundleID)
.filter { $0.processIdentifier != pid && !$0.isTerminated }
.map { application in
InstanceInfo(
version: application.bundleURL.map { version(of: $0) } ?? "0",
launchDate: application.launchDate ?? .distantPast,
pid: application.processIdentifier
)
}
}

private static var isRunningTests: Bool {
ProcessInfo.processInfo.environment.keys.contains { $0.hasPrefix("XCTest") }
}

private static func version(of bundleURL: URL) -> String {
Bundle(url: bundleURL)?
.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "0"
}
}
Loading
Loading