mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-05-11 18:36:11 +02:00
Refact. Flutter web desktop (#7539)
* Refact. Flutter web desktop Signed-off-by: fufesou <shuanglongchen@yeah.net> * Flutter web, prevent default context menu Signed-off-by: fufesou <shuanglongchen@yeah.net> --------- Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
810b980e6b
commit
6e44a91d0b
27 changed files with 362 additions and 153 deletions
|
@ -652,7 +652,7 @@ export default class Connection {
|
|||
}
|
||||
|
||||
getOption(name: string): any {
|
||||
return this._options[name];
|
||||
return this._options[name] ?? globals.getUserDefaultOption(name);
|
||||
}
|
||||
|
||||
getToggleOption(name: string): Boolean {
|
||||
|
@ -839,6 +839,52 @@ export default class Connection {
|
|||
}
|
||||
|
||||
toggleOption(name: string) {
|
||||
|
||||
// } else if name == "block-input" {
|
||||
// option.block_input = BoolOption::Yes.into();
|
||||
// } else if name == "unblock-input" {
|
||||
// option.block_input = BoolOption::No.into();
|
||||
// } else if name == "show-quality-monitor" {
|
||||
// config.show_quality_monitor.v = !config.show_quality_monitor.v;
|
||||
// } else if name == "allow_swap_key" {
|
||||
// config.allow_swap_key.v = !config.allow_swap_key.v;
|
||||
// } else if name == "view-only" {
|
||||
// config.view_only.v = !config.view_only.v;
|
||||
// let f = |b: bool| {
|
||||
// if b {
|
||||
// BoolOption::Yes.into()
|
||||
// } else {
|
||||
// BoolOption::No.into()
|
||||
// }
|
||||
// };
|
||||
// if config.view_only.v {
|
||||
// option.disable_keyboard = f(true);
|
||||
// option.disable_clipboard = f(true);
|
||||
// option.show_remote_cursor = f(true);
|
||||
// option.enable_file_transfer = f(false);
|
||||
// option.lock_after_session_end = f(false);
|
||||
// } else {
|
||||
// option.disable_keyboard = f(false);
|
||||
// option.disable_clipboard = f(self.get_toggle_option("disable-clipboard"));
|
||||
// option.show_remote_cursor = f(self.get_toggle_option("show-remote-cursor"));
|
||||
// option.enable_file_transfer = f(self.config.enable_file_transfer.v);
|
||||
// option.lock_after_session_end = f(self.config.lock_after_session_end.v);
|
||||
// }
|
||||
// } else {
|
||||
// let is_set = self
|
||||
// .options
|
||||
// .get(&name)
|
||||
// .map(|o| !o.is_empty())
|
||||
// .unwrap_or(false);
|
||||
// if is_set {
|
||||
// self.config.options.remove(&name);
|
||||
// } else {
|
||||
// self.config.options.insert(name, "Y".to_owned());
|
||||
// }
|
||||
// self.config.store(&self.id);
|
||||
// return None;
|
||||
// }
|
||||
|
||||
const v = !this._options[name];
|
||||
const option = message.OptionMessage.fromPartial({});
|
||||
const v2 = v
|
||||
|
@ -860,13 +906,43 @@ export default class Connection {
|
|||
case "privacy-mode":
|
||||
option.privacy_mode = v2;
|
||||
break;
|
||||
case "enable-file-transfer":
|
||||
option.enable_file_transfer = v2;
|
||||
break;
|
||||
case "block-input":
|
||||
option.block_input = message.OptionMessage_BoolOption.Yes;
|
||||
break;
|
||||
case "unblock-input":
|
||||
option.block_input = message.OptionMessage_BoolOption.No;
|
||||
break;
|
||||
case "show-quality-monitor":
|
||||
case "allow-swap-key":
|
||||
break;
|
||||
case "view-only":
|
||||
if (v) {
|
||||
option.disable_keyboard = message.OptionMessage_BoolOption.Yes;
|
||||
option.disable_clipboard = message.OptionMessage_BoolOption.Yes;
|
||||
option.show_remote_cursor = message.OptionMessage_BoolOption.Yes;
|
||||
option.enable_file_transfer = message.OptionMessage_BoolOption.No;
|
||||
option.lock_after_session_end = message.OptionMessage_BoolOption.No;
|
||||
} else {
|
||||
option.disable_keyboard = message.OptionMessage_BoolOption.No;
|
||||
option.disable_clipboard = this.getToggleOption("disable-clipboard")
|
||||
? message.OptionMessage_BoolOption.Yes
|
||||
: message.OptionMessage_BoolOption.No;
|
||||
option.show_remote_cursor = this.getToggleOption("show-remote-cursor")
|
||||
? message.OptionMessage_BoolOption.Yes
|
||||
: message.OptionMessage_BoolOption.No;
|
||||
option.enable_file_transfer = this.getToggleOption("enable-file-transfer")
|
||||
? message.OptionMessage_BoolOption.Yes
|
||||
: message.OptionMessage_BoolOption.No;
|
||||
option.lock_after_session_end = this.getToggleOption("lock-after-session-end")
|
||||
? message.OptionMessage_BoolOption.Yes
|
||||
: message.OptionMessage_BoolOption.No;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this.setOption(name, this._options[name] ? undefined : "Y");
|
||||
return;
|
||||
}
|
||||
if (name.indexOf("block-input") < 0) this.setOption(name, v);
|
||||
|
|
|
@ -211,7 +211,7 @@ window.setByName = (name, value) => {
|
|||
curConn.refresh();
|
||||
break;
|
||||
case 'reconnect':
|
||||
curConn.reconnect();
|
||||
curConn?.reconnect();
|
||||
break;
|
||||
case 'toggle_option':
|
||||
curConn.toggleOption(value);
|
||||
|
@ -244,6 +244,7 @@ window.setByName = (name, value) => {
|
|||
curConn.inputString(value);
|
||||
break;
|
||||
case 'send_mouse':
|
||||
if (!curConn) return;
|
||||
let mask = 0;
|
||||
value = JSON.parse(value);
|
||||
switch (value.type) {
|
||||
|
@ -288,6 +289,9 @@ window.setByName = (name, value) => {
|
|||
value = JSON.parse(value);
|
||||
localStorage.setItem(name + ':' + value.name, value.value);
|
||||
break;
|
||||
case 'option:user:default':
|
||||
setUserDefaultOption(value);
|
||||
break;
|
||||
case 'option:session':
|
||||
value = JSON.parse(value);
|
||||
curConn.setOption(value.name, value.value);
|
||||
|
@ -295,12 +299,11 @@ window.setByName = (name, value) => {
|
|||
case 'option:peer':
|
||||
setPeerOption(value);
|
||||
break;
|
||||
case 'option:toggle':
|
||||
return curConn.toggleOption(value);
|
||||
case 'input_os_password':
|
||||
curConn.inputOsPassword(value);
|
||||
break;
|
||||
case 'check_conn_status':
|
||||
curConn.checkConnStatus();
|
||||
break;
|
||||
case 'session_add_sync':
|
||||
return sessionAdd(value);
|
||||
case 'session_start':
|
||||
|
@ -374,8 +377,14 @@ function _getByName(name, arg) {
|
|||
case 'translate':
|
||||
arg = JSON.parse(arg);
|
||||
return translate(arg.locale, arg.text);
|
||||
case 'option:user:default':
|
||||
return getUserDefaultOption(arg);
|
||||
case 'option:session':
|
||||
return curConn.getOption(arg);
|
||||
if (curConn) {
|
||||
return curConn.getOption(arg);
|
||||
} else {
|
||||
return getUserDefaultOption(arg);
|
||||
}
|
||||
case 'option:peer':
|
||||
return getPeerOption(arg);
|
||||
case 'option:toggle':
|
||||
|
@ -412,6 +421,28 @@ function _getByName(name, arg) {
|
|||
return getAuditServer(arg);
|
||||
case 'alternative_codecs':
|
||||
return getAlternativeCodecs();
|
||||
case 'screen_info':
|
||||
return JSON.stringify({
|
||||
frame: {
|
||||
l: window.screenX,
|
||||
t: window.screenY,
|
||||
r: window.screenX + window.innerWidth,
|
||||
b: window.screenY + window.innerHeight,
|
||||
},
|
||||
visibleFrame: {
|
||||
l: window.screen.availLeft,
|
||||
t: window.screen.availTop,
|
||||
r: window.screen.availLeft + window.screen.availWidth,
|
||||
b: window.screen.availTop + window.screen.availHeight,
|
||||
},
|
||||
scaleFactor: window.devicePixelRatio,
|
||||
});
|
||||
case 'main_display':
|
||||
return JSON.stringify({
|
||||
w: window.screen.availWidth,
|
||||
h: window.screen.availHeight,
|
||||
scaleFactor: window.devicePixelRatio,
|
||||
});
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
@ -521,20 +552,52 @@ export function getVersionNumber(v) {
|
|||
}
|
||||
}
|
||||
|
||||
// ========================== options begin ==========================
|
||||
function setUserDefaultOption(value) {
|
||||
try {
|
||||
const ojb = JSON.parse(value);
|
||||
const userDefaultOptions = JSON.parse(localStorage.getItem('user-default-options')) || {};
|
||||
userDefaultOptions[ojb.name] = ojb.value;
|
||||
localStorage.setItem('user-default-options', JSON.stringify(userDefaultOptions));
|
||||
}
|
||||
catch (e) {
|
||||
console.error('Failed to set user default options: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
export function getUserDefaultOption(value) {
|
||||
const defaultOptions = {
|
||||
'view_style': 'original',
|
||||
'scroll_style': 'scrollauto',
|
||||
'image_quality': 'balanced',
|
||||
'codec-preference': 'auto',
|
||||
'custom_image_quality': '50',
|
||||
'custom-fps': '30',
|
||||
};
|
||||
try {
|
||||
const userDefaultOptions = JSON.parse(localStorage.getItem('user-default-options')) || {};
|
||||
return userDefaultOptions[value] || defaultOptions[value] || '';
|
||||
}
|
||||
catch (e) {
|
||||
console.error('Failed to get user default options: ' + e.message);
|
||||
return defaultOptions[value] || '';
|
||||
}
|
||||
}
|
||||
|
||||
function getPeerOption(value) {
|
||||
try {
|
||||
const obj = JSON.parse(value);
|
||||
const options = getPeers()[obj.id] || {};
|
||||
return options[obj.name] || '';
|
||||
return options[obj.name] ?? getUserDefaultOption(obj.name);
|
||||
}
|
||||
catch (e) {
|
||||
console.error('Failed to get peer option: "' + value + '", ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
function setPeerOption(value) {
|
||||
function setPeerOption(param) {
|
||||
try {
|
||||
const obj = JSON.parse(value);
|
||||
const obj = JSON.parse(param);
|
||||
const id = obj.id;
|
||||
const name = obj.name;
|
||||
const value = obj.value;
|
||||
|
@ -554,6 +617,7 @@ function setPeerOption(value) {
|
|||
console.error('Failed to set peer option: "' + value + '", ' + e.message);
|
||||
}
|
||||
}
|
||||
// ========================= options end ===========================
|
||||
|
||||
// ========================== peers begin ==========================
|
||||
function getRecentPeers() {
|
||||
|
@ -668,10 +732,10 @@ function increasePort(host, offset) {
|
|||
|
||||
function getAlternativeCodecs() {
|
||||
return JSON.stringify({
|
||||
vp8: 1,
|
||||
av1: 0,
|
||||
h264: 1,
|
||||
h265: 1,
|
||||
vp8: true,
|
||||
av1: false,
|
||||
h264: false,
|
||||
h265: false,
|
||||
});
|
||||
}
|
||||
// ========================== settings end ===========================
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue