Skip to content

Commit

Permalink
fix: turn off the alert volume instead of system volume (#539)
Browse files Browse the repository at this point in the history
* fix: turn off the alert volume instead of system volume

* perf: remove unused disableEmptyCopyBeep

* perf: improve dismissing pop button

* perf: change alert volume type from float to NSInteger
  • Loading branch information
tisfeng authored May 7, 2024
1 parent 8c4ac14 commit 92735ae
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 175 deletions.
12 changes: 12 additions & 0 deletions Easydict.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
038EA1AA2B41169C008A6DD1 /* ZipArchive in Frameworks */ = {isa = PBXBuildFile; productRef = 038EA1A92B41169C008A6DD1 /* ZipArchive */; };
038EA1AD2B41282F008A6DD1 /* MJExtension in Frameworks */ = {isa = PBXBuildFile; productRef = 038EA1AC2B41282F008A6DD1 /* MJExtension */; };
038F1F8F2BAD838F00CD2F65 /* NSMenu+PopUpBelowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 038F1F8E2BAD838F00CD2F65 /* NSMenu+PopUpBelowView.swift */; };
039459F72BE7DD6300FD70F9 /* AppleScriptUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 039459F62BE7DD6300FD70F9 /* AppleScriptUtils.swift */; };
0396D611292C932F006A11D9 /* EZSelectLanguageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 0396D610292C932F006A11D9 /* EZSelectLanguageCell.m */; };
0396D615292CC4C3006A11D9 /* EZLocalStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = 0396D614292CC4C3006A11D9 /* EZLocalStorage.m */; };
0396DE552BB5844A009FD2A5 /* BaseOpenAIService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0396DE542BB5844A009FD2A5 /* BaseOpenAIService.swift */; };
Expand Down Expand Up @@ -501,6 +502,7 @@
03882F8C29D95044005B5A52 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
038A723F2B62C0B9004995E3 /* String+Regex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Regex.swift"; sourceTree = "<group>"; };
038F1F8E2BAD838F00CD2F65 /* NSMenu+PopUpBelowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSMenu+PopUpBelowView.swift"; sourceTree = "<group>"; };
039459F62BE7DD6300FD70F9 /* AppleScriptUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleScriptUtils.swift; sourceTree = "<group>"; };
0396D60F292C932F006A11D9 /* EZSelectLanguageCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EZSelectLanguageCell.h; sourceTree = "<group>"; };
0396D610292C932F006A11D9 /* EZSelectLanguageCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZSelectLanguageCell.m; sourceTree = "<group>"; };
0396D613292CC4C3006A11D9 /* EZLocalStorage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EZLocalStorage.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1374,6 +1376,14 @@
path = AppKit;
sourceTree = "<group>";
};
039459F32BE7D1D100FD70F9 /* GetSelectedText */ = {
isa = PBXGroup;
children = (
039459F62BE7DD6300FD70F9 /* AppleScriptUtils.swift */,
);
path = GetSelectedText;
sourceTree = "<group>";
};
0396D612292CBDFD006A11D9 /* Storage */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2359,6 +2369,7 @@
967712EB2B5B93E200105E0F /* Feature */ = {
isa = PBXGroup;
children = (
039459F32BE7D1D100FD70F9 /* GetSelectedText */,
032A28632BB26DB600265BA4 /* Appearance */,
EA3B81F72B52549B004C0E8B /* Configuration */,
03779F122BB256B5008D3C42 /* DefaultAPIKeys */,
Expand Down Expand Up @@ -3083,6 +3094,7 @@
03BDA7BB2A26DA280079D04F /* XPMArgsKonstants.m in Sources */,
03BE26EB2A24B2AF00FB7117 /* AppDelegate+EZURLScheme.m in Sources */,
03262C1C29EEE91700EFECA0 /* EZEnumTypes.m in Sources */,
039459F72BE7DD6300FD70F9 /* AppleScriptUtils.swift in Sources */,
0333FDA62A035D5700891515 /* NSString+EZChineseText.m in Sources */,
03E02A222924E77100A10260 /* EZMenuItemManager.m in Sources */,
039D119929D5E26300C93F46 /* EZAudioUtils.m in Sources */,
Expand Down
64 changes: 0 additions & 64 deletions Easydict/App/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -1002,38 +1002,6 @@
}
}
},
"disable_empty_copy_beep" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Disable Empty Copy Beep:"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "禁用空复制提示音:"
}
}
}
},
"disable_empty_copy_beep_msg" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Activated when selected text is empty"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "划词内容为空时禁用复制提示音"
}
}
}
},
"disabled_app_list" : {
"comment" : "disabled app list",
"localizations" : {
Expand Down Expand Up @@ -3701,38 +3669,6 @@
}
}
},
"setting.general.voice.disable_empty_copy_beep_msg" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Disable 'beep' when selected text is empty"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "禁用空复制提示音"
}
}
}
},
"setting.general.voice.header" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Sound"
}
},
"zh-Hans" : {
"stringUnit" : {
"state" : "translated",
"value" : "声音"
}
}
}
},
"setting.general.window.fixed_window_position" : {
"localizations" : {
"en" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ extension Defaults.Keys {
static let autoSelectText = Key<Bool>("EZConfiguration_kAutoSelectTextKey", default: true)
static let forceAutoGetSelectedText = Key<Bool>("EZConfiguration_kForceAutoGetSelectedText", default: false)

static let disableEmptyCopyBeep = Key<Bool>("EZConfiguration_kDisableEmptyCopyBeepKey", default: true)
static let clickQuery = Key<Bool>("EZConfiguration_kClickQueryKey", default: false)
static let autoPlayAudio = Key<Bool>("EZConfiguration_kAutoPlayAudioKey", default: true)
static let launchAtStartup = Key<Bool>("EZConfiguration_kLaunchAtStartupKey", default: false)
Expand Down
13 changes: 0 additions & 13 deletions Easydict/Swift/Feature/Configuration/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class Configuration: NSObject {

@DefaultsWrapper(.forceAutoGetSelectedText) var forceAutoGetSelectedText: Bool

@DefaultsWrapper(.disableEmptyCopyBeep) var disableEmptyCopyBeep: Bool // Some apps will beep when empty copy.

@DefaultsWrapper(.clickQuery) var clickQuery: Bool

@DefaultsWrapper(.launchAtStartup) var launchAtStartup: Bool
Expand Down Expand Up @@ -195,13 +193,6 @@ class Configuration: NSObject {
}
.store(in: &cancellables)

Defaults.publisher(.disableEmptyCopyBeep)
.removeDuplicates()
.sink { [weak self] _ in
self?.didSetDisableEmptyCopyBeep()
}
.store(in: &cancellables)

Defaults.publisher(.clickQuery)
.removeDuplicates()
.sink { [weak self] _ in
Expand Down Expand Up @@ -429,10 +420,6 @@ extension Configuration {
logSettings(["force_get_selected_text": forceAutoGetSelectedText])
}

fileprivate func didSetDisableEmptyCopyBeep() {
logSettings(["disableEmptyCopyBeep": disableEmptyCopyBeep])
}

fileprivate func didSetClickQuery() {
EZWindowManager.shared().updatePopButtonQueryAction()

Expand Down
42 changes: 42 additions & 0 deletions Easydict/Swift/Feature/GetSelectedText/AppleScriptUtils.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// AppleScriptUtils.swift
// Easydict
//
// Created by tisfeng on 2024/5/5.
// Copyright © 2024 izual. All rights reserved.
//

import Foundation

// MARK: - AppleScriptUtils

@objcMembers
class AppleScriptUtils: NSObject {
static func getAlertVolume() -> Int32 {
var error: NSDictionary?
let script = """
set alertVolume to alert volume of (get volume settings)
return alertVolume
"""
let appleScript = NSAppleScript(source: script)
if let outputEvent = appleScript?.executeAndReturnError(&error) {
return outputEvent.int32Value
} else {
if let error = error {
logError(error.description)
}
return 0
}
}

static func setAlertVolume(_ volume: Int) {
var error: NSDictionary?
let script = """
tell application "System Events"
set volume alert volume \(volume)
end tell
"""
let appleScript = NSAppleScript(source: script)
appleScript?.executeAndReturnError(&error)
}
}
12 changes: 1 addition & 11 deletions Easydict/Swift/View/SettingView/Tabs/TabView/GeneralTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ struct GeneralTab: View {
Text("setting.general.mouse_query.header")
}

Section {
Toggle(
"setting.general.voice.disable_empty_copy_beep_msg",
isOn: $disableEmptyCopyBeep
) // 禁用提示音:划词内容为空时生效
Toggle("setting.general.voice.auto_play_word_audio", isOn: $autoPlayAudio) // 查询英语单词后自动播放发音
} header: {
Text("setting.general.voice.header")
}

Section {
Picker(
"setting.general.window.mouse_select_translate_window_type",
Expand Down Expand Up @@ -121,6 +111,7 @@ struct GeneralTab: View {
Toggle("auto_query_ocr_text", isOn: $autoQueryOCRText)
Toggle("auto_query_selected_text", isOn: $autoQuerySelectedText)
Toggle("auto_query_pasted_text", isOn: $autoQueryPastedText)
Toggle("setting.general.voice.auto_play_word_audio", isOn: $autoPlayAudio) // 查询英语单词后自动播放发音
} header: {
Text("setting.general.auto_query.header")
}
Expand Down Expand Up @@ -262,7 +253,6 @@ struct GeneralTab: View {
@Default(.automaticWordSegmentation) var automaticWordSegmentation: Bool
@Default(.automaticallyRemoveCodeCommentSymbols) var automaticallyRemoveCodeCommentSymbols: Bool

@Default(.disableEmptyCopyBeep) private var disableEmptyCopyBeep
@Default(.autoPlayAudio) private var autoPlayAudio

@Default(.autoQueryOCRText) private var autoQueryOCRText
Expand Down
Loading

0 comments on commit 92735ae

Please sign in to comment.