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
14 changes: 11 additions & 3 deletions FinderSyncExt/FinderSyncExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ class FinderSyncExt: FIFinderSync, @unchecked Sendable {

/// Register each mounted volume explicitly; filesystem ancestry alone is not
/// a reliable observation boundary for Finder Sync across mount points.
///
/// This is also what makes Finder redraw those volumes' sidebar icons with
/// RClick's app icon (#158) — a trade-off, not an oversight: a sandboxed
/// extension cannot read a volume root (`/Volumes` is readable, `/Volumes/<a
/// volume>` is not), so it cannot discover the volume's contents to observe
/// anything narrower. See specs/external-volumes-observation.md.
private func setupObservingDirectories() {
// Finder Sync requires an initial set during extension startup.
FIFinderSyncController.default().directoryURLs = [URL(fileURLWithPath: "/")]
Expand Down Expand Up @@ -243,9 +249,11 @@ class FinderSyncExt: FIFinderSync, @unchecked Sendable {
///
/// ⚠️ 这两行**不是**"外置盘图标变成 RClick 图标"的修复。#155 那个现象在这里
/// 被误判过两次:25b69e8 把随机标识改成空串,b697cc3 改成干脆不调用 —— 两次
/// 都没有解决,第二次还实测过"不调用时图标照旧"。真正的原因在别处:扩展把
/// 每个卷根都放进了 `directoryURLs`(见 setupObservingDirectories),Finder
/// 因而重新渲染这些卷的侧边栏图标。别再往 badge 上找了。
/// 都没有解决,第二次还实测过"不调用时图标照旧"。真正的原因在观察根:Finder
/// 会把扩展的图标画到每个**被当作根观察**的文件夹上,扩展则把每个卷根放进了
/// `directoryURLs`,于是这些卷的侧边栏图标被重画(见 setupObservingDirectories)。
/// 换成像"只观察卷内一级子目录"这种绕法行不通:沙盒下扩展读不到卷根。
/// 别再往 badge 上找了。
override func requestBadgeIdentifier(for url: URL) {
// 故意留空,见上。
}
Expand Down
18 changes: 10 additions & 8 deletions RClick.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@
CODE_SIGN_ENTITLEMENTS = RClick/RClickDebug.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20260916001;
CURRENT_PROJECT_VERSION = 20261014001;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 4L3563XCBN;
ENABLE_APP_SANDBOX = YES;
Expand All @@ -498,13 +498,14 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = RClick;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity";
INFOPLIST_KEY_LSUIElement = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.6;
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.3.1;
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick;
PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES;
Expand All @@ -526,7 +527,7 @@
CODE_SIGN_ENTITLEMENTS = RClick/RClick.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20260916001;
CURRENT_PROJECT_VERSION = 20261014001;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 4L3563XCBN;
ENABLE_APP_SANDBOX = YES;
Expand All @@ -535,13 +536,14 @@
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = RClick;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity";
INFOPLIST_KEY_LSUIElement = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.6;
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.3.1;
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick;
PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES;
Expand Down Expand Up @@ -604,7 +606,7 @@
CODE_SIGN_ENTITLEMENTS = FinderSyncExt/FinderSyncExt.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20260916001;
CURRENT_PROJECT_VERSION = 20261014001;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 4L3563XCBN;
ENABLE_APP_SANDBOX = YES;
Expand All @@ -620,7 +622,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.6;
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.3.1;
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick.FinderSyncExt;
PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES;
Expand All @@ -639,7 +641,7 @@
CODE_SIGN_ENTITLEMENTS = FinderSyncExt/FinderSyncExt.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20260916001;
CURRENT_PROJECT_VERSION = 20261014001;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 4L3563XCBN;
ENABLE_APP_SANDBOX = YES;
Expand All @@ -655,7 +657,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.6;
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.3.1;
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick.FinderSyncExt;
PRODUCT_NAME = "$(TARGET_NAME)";
REGISTER_APP_GROUPS = YES;
Expand Down
13 changes: 7 additions & 6 deletions RClick/RClickApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {

let messager = Messager.shared
var showMenuBarExtra = UserDefaults.group.bool(forKey: Key.showMenuBarExtra)
var showInDock = UserDefaults.group.bool(forKey: Key.showInDock)
var settingsWindow: NSWindow!

override init() {
Expand Down Expand Up @@ -103,11 +102,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}

if showInDock {
NSApp.setActivationPolicy(.regular)
} else {
NSApp.setActivationPolicy(.accessory)
}
// RClick 是菜单栏应用,Dock 里不该出现它。这件事由 Info.plist 的
// `LSUIElement`(构建设置 `INFOPLIST_KEY_LSUIElement`)声明,进程从第一
// 瞬间就是 agent —— 不再像以前那样先作为普通 App 启动、再在这里用
// `setActivationPolicy(.accessory)` 补救:那条路要求本次启动走到这一行,
// 而启动早期的失败路径(见 AppDelegate.init)和首启异常都会留下一个带
// Dock 图标的普通 App。曾经读 `SHOW_IN_DOCK` 做开关,但没有任何代码写过
// 那个键、设置页也没有开关,只有"看起来可配"的假象,一并删掉了。

// 迁移旧的"开机登录"设置(修复前该开关只写入 UserDefaults,未真正注册登录项)
migrateLegacyLaunchAtLoginSetting()
Expand Down
2 changes: 0 additions & 2 deletions RClick/Shared/StringExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ enum Key {
static let showContextualMenuForContainer = "SHOW_CONTEXTUAL_MENU_FOR_CONTAINER"
static let showContextualMenuForSidebar = "SHOW_CONTEXTUAL_MENU_FOR_SIDEBAR"
static let showToolbarItemMenu = "SHOW_TOOLBAR_ITEM_MENU"
static let showDockIcon = "SHOW_DOCK_ICON"

static let globalApplicationArgumentsString = "GLOBAL_APPLICATION_ARGUMENTS_STRING"
static let globalApplicationEnvironmentString = "GLOBAL_APPLICATION_ENVIRONMENT_STRING"
Expand All @@ -36,7 +35,6 @@ enum Key {
static let fileTypes = "RCLICK_FILE_TYPES"
static let commonDirs = "RCLICK_COMMON_DIRS"
static let showMenuBarExtra = "showMenuBarExtra"
static let showInDock = "SHOW_IN_DOCK"
static let actionMenuItems = "RCLICK_ACTION_MENU_ITEMS"
static let appMenuItems = "RCLICK_APP_MENU_ITEMS"

Expand Down
65 changes: 51 additions & 14 deletions specs/external-volumes-observation.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# External and network volume observation (#148, #150)
# External and network volume observation (#148, #150, #155, #158)

Finder observation and file-operation authorization are separate. Registering a
security-scoped bookmark in the app does not add a Finder Sync observation root.
The old extension registered only `/`, once at startup. It neither enumerated
mounted volumes nor handled volume lifecycle changes.

Apple documents recursive subdirectory observation, but does not explicitly
promise traversal across volume boundaries. Adding `/Volumes` alone still relies
on that assumption and misses volumes mounted elsewhere. Register `/` plus all
URLs from `FileManager.mountedVolumeURLs(includingResourceValuesForKeys:nil,
options:[])`, without filtering out network, hidden, or non-removable volumes.
No directory traversal or volume resource-value queries are needed.
## Observation roots

The extension registers `/` once at startup, then every mounted volume. Apple
documents recursive subdirectory observation but does not promise traversal
across volume boundaries, so `/` alone does not cover a volume mounted under
`/Volumes`. Enumerate with `FileManager.mountedVolumeURLs(includingResourceValues
ForKeys:options:[])`, without filtering out network, hidden, or non-removable
volumes. No directory traversal or volume resource-value queries are needed.

Subscribe to `NSWorkspace.shared.notificationCenter` before taking the initial
snapshot. Apply mount/unmount/rename notification URLs directly to the current
Expand All @@ -19,22 +19,57 @@ enumeration can still return the ejected volume. Blindly rescanning on every
notification therefore leaves stale roots. Re-enumerate only when notification
URLs are unavailable or the initial snapshot has not succeeded; preserve the
previous set on enumeration failure and apply event paths after any retry. Assign
`directoryURLs` only when the set changes. Observer lifetime follows the extension;
UI-framework interaction and observer cleanup use the main actor.
`directoryURLs` only when the set changes. Observer lifetime follows the
extension; UI-framework interaction and observer cleanup use the main actor.

## The volume's sidebar icon (#155, #158)

Observing a volume root is what makes Finder redraw that volume's sidebar icon
with the extension's own icon. RClick ships no sidebar iconset — the documented
way to supply one — so Finder falls back to the app icon: every external disk and
mounted disk image appears in the sidebar wearing RClick's icon. Measured on this
machine against the installed 2.3.0: mounting a DMG volume produced a sidebar
entry carrying RClick's app icon, while `/` (`Macintosh HD`) and every favourite
folder kept theirs. Badges were blamed twice for this symptom (#128, #155) and
measured false both times; they are not involved.

**Observing the volumes' contents instead of their roots does not work.** That
variant was implemented, and it removes the icon problem by never observing a
mount point — but it produced no menu anywhere on the volume, including inside
its folders. The reason is the sandbox: `application.sb` allows sandboxed apps to
read `(literal "/Volumes")` and nothing below it, and the extension holds no
bookmark for a user's volume, so its directory listing is denied and the volume
contributes no observation roots at all. A sandboxed FinderSync extension cannot
discover what is on a volume; it can only observe the volume.

So the extension observes volume roots and the sidebar icon is a known
consequence, accepted deliberately: a working menu on external disks is worth
more than their sidebar icon, and the alternative loses both. `#158` stays open
as a macOS limitation. If a future release wants the icon as well, the only route
seen so far is the documented sidebar iconset — an iconset in the containing app
with monochrome `sidebar_*.png` templates — which would have to be measured
before it is believed.

## Validation

- Release build and the complete existing test suite passed with
`CODE_SIGNING_ALLOWED=NO` under Swift 6.
`CODE_SIGNING_ALLOWED=NO` under Swift 6 and with signing enabled. Note that the
test host must be signed: built with `CODE_SIGNING_ALLOWED=NO` it cannot open
its App Group container, exits at launch, and the runner reports "hung before
establishing connection" rather than a test failure.
- Regression test `notificationPathsOverrideStaleVolumeEnumeration` failed with
rescan-only handling and passed after applying notification URLs.
- Tests cover startup volumes, simulated external/NAS/custom mount paths,
mount/unmount/rename, duplicate events, failed enumeration and cleanup.
- A temporary DMG using the production observer and real NSWorkspace notifications
produced `probe-volume-present=false → true → false` without restarting the
observer. The DMG was ejected after the probe.
- Normal signing remains blocked by missing upstream provisioning profiles.
This verifies observation-root management, not a signed Finder installation or
- The subdirectory variant was measured on this machine with a real USB volume
(mounted at `/Volumes/UPAN`, folders at its root): the volume kept its own
sidebar icon — the intended effect — and had no RClick menu anywhere, root or
subfolder, which is why it was abandoned.
- Normal signing remains blocked by missing upstream provisioning profiles. This
verifies observation-root management, not a signed Finder installation or
physical USB / SMB / NFS / AFP menu appearance and action execution.

After signing and enabling the extension, check a volume mounted before launch,
Expand All @@ -49,3 +84,5 @@ Sources:
- https://developer.apple.com/documentation/appkit/nsworkspace/didmountnotification
- https://developer.apple.com/documentation/appkit/nsworkspace/didunmountnotification
- https://developer.apple.com/documentation/appkit/nsworkspace/didrenamevolumenotification
- https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/Finder.html
- `/System/Library/Sandbox/Profiles/application.sb` (`(literal "/Volumes")`)
Loading