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
30 changes: 30 additions & 0 deletions Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,16 @@
}
}
},
"Click" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "点击"
}
}
}
},
"Click the refresh button above to fetch available models, or add a custom model below." : {
"localizations" : {
"zh-Hans" : {
Expand Down Expand Up @@ -837,6 +847,16 @@
}
}
},
"Floating Icon Activation:" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "悬浮球触发方式:"
}
}
}
},
"Font Size: %lld" : {
"extractionState" : "stale",
"localizations" : {
Expand Down Expand Up @@ -1009,6 +1029,16 @@
}
}
},
"Hover" : {
"localizations" : {
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "悬停"
}
}
}
},
"Image file too large. Maximum 2 MB." : {
"extractionState" : "stale",
"localizations" : {
Expand Down
6 changes: 6 additions & 0 deletions Sources/UI/Settings/GeneralSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct GeneralSettingsView: View {
@Default(.targetLanguage) private var targetLanguage
@Default(.isAutoDetectEnabled) private var isAutoDetectEnabled
@Default(.textDetectionMode) private var textDetectionMode
@Default(.triggerActivationMode) private var triggerActivationMode
@Default(.showInDock) private var showInDock
@Default(.popupDefaultWidth) private var popupDefaultWidth
@Default(.popupDefaultHeight) private var popupDefaultHeight
Expand Down Expand Up @@ -122,6 +123,11 @@ struct GeneralSettingsView: View {
Toggle("Show floating icon on text selection", isOn: $isAutoDetectEnabled)

if isAutoDetectEnabled {
Picker("Floating Icon Activation:", selection: $triggerActivationMode) {
Text("Hover").tag(TriggerActivationMode.hover)
Text("Click").tag(TriggerActivationMode.click)
}

Picker("Text Detection Mode:", selection: $textDetectionMode) {
Text("Conservative").tag(TextDetectionMode.conservative)
Text("Standard").tag(TextDetectionMode.standard)
Expand Down
22 changes: 20 additions & 2 deletions Sources/UI/TriggerIcon/TriggerIconController.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AppKit
import Defaults

// MARK: - TriggerTrackingView

Expand Down Expand Up @@ -104,11 +105,28 @@ final class TriggerIconController {
let panel = TriggerIconPanel()
let trackingView = TriggerTrackingView(frame: NSRect(x: 0, y: 0, width: TriggerIconPanel.size, height: TriggerIconPanel.size))

let activationMode = Defaults[.triggerActivationMode]

trackingView.onMouseEntered = { [weak self] in
self?.startHoverTimer()
guard let self else { return }
switch activationMode {
case .hover:
self.startHoverTimer()
case .click:
// Pause auto-dismiss while cursor is over the icon so the user has time to click.
self.cancelAutoDismissTimer()
}
}
trackingView.onMouseExited = { [weak self] in
self?.cancelHoverTimer()
guard let self else { return }
switch activationMode {
case .hover:
self.cancelHoverTimer()
Comment thread
yusixian marked this conversation as resolved.
case .click:
// In click mode, mouseEntered paused auto-dismiss; restart it on exit
// so the icon eventually disappears if the user never clicks.
self.startAutoDismissTimer()
}
}
trackingView.onMouseDown = { [weak self] in
self?.triggerTranslation()
Expand Down
8 changes: 8 additions & 0 deletions Sources/Utilities/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ enum MenuBarIconCatalog {
]
}

// MARK: - Trigger Icon Activation Mode

enum TriggerActivationMode: String, CaseIterable, Defaults.Serializable {
case hover // Hover over the trigger icon (default behavior)
case click // Click the trigger icon
}

// MARK: - Settings Tab

enum SettingsTab: String, Defaults.Serializable {
Expand Down Expand Up @@ -152,6 +159,7 @@ extension Defaults.Keys {
// Auto-detect text selection
static let isAutoDetectEnabled = Key<Bool>("isAutoDetectEnabled", default: true)
static let textDetectionMode = Key<TextDetectionMode>("textDetectionMode", default: .full)
static let triggerActivationMode = Key<TriggerActivationMode>("triggerActivationMode", default: .hover)
static let excludedAppBundleIDs = Key<Set<String>>("excludedAppBundleIDs", default: [])

// Appearance
Expand Down
Loading