refactor msgbox

This commit is contained in:
rustdesk 2021-12-29 11:42:43 +08:00
parent 8be7331cb6
commit 365fc90d8b
7 changed files with 29 additions and 33 deletions

8
Cargo.lock generated
View File

@ -2569,9 +2569,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.34" version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1" checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
dependencies = [ dependencies = [
"unicode-xid", "unicode-xid",
] ]
@ -2728,9 +2728,9 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.10" version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
] ]

View File

@ -146,7 +146,7 @@ class SessionList: Reactor.Component {
createNewConnect(id, "port-forward"); createNewConnect(id, "port-forward");
} else if (action == "rename") { } else if (action == "rename") {
var old_name = handler.get_peer_option(id, "alias"); var old_name = handler.get_peer_option(id, "alias");
handler.msgbox("custom-rename", "Rename", "<div .form> \ msgbox("custom-rename", "Rename", "<div .form> \
<div><input name='name' .outline-focus style='width: *; height: 23px', value='" + old_name + "' /></div> \ <div><input name='name' .outline-focus style='width: *; height: 23px', value='" + old_name + "' /></div> \
</div> \ </div> \
", function(res=null) { ", function(res=null) {

View File

@ -216,7 +216,7 @@ function getMsgboxParams() {
return msgbox_params; return msgbox_params;
} }
function msgbox(type, title, text, callback, height, width, retry=0, contentStyle="") { function msgbox(type, title, text, callback=null, height=180, width=500, retry=0, contentStyle="") {
var has_msgbox = msgbox_params != null; var has_msgbox = msgbox_params != null;
if (!has_msgbox && !type) return; if (!has_msgbox && !type) return;
var remember = false; var remember = false;
@ -249,7 +249,7 @@ function msgbox(type, title, text, callback, height, width, retry=0, contentStyl
} else if (res == "!alive") { } else if (res == "!alive") {
// do nothing // do nothing
} else if (res.type == "input-password") { } else if (res.type == "input-password") {
if (!is_port_forward) handler.msgbox("connecting", "Connecting...", "Logging in..."); if (!is_port_forward) msgbox("connecting", "Connecting...", "Logging in...");
handler.login(res.password, res.remember); handler.login(res.password, res.remember);
} else if (res.reconnect) { } else if (res.reconnect) {
if (!is_port_forward) connecting(); if (!is_port_forward) connecting();
@ -261,19 +261,13 @@ function connecting() {
handler.msgbox("connecting", "Connecting...", "Connection in progress. Please wait."); handler.msgbox("connecting", "Connecting...", "Connection in progress. Please wait.");
} }
handler.msgbox = function(type, title, text, callback=null, height=180, width=500, retry=0, contentStyle="") { handler.msgbox = function(type, title, text, retry=0) {
// directly call view.Dialog from native may crash, add timer here, seem safe self.timer(30ms, function() { msgbox(type, title, text, null, 180, 500, retry); });
// too short time, msgbox won't get focus, per my test, 150 is almost minimun
self.timer(150ms, function() { msgbox(type, title, text, callback, height, width, retry, contentStyle); });
}
handler.block_msgbox = function(type, title, text, callback=null, height=180, width=500, retry=0) {
msgbox(type, title, text, callback, height, width, retry);
} }
var reconnectTimeout = 1; var reconnectTimeout = 1;
handler.msgbox_retry = function(type, title, text, hasRetry, callback=null, height=180, width=500) { handler.msgbox_retry = function(type, title, text, hasRetry) {
handler.msgbox(type, title, text, callback, height, width, hasRetry ? reconnectTimeout : 0); handler.msgbox(type, title, text, hasRetry ? reconnectTimeout : 0);
if (hasRetry) { if (hasRetry) {
reconnectTimeout *= 2; reconnectTimeout *= 2;
} else { } else {

View File

@ -431,7 +431,7 @@ class FolderView : Reactor.Component {
event click $(.add-folder) () { event click $(.add-folder) () {
var me = this; var me = this;
handler.msgbox("custom", translate("Create Folder"), "<div .form> \ msgbox("custom", translate("Create Folder"), "<div .form> \
<div>" + translate("Please enter the folder name") + ":</div> \ <div>" + translate("Please enter the folder name") + ":</div> \
<div><input|text(name) .outline-focus /></div> \ <div><input|text(name) .outline-focus /></div> \
</div>", function(res=null) { </div>", function(res=null) {
@ -440,7 +440,7 @@ class FolderView : Reactor.Component {
var name = res.name.trim(); var name = res.name.trim();
if (!name) return; if (!name) return;
if (name.indexOf(me.sep()) >= 0) { if (name.indexOf(me.sep()) >= 0) {
handler.msgbox("custom-error", "Create Folder", "Invalid folder name"); msgbox("custom-error", "Create Folder", "Invalid folder name");
return; return;
} }
var path = me.joinPath(name); var path = me.joinPath(name);
@ -576,16 +576,16 @@ handler.jobDone = function(id, file_num = -1) {
handler.jobError = function(id, err, file_num = -1) { handler.jobError = function(id, err, file_num = -1) {
var job = deleting_single_file_jobs[id]; var job = deleting_single_file_jobs[id];
if (job) { if (job) {
handler.msgbox("custom-error", "Delete File", err); msgbox("custom-error", "Delete File", err);
return; return;
} }
job = create_dir_jobs[id]; job = create_dir_jobs[id];
if (job) { if (job) {
handler.msgbox("custom-error", "Create Folder", err); msgbox("custom-error", "Create Folder", err);
return; return;
} }
if (file_num < 0) { if (file_num < 0) {
handler.msgbox("custom-error", "Failed", err); msgbox("custom-error", "Failed", err);
} }
file_transfer.job_table.updateJobStatus(id, file_num, err); file_transfer.job_table.updateJobStatus(id, file_num, err);
} }
@ -599,7 +599,7 @@ var deleting_single_file_jobs = {};
var create_dir_jobs = {} var create_dir_jobs = {}
function confirmDelete(path, is_remote) { function confirmDelete(path, is_remote) {
handler.block_msgbox("custom-skip", "Confirm Delete", "<div .form> \ msgbox("custom-skip", "Confirm Delete", "<div .form> \
<div>" + translate('Are you sure you want to delete this file?') + "</div> \ <div>" + translate('Are you sure you want to delete this file?') + "</div> \
<div.ellipsis style=\"font-weight: bold;\">" + path + "</div> \ <div.ellipsis style=\"font-weight: bold;\">" + path + "</div> \
</div>", function(res=null) { </div>", function(res=null) {
@ -619,7 +619,7 @@ handler.confirmDeleteFiles = function(id, i, name) {
if (i >= n) return; if (i >= n) return;
var file_path = job.path; var file_path = job.path;
if (name) file_path += handler.get_path_sep(job.is_remote) + name; if (name) file_path += handler.get_path_sep(job.is_remote) + name;
handler.block_msgbox("custom-skip", "Confirm Delete", "<div .form> \ msgbox("custom-skip", "Confirm Delete", "<div .form> \
<div>" + translate('Deleting') + " #" + (i + 1) + " / " + n + " " + translate('files') + ".</div> \ <div>" + translate('Deleting') + " #" + (i + 1) + " / " + n + " " + translate('files') + ".</div> \
<div>" + translate('Are you sure you want to delete this file?') + "</div> \ <div>" + translate('Are you sure you want to delete this file?') + "</div> \
<div.ellipsis style=\"font-weight: bold;\" .text>" + name + "</div> \ <div.ellipsis style=\"font-weight: bold;\" .text>" + name + "</div> \

View File

@ -277,7 +277,7 @@ function handle_custom_image_quality() {
var tmp = handler.get_custom_image_quality(); var tmp = handler.get_custom_image_quality();
var bitrate0 = tmp[0] || 50; var bitrate0 = tmp[0] || 50;
var quantizer0 = tmp.length > 1 ? tmp[1] : 100; var quantizer0 = tmp.length > 1 ? tmp[1] : 100;
handler.msgbox("custom", "Custom Image Quality", "<div .form> \ msgbox("custom", "Custom Image Quality", "<div .form> \
<div><input type=\"hslider\" style=\"width: 50%\" name=\"bitrate\" max=\"100\" min=\"10\" value=\"" + bitrate0 + "\"/ buddy=\"bitrate-buddy\"><b #bitrate-buddy>x</b>% bitrate</div> \ <div><input type=\"hslider\" style=\"width: 50%\" name=\"bitrate\" max=\"100\" min=\"10\" value=\"" + bitrate0 + "\"/ buddy=\"bitrate-buddy\"><b #bitrate-buddy>x</b>% bitrate</div> \
<div><input type=\"hslider\" style=\"width: 50%\" name=\"quantizer\" max=\"100\" min=\"0\" value=\"" + quantizer0 + "\"/ buddy=\"quantizer-buddy\"><b #quantizer-buddy>x</b>% quantizer</div> \ <div><input type=\"hslider\" style=\"width: 50%\" name=\"quantizer\" max=\"100\" min=\"0\" value=\"" + quantizer0 + "\"/ buddy=\"quantizer-buddy\"><b #quantizer-buddy>x</b>% quantizer</div> \
</div>", function(res=null) { </div>", function(res=null) {

View File

@ -71,7 +71,7 @@ function createNewConnect(id, type) {
app.remote_id.value = formatId(id); app.remote_id.value = formatId(id);
if (!id) return; if (!id) return;
if (id == my_id) { if (id == my_id) {
handler.msgbox("custom-error", "Error", "You cannot connect to your own computer"); msgbox("custom-error", "Error", "You cannot connect to your own computer");
return; return;
} }
handler.set_remote_id(id); handler.set_remote_id(id);
@ -182,7 +182,7 @@ class MyIdMenu: Reactor.Component {
} }
if (me.id == "whitelist") { if (me.id == "whitelist") {
var old_value = handler.get_option("whitelist").split(",").join("\n"); var old_value = handler.get_option("whitelist").split(",").join("\n");
handler.msgbox("custom-whitelist", translate("IP Whitelisting"), "<div .form> \ msgbox("custom-whitelist", translate("IP Whitelisting"), "<div .form> \
<div>" + translate("whitelist_sep") + "</div> \ <div>" + translate("whitelist_sep") + "</div> \
<textarea spellcheck=\"false\" name=\"text\" novalue=\"0.0.0.0\" style=\"overflow: scroll-indicator; width:*; height: 160px; font-size: 1.2em; padding: 0.5em;\">" + old_value + "</textarea>\ <textarea spellcheck=\"false\" name=\"text\" novalue=\"0.0.0.0\" style=\"overflow: scroll-indicator; width:*; height: 160px; font-size: 1.2em; padding: 0.5em;\">" + old_value + "</textarea>\
</div> \ </div> \
@ -206,7 +206,7 @@ class MyIdMenu: Reactor.Component {
var configOptions = handler.get_options(); var configOptions = handler.get_options();
var old_relay = configOptions["relay-server"] || ""; var old_relay = configOptions["relay-server"] || "";
var old_id = configOptions["custom-rendezvous-server"] || ""; var old_id = configOptions["custom-rendezvous-server"] || "";
handler.msgbox("custom-server", "ID/Relay Server", "<div .form> \ msgbox("custom-server", "ID/Relay Server", "<div .form> \
<div><span style='width: 100px; display:inline-block'>" + translate("ID Server") + ": </span><input .outline-focus style='width: 250px' name='id' value='" + old_id + "' /></div> \ <div><span style='width: 100px; display:inline-block'>" + translate("ID Server") + ": </span><input .outline-focus style='width: 250px' name='id' value='" + old_id + "' /></div> \
<div><span style='width: 100px; display:inline-block'>" + translate("Relay Server") + ": </span><input style='width: 250px' name='relay' value='" + old_relay + "' /></div> \ <div><span style='width: 100px; display:inline-block'>" + translate("Relay Server") + ": </span><input style='width: 250px' name='relay' value='" + old_relay + "' /></div> \
</div> \ </div> \
@ -231,7 +231,7 @@ class MyIdMenu: Reactor.Component {
handler.set_option("stop-service", service_stopped ? "" : "Y"); handler.set_option("stop-service", service_stopped ? "" : "Y");
} else if (me.id == "about") { } else if (me.id == "about") {
var name = handler.get_app_name(); var name = handler.get_app_name();
handler.msgbox("custom-nocancel-nook-hasclose", "About " + name, "<div style='line-height: 2em'> \ msgbox("custom-nocancel-nook-hasclose", "About " + name, "<div style='line-height: 2em'> \
<div>Version: " + handler.get_version() + " \ <div>Version: " + handler.get_version() + " \
<div .link .custom-event url='http://rustdesk.com/privacy'>Privacy Statement</div> \ <div .link .custom-event url='http://rustdesk.com/privacy'>Privacy Statement</div> \
<div .link .custom-event url='http://rustdesk.com'>Website</div> \ <div .link .custom-event url='http://rustdesk.com'>Website</div> \
@ -412,7 +412,7 @@ class UpdateMe: Reactor.Component {
handler.update_me(path); handler.update_me(path);
}; };
var onerror = function(err) { var onerror = function(err) {
handler.msgbox("custom-error", "Download Error", "Failed to download"); msgbox("custom-error", "Download Error", "Failed to download");
}; };
var onprogress = function(loaded, total) { var onprogress = function(loaded, total) {
if (!total) total = 5 * 1024 * 1024; if (!total) total = 5 * 1024 * 1024;
@ -494,7 +494,7 @@ class ModifyDefaultLogin: Reactor.Component {
event click $(#modify-default-login) { event click $(#modify-default-login) {
if (var r = handler.modify_default_login()) { if (var r = handler.modify_default_login()) {
handler.msgbox("custom-error", "Error", r); msgbox("custom-error", "Error", r);
} }
app.update(); app.update();
} }
@ -557,7 +557,7 @@ class Password: Reactor.Component {
event click $(li#set-password) { event click $(li#set-password) {
var me = this; var me = this;
handler.msgbox("custom-password", translate("Set Password"), "<div .form .set-password> \ msgbox("custom-password", translate("Set Password"), "<div .form .set-password> \
<div><span>" + translate('Password') + ":</span><input|password(password) .outline-focus /></div> \ <div><span>" + translate('Password') + ":</span><input|password(password) .outline-focus /></div> \
<div><span>" + translate('Confirmation') + ":</span><input|password(confirmation) /></div> \ <div><span>" + translate('Confirmation') + ":</span><input|password(confirmation) /></div> \
</div> \ </div> \

View File

@ -80,6 +80,9 @@ impl sciter::EventHandler for Handler {
fn attached(&mut self, root: HELEMENT) { fn attached(&mut self, root: HELEMENT) {
self.write().unwrap().element = Some(Element::from(root)); self.write().unwrap().element = Some(Element::from(root));
if self.is_port_forward() {
return;
}
} }
fn detached(&mut self, _root: HELEMENT) { fn detached(&mut self, _root: HELEMENT) {
@ -855,7 +858,6 @@ impl Handler {
command: bool, command: bool,
extended: bool, extended: bool,
) { ) {
if self.peer_platform() == "Windows" { if self.peer_platform() == "Windows" {
if ctrl && alt && name == "VK_DELETE" { if ctrl && alt && name == "VK_DELETE" {
self.ctrl_alt_del(); self.ctrl_alt_del();