move option video-save-directory and allow-auto-record-outgoing to local (#9715)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages 2024-10-22 08:24:52 +08:00 committed by GitHub
parent 6088920f8d
commit 6159449eba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 34 additions and 14 deletions

View File

@ -580,7 +580,8 @@ class _GeneralState extends State<_General> {
kOptionAllowAutoRecordIncoming),
if (!bind.isIncomingOnly())
_OptionCheckBox(context, 'Automatically record outgoing sessions',
kOptionAllowAutoRecordOutgoing),
kOptionAllowAutoRecordOutgoing,
isServer: false),
if (showRootDir && !bind.isOutgoingOnly())
Row(
children: [
@ -635,7 +636,7 @@ class _GeneralState extends State<_General> {
await FilePicker.platform.getDirectoryPath(
initialDirectory: initialDirectory);
if (selectedDirectory != null) {
await bind.mainSetOption(
await bind.mainSetLocalOption(
key: kOptionVideoSaveDirectory,
value: selectedDirectory);
setState(() {});

View File

@ -106,7 +106,7 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
_autoRecordIncomingSession = option2bool(kOptionAllowAutoRecordIncoming,
bind.mainGetOptionSync(key: kOptionAllowAutoRecordIncoming));
_autoRecordOutgoingSession = option2bool(kOptionAllowAutoRecordOutgoing,
bind.mainGetOptionSync(key: kOptionAllowAutoRecordOutgoing));
bind.mainGetLocalOption(key: kOptionAllowAutoRecordOutgoing));
_localIP = bind.mainGetOptionSync(key: 'local-ip-addr');
_directAccessPort = bind.mainGetOptionSync(key: kOptionDirectAccessPort);
_allowAutoDisconnect = option2bool(kOptionAllowAutoDisconnect,
@ -711,13 +711,13 @@ class _SettingsState extends State<SettingsPage> with WidgetsBindingObserver {
onToggle: isOptionFixed(kOptionAllowAutoRecordOutgoing)
? null
: (v) async {
await bind.mainSetOption(
await bind.mainSetLocalOption(
key: kOptionAllowAutoRecordOutgoing,
value: bool2option(
kOptionAllowAutoRecordOutgoing, v));
final newValue = option2bool(
kOptionAllowAutoRecordOutgoing,
await bind.mainGetOption(
bind.mainGetLocalOption(
key: kOptionAllowAutoRecordOutgoing));
setState(() {
_autoRecordOutgoingSession = newValue;

View File

@ -1562,6 +1562,21 @@ impl LocalConfig {
.unwrap_or_default()
}
// Usually get_option should be used.
pub fn get_option_from_file(k: &str) -> String {
get_or(
&OVERWRITE_LOCAL_SETTINGS,
&Self::load().options,
&DEFAULT_LOCAL_SETTINGS,
k,
)
.unwrap_or_default()
}
pub fn get_bool_option(k: &str) -> bool {
option2bool(k, &Self::get_option(k))
}
pub fn set_option(k: String, v: String) {
if !is_option_can_save(&OVERWRITE_LOCAL_SETTINGS, &k, &DEFAULT_LOCAL_SETTINGS, &v) {
return;
@ -2326,6 +2341,8 @@ pub mod keys {
OPTION_DISABLE_GROUP_PANEL,
OPTION_PRE_ELEVATE_SERVICE,
OPTION_ALLOW_REMOTE_CM_MODIFICATION,
OPTION_ALLOW_AUTO_RECORD_OUTGOING,
OPTION_VIDEO_SAVE_DIRECTORY,
];
// DEFAULT_SETTINGS, OVERWRITE_SETTINGS
pub const KEYS_SETTINGS: &[&str] = &[
@ -2347,8 +2364,6 @@ pub mod keys {
OPTION_AUTO_DISCONNECT_TIMEOUT,
OPTION_ALLOW_ONLY_CONN_WINDOW_OPEN,
OPTION_ALLOW_AUTO_RECORD_INCOMING,
OPTION_ALLOW_AUTO_RECORD_OUTGOING,
OPTION_VIDEO_SAVE_DIRECTORY,
OPTION_ENABLE_ABR,
OPTION_ALLOW_REMOVE_WALLPAPER,
OPTION_ALLOW_ALWAYS_SOFTWARE_RENDER,

View File

@ -1442,7 +1442,7 @@ impl LoginConfigHandler {
self.adapter_luid = adapter_luid;
self.selected_windows_session_id = None;
self.shared_password = shared_password;
self.record = Config::get_bool_option(OPTION_ALLOW_AUTO_RECORD_OUTGOING);
self.record = LocalConfig::get_bool_option(OPTION_ALLOW_AUTO_RECORD_OUTGOING);
}
/// Check if the client should auto login.

View File

@ -890,7 +890,7 @@ pub async fn set_data(data: &Data) -> ResultType<()> {
set_data_async(data).await
}
pub async fn set_data_async(data: &Data) -> ResultType<()> {
async fn set_data_async(data: &Data) -> ResultType<()> {
let mut c = connect(1000, "").await?;
c.send(data).await?;
Ok(())

View File

@ -253,7 +253,7 @@ class Enhancements: Reactor.Component {
var root_dir = show_root_dir ? handler.video_save_directory(true) : "";
var ts0 = handler.get_option("enable-record-session") == '' ? { checked: true } : {};
var ts1 = handler.get_option("allow-auto-record-incoming") == 'Y' ? { checked: true } : {};
var ts2 = handler.get_option("allow-auto-record-outgoing") == 'Y' ? { checked: true } : {};
var ts2 = handler.get_local_option("allow-auto-record-outgoing") == 'Y' ? { checked: true } : {};
msgbox("custom-recording", translate('Recording'),
<div .form>
<div><button|checkbox(enable_record_session) {ts0}>{translate('Enable recording session')}</button></div>
@ -269,8 +269,8 @@ class Enhancements: Reactor.Component {
if (!res) return;
handler.set_option("enable-record-session", res.enable_record_session ? '' : 'N');
handler.set_option("allow-auto-record-incoming", res.auto_record_incoming ? 'Y' : '');
handler.set_option("allow-auto-record-outgoing", res.auto_record_outgoing ? 'Y' : '');
handler.set_option("video-save-directory", $(#folderPath).text);
handler.set_local_option("allow-auto-record-outgoing", res.auto_record_outgoing ? 'Y' : '');
handler.set_local_option("video-save-directory", $(#folderPath).text);
});
}
this.toggleMenuState();

View File

@ -212,7 +212,7 @@ pub fn get_builtin_option(key: &str) -> String {
#[inline]
pub fn set_local_option(key: String, value: String) {
LocalConfig::set_option(key, value);
LocalConfig::set_option(key.clone(), value.clone());
}
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
@ -844,7 +844,11 @@ pub fn video_save_directory(root: bool) -> String {
return dir.to_string_lossy().to_string();
}
}
let dir = Config::get_option("video-save-directory");
// Get directory from config file otherwise --server will use the old value from global var.
#[cfg(any(target_os = "linux", target_os = "macos"))]
let dir = LocalConfig::get_option_from_file(OPTION_VIDEO_SAVE_DIRECTORY);
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
let dir = LocalConfig::get_option(OPTION_VIDEO_SAVE_DIRECTORY);
if !dir.is_empty() {
return dir;
}