rustdesk/src/ui/header.tis

616 lines
26 KiB
Plaintext
Raw Normal View History

2021-03-29 15:59:14 +08:00
var pi = handler.get_default_pi(); // peer information
var chat_msgs = [];
var svg_fullscreen = <svg viewBox="0 0 357 357">
<path d="M51,229.5H0V357h127.5v-51H51V229.5z M0,127.5h51V51h76.5V0H0V127.5z M306,306h-76.5v51H357V229.5h-51V306z M229.5,0v51 H306v76.5h51V0H229.5z"/>
</svg>;
var svg_action = <svg viewBox="-91 0 512 512"><path d="M315 211H191L298 22a15 15 0 00-13-22H105c-6 0-12 4-14 10L1 281a15 15 0 0014 20h127L61 491a15 15 0 0025 16l240-271a15 15 0 00-11-25z"/></svg>;
var svg_display = <svg viewBox="0 0 640 512">
<path d="M592 0H48A48 48 0 0 0 0 48v320a48 48 0 0 0 48 48h240v32H112a16 16 0 0 0-16 16v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16v-32a16 16 0 0 0-16-16H352v-32h240a48 48 0 0 0 48-48V48a48 48 0 0 0-48-48zm-16 352H64V64h512z"/>
</svg>;
var svg_secure = <svg viewBox="0 0 347.97 347.97">
<path fill="#3F7D46" d="m317.31 54.367c-59.376 0-104.86-16.964-143.33-54.367-38.461 37.403-83.947 54.367-143.32 54.367 0 97.405-20.155 236.94 143.32 293.6 163.48-56.666 143.33-196.2 143.33-293.6zm-155.2 171.41-47.749-47.756 21.379-21.378 26.37 26.376 50.121-50.122 21.378 21.378-71.499 71.502z"/>
</svg>;
var svg_insecure = <svg viewBox="0 0 347.97 347.97"><path d="M317.469 61.615c-59.442 0-104.976-16.082-143.489-51.539-38.504 35.457-84.04 51.539-143.479 51.539 0 92.337-20.177 224.612 143.479 278.324 163.661-53.717 143.489-185.992 143.489-278.324z" fill="none" stroke="red" stroke-width="14.827"/><g fill="red"><path d="M238.802 115.023l-111.573 114.68-8.6-8.367L230.2 106.656z"/><path d="M125.559 108.093l114.68 111.572-8.368 8.601-114.68-111.572z"/></g></svg>;
var svg_insecure_relay = <svg viewBox="0 0 347.97 347.97"><path d="M317.469 61.615c-59.442 0-104.976-16.082-143.489-51.539-38.504 35.457-84.04 51.539-143.479 51.539 0 92.337-20.177 224.612 143.479 278.324 163.661-53.717 143.489-185.992 143.489-278.324z" fill="none" stroke="red" stroke-width="14.827"/><g fill="red"><path d="M231.442 247.498l-7.754-10.205c-17.268 12.441-38.391 17.705-59.478 14.822-21.087-2.883-39.613-13.569-52.166-30.088-25.916-34.101-17.997-82.738 17.65-108.42 32.871-23.685 78.02-19.704 105.172 7.802l-32.052 7.987 3.082 12.369 48.722-12.142-11.712-46.998-12.822 3.196 4.496 18.039c-31.933-24.008-78.103-25.342-112.642-.458-31.361 22.596-44.3 60.436-35.754 94.723 2.77 11.115 7.801 21.862 15.192 31.588 30.19 39.727 88.538 47.705 130.066 17.785z"/></g></svg>;
var svg_secure_relay = <svg viewBox="0 0 347.97 347.97"><path d="M317.469 61.615c-59.442 0-104.976-16.082-143.489-51.539-38.504 35.457-84.04 51.539-143.479 51.539 0 92.337-20.177 224.612 143.479 278.324 163.661-53.717 143.489-185.992 143.489-278.324z" fill="#3f7d46" stroke="#3f7d46" stroke-width="14.827"/><g fill="red"><path d="M231.442 247.498l-7.754-10.205c-17.268 12.441-38.391 17.705-59.478 14.822-21.087-2.883-39.613-13.569-52.166-30.088-25.916-34.101-17.997-82.738 17.65-108.42 32.871-23.685 78.02-19.704 105.172 7.802l-32.052 7.987 3.082 12.369 48.722-12.142-11.712-46.998-12.822 3.196 4.496 18.039c-31.933-24.008-78.103-25.342-112.642-.458-31.361 22.596-44.3 60.436-35.754 94.723 2.77 11.115 7.801 21.862 15.192 31.588 30.19 39.727 88.538 47.705 130.066 17.785z" fill="#fff"/></g></svg>;
var svg_recording_off = <svg t="1663505560063" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5393" width="32" height="32"><path d="M1002.666667 260.266667c-12.8-8.533333-29.866667-4.266667-42.666667 4.266666L725.333333 430.933333V298.666667c0-72.533333-55.466667-128-128-128H128C55.466667 170.666667 0 226.133333 0 298.666667v426.666666c0 72.533333 55.466667 128 128 128h469.333333c72.533333 0 128-55.466667 128-128v-132.266666l230.4 166.4c17.066667 12.8 46.933333 8.533333 59.733334-8.533334 4.266667-8.533333 8.533333-17.066667 8.533333-25.6V298.666667c0-17.066667-8.533333-29.866667-21.333333-38.4zM640 725.333333c0 25.6-17.066667 42.666667-42.666667 42.666667H128c-25.6 0-42.666667-17.066667-42.666667-42.666667V298.666667c0-25.6 17.066667-42.666667 42.666667-42.666667h469.333333c25.6 0 42.666667 17.066667 42.666667 42.666667v426.666666z m298.666667-81.066666L755.2 512 938.666667 379.733333v264.533334z" p-id="5394" fill="#8a8a8a"></path></svg>;
var svg_recording_on = <svg t="1663505598640" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5644" width="32" height="32"><path d="M1002.666667 260.266667c-12.8-8.533333-29.866667-4.266667-42.666667 4.266666L725.333333 430.933333V298.666667c0-72.533333-55.466667-128-128-128H128C55.466667 170.666667 0 226.133333 0 298.666667v426.666666c0 72.533333 55.466667 128 128 128h469.333333c72.533333 0 128-55.466667 128-128v-132.266666l230.4 166.4c17.066667 12.8 46.933333 8.533333 59.733334-8.533334 4.266667-8.533333 8.533333-17.066667 8.533333-25.6V298.666667c0-17.066667-8.533333-29.866667-21.333333-38.4z" p-id="5645" fill="#2C8CFF"></path></svg>;
2021-03-29 15:59:14 +08:00
2021-05-02 21:19:48 +08:00
var cur_window_state = view.windowState;
function check_state_change() {
if (view.windowState != cur_window_state) {
stateChanged();
}
self.timer(30ms, check_state_change);
}
if (is_linux) {
check_state_change();
} else {
view << event statechange {
stateChanged();
}
}
2021-12-25 16:45:22 +08:00
function get_id() {
return handler.get_option('alias') || handler.get_id()
}
2021-05-02 21:19:48 +08:00
function stateChanged() {
stdout.println('state changed from ' + cur_window_state + ' -> ' + view.windowState);
cur_window_state = view.windowState;
2021-03-29 15:59:14 +08:00
adjustBorder();
adaptDisplay();
if (cur_window_state != View.WINDOW_MINIMIZED) {
view.focus = handler; // to make focus away from restore/maximize button, so that enter key work
}
2021-03-29 15:59:14 +08:00
var fs = view.windowState == View.WINDOW_FULL_SCREEN;
var el = $(#fullscreen);
if (el) el.attributes.toggleClass("active", fs);
el = $(#maximize);
if (el) {
el.state.disabled = fs;
}
2021-05-03 01:00:19 +08:00
if (fs) {
$(header).style.set {
display: "none",
};
}
2021-03-29 15:59:14 +08:00
}
var header;
var old_window_state = View.WINDOW_SHOWN;
2022-05-12 17:35:25 +08:00
var is_edit_os_password;
class EditOsPassword: Reactor.Component {
function render() {
return <span style="margin-left: 12px; padding: 0 6px; display: inline-block;" .link>{svg_edit}</span>;
}
function onMouse(evt) {
if (evt.type == Event.MOUSE_DOWN) {
is_edit_os_password = true;
editOSPassword();
}
}
}
function editOSPassword(login=false) {
var p0 = handler.get_option('os-password');
msgbox("custom-os-password", 'OS Password', p0, "", function(res=null) {
2022-05-12 17:35:25 +08:00
if (!res) return;
var a0 = handler.get_option('auto-login') != '';
var p = (res.password || '').trim();
var a = res.auto_login || false;
if (p == p0 && a == a0) return;
if (p != p0) handler.set_option('os-password', p);
if (a != a0) handler.set_option('auto-login', a ? 'Y' : '');
if (p && login) {
handler.input_os_password(p, true);
}
});
}
var recording = false;
2021-03-29 15:59:14 +08:00
class Header: Reactor.Component {
2022-05-12 17:35:25 +08:00
this var conn_note = "";
2021-12-25 16:45:22 +08:00
function this() {
2021-03-29 15:59:14 +08:00
header = this;
}
function render() {
var icon_conn;
var title_conn;
if (this.secure_connection && this.direct_connection) {
icon_conn = svg_secure;
2021-12-25 16:45:22 +08:00
title_conn = translate("Direct and encrypted connection");
2021-03-29 15:59:14 +08:00
} else if (this.secure_connection && !this.direct_connection) {
icon_conn = svg_secure_relay;
2021-12-25 16:45:22 +08:00
title_conn = translate("Relayed and encrypted connection");
2021-03-29 15:59:14 +08:00
} else if (!this.secure_connection && this.direct_connection) {
icon_conn = svg_insecure;
2021-12-25 16:45:22 +08:00
title_conn = translate("Direct and unencrypted connection");
2021-03-29 15:59:14 +08:00
} else {
icon_conn = svg_insecure_relay;
2021-12-25 16:45:22 +08:00
title_conn = translate("Relayed and unencrypted connection");
2021-03-29 15:59:14 +08:00
}
2021-12-25 16:45:22 +08:00
var title = get_id();
2021-03-29 15:59:14 +08:00
if (pi.hostname) title += "(" + pi.username + "@" + pi.hostname + ")";
if ((pi.displays || []).length == 0) {
2022-02-08 13:58:42 +08:00
return <div .ellipsis style="size:*;text-align:center;margin:* 0;">{title}</div>;
2021-03-29 15:59:14 +08:00
}
var screens = pi.displays.map(function(d, i) {
return <div #screen class={pi.current_display == i ? "current" : ""}>
{i+1}
</div>;
});
updateWindowToolbarPosition();
2021-12-25 16:45:22 +08:00
var style = "flow:horizontal;";
if (is_osx) style += "margin:*";
self.timer(1ms, updatePrivacyMode);
2021-03-29 15:59:14 +08:00
self.timer(1ms, toggleMenuState);
return <div style={style}>
2021-05-02 22:55:50 +08:00
{is_osx || is_xfce ? "" : <span #fullscreen>{svg_fullscreen}</span>}
2021-03-29 15:59:14 +08:00
<div #screens>
<span #secure title={title_conn}>{icon_conn}</span>
2021-12-25 16:45:22 +08:00
<div .remote-id>{get_id()}</div>
2021-03-29 15:59:14 +08:00
<div style="flow:horizontal;border-spacing: 0.5em;">{screens}</div>
{this.renderGlobalScreens()}
</div>
<span #chat>{svg_chat}</span>
<span #action>{svg_action}</span>
<span #display>{svg_display}</span>
2022-07-23 20:51:01 +08:00
<span #keyboard>{svg_keyboard}</span>
{recording_enabled ? <span #recording>{recording ? svg_recording_on : svg_recording_off}</span> : ""}
2022-07-23 20:51:01 +08:00
{this.renderKeyboardPop()}
2021-03-29 15:59:14 +08:00
{this.renderDisplayPop()}
{this.renderActionPop()}
</div>;
}
2022-07-23 20:51:01 +08:00
function renderKeyboardPop(){
return <popup>
<menu.context #keyboard-options>
<li #legacy><span>{svg_checkmark}</span>{translate('Legacy mode')}</li>
<li #map><span>{svg_checkmark}</span>{translate('Map mode')}</li>
</menu>
</popup>;
}
2021-03-29 15:59:14 +08:00
function renderDisplayPop() {
var codecs = handler.supported_hwcodec();
var show_codec = handler.has_hwcodec() && (codecs[0] || codecs[1]);
var cursor_embedded = false;
if ((pi.displays || []).length > 0) {
if (pi.displays.length > pi.current_display) {
cursor_embedded = pi.displays[pi.current_display].cursor_embedded;
}
}
2021-03-29 15:59:14 +08:00
return <popup>
<menu.context #display-options>
2021-12-25 16:45:22 +08:00
<li #adjust-window style="display:none">{translate('Adjust Window')}</li>
2021-03-29 15:59:14 +08:00
<div #adjust-window .separator style="display:none"/>
2021-12-25 16:45:22 +08:00
<li #original type="view-style"><span>{svg_checkmark}</span>{translate('Original')}</li>
<li #shrink type="view-style"><span>{svg_checkmark}</span>{translate('Shrink')}</li>
<li #stretch type="view-style"><span>{svg_checkmark}</span>{translate('Stretch')}</li>
2021-03-29 15:59:14 +08:00
<div .separator />
2021-12-25 16:45:22 +08:00
<li #best type="image-quality"><span>{svg_checkmark}</span>{translate('Good image quality')}</li>
<li #balanced type="image-quality"><span>{svg_checkmark}</span>{translate('Balanced')}</li>
<li #low type="image-quality"><span>{svg_checkmark}</span>{translate('Optimize reaction time')}</li>
<li #custom type="image-quality"><span>{svg_checkmark}</span>{translate('Custom')}</li>
{show_codec ? <div>
<div .separator />
<li #auto type="codec-preference"><span>{svg_checkmark}</span>Auto</li>
<li #vp9 type="codec-preference"><span>{svg_checkmark}</span>VP9</li>
{codecs[0] ? <li #h264 type="codec-preference"><span>{svg_checkmark}</span>H264</li> : ""}
{codecs[1] ? <li #h265 type="codec-preference"><span>{svg_checkmark}</span>H265</li> : ""}
</div> : ""}
2021-03-29 15:59:14 +08:00
<div .separator />
{!cursor_embedded && <li #show-remote-cursor .toggle-option><span>{svg_checkmark}</span>{translate('Show remote cursor')}</li>}
2022-06-23 17:42:30 +08:00
<li #show-quality-monitor .toggle-option><span>{svg_checkmark}</span>{translate('Show quality monitor')}</li>
2021-12-25 16:45:22 +08:00
{audio_enabled ? <li #disable-audio .toggle-option><span>{svg_checkmark}</span>{translate('Mute')}</li> : ""}
{is_win && pi.platform == 'Windows' && file_enabled ? <li #enable-file-transfer .toggle-option><span>{svg_checkmark}</span>{translate('Allow file copy and paste')}</li> : ""}
2021-12-25 16:45:22 +08:00
{keyboard_enabled && clipboard_enabled ? <li #disable-clipboard .toggle-option><span>{svg_checkmark}</span>{translate('Disable clipboard')}</li> : ""}
{keyboard_enabled ? <li #lock-after-session-end .toggle-option><span>{svg_checkmark}</span>{translate('Lock after session end')}</li> : ""}
{keyboard_enabled && pi.platform == "Windows" ? <li #privacy-mode><span>{svg_checkmark}</span>{translate('Privacy mode')}</li> : ""}
2023-02-25 10:41:02 +08:00
{keyboard_enabled && ((is_osx && pi.platform != "Mac OS") || (!is_osx && pi.platform == "Mac OS")) ? <li #allow_swap_key .toggle-option><span>{svg_checkmark}</span>{translate('Swap control-command key')}</li> : ""}
2021-03-29 15:59:14 +08:00
</menu>
</popup>;
}
function renderActionPop() {
return <popup>
<menu.context #action-options>
2022-05-12 17:35:25 +08:00
{keyboard_enabled ? <li #os-password>{translate('OS Password')}<EditOsPassword /></li> : ""}
2021-12-25 16:45:22 +08:00
<li #transfer-file>{translate('Transfer File')}</li>
<li #tunnel>{translate('TCP Tunneling')}</li>
{handler.get_audit_server("conn") && <li #note>{translate('Note')}</li>}
<div .separator />
2021-12-25 16:45:22 +08:00
{keyboard_enabled && (pi.platform == "Linux" || pi.sas_enabled) ? <li #ctrl-alt-del>{translate('Insert')} Ctrl + Alt + Del</li> : ""}
{restart_enabled && (pi.platform == "Linux" || pi.platform == "Windows" || pi.platform == "Mac OS") ? <li #restart_remote_device>{translate('Restart Remote Device')}</li> : ""}
2021-12-25 16:45:22 +08:00
{keyboard_enabled ? <li #lock-screen>{translate('Insert Lock')}</li> : ""}
{keyboard_enabled && pi.platform == "Windows" && pi.sas_enabled ? <li #block-input>{translate("Block user input")}</li> : ""}
2022-02-10 11:32:16 +08:00
<li #refresh>{translate('Refresh')}</li>
2021-03-29 15:59:14 +08:00
</menu>
</popup>;
}
function renderGlobalScreens() {
2021-12-25 16:45:22 +08:00
if (pi.displays.length < 3) return "";
2021-03-29 15:59:14 +08:00
var x0 = 9999999;
var y0 = 9999999;
var x = -9999999;
var y = -9999999;
pi.displays.map(function(d, i) {
if (d.x < x0) x0 = d.x;
if (d.y < y0) y0 = d.y;
var dx = d.x + d.width;
if (dx > x) x = dx;
var dy = d.y + d.height;
if (dy > y) y = dy;
});
var w = x - x0;
var h = y - y0;
var scale = 16. / h;
var screens = pi.displays.map(function(d, i) {
var min_wh = d.width > d.height ? d.height : d.width;
2021-07-26 01:50:47 +08:00
var fs = min_wh * 0.9 * scale;
2021-03-29 15:59:14 +08:00
var style = "width:" + (d.width * scale) + "px;" +
"height:" + (d.height * scale) + "px;" +
"left:" + ((d.x - x0) * scale) + "px;" +
"top:" + ((d.y - y0) * scale) + "px;" +
2021-07-26 01:50:47 +08:00
"font-size:" + fs + "px;";
if (is_osx) {
style += "line-height:" + fs + "px;";
}
2021-03-29 15:59:14 +08:00
return <div style={style} class={pi.current_display == i ? "current" : ""}>{i+1}</div>;
});
var style = "width:" + (w * scale) + "px; height:" + (h * scale) + "px;";
return <div #global-screens style={style}>
{screens}
</div>;
}
event click $(#fullscreen) (_, el) {
if (view.windowState == View.WINDOW_FULL_SCREEN) {
if (old_window_state == View.WINDOW_MAXIMIZED) {
view.windowState = View.WINDOW_SHOWN;
}
view.windowState = old_window_state;
} else {
old_window_state = view.windowState;
if (view.windowState == View.WINDOW_MAXIMIZED) {
view.windowState = View.WINDOW_SHOWN;
}
view.windowState = View.WINDOW_FULL_SCREEN;
2021-05-03 00:50:50 +08:00
if (is_linux) { self.timer(150ms, function() { view.windowState = View.WINDOW_FULL_SCREEN; }); }
2021-03-29 15:59:14 +08:00
}
}
event click $(#chat) {
startChat();
}
event click $(#action) (_, me) {
var menu = $(menu#action-options);
me.popup(menu);
}
event click $(#display) (_, me) {
var menu = $(menu#display-options);
me.popup(menu);
}
2022-07-23 20:51:01 +08:00
event click $(#keyboard) (_, me) {
var menu = $(menu#keyboard-options);
me.popup(menu);
}
event click $(span#recording) (_, me) {
recording = !recording;
header.update();
if (recording)
handler.refresh_video();
else
handler.record_screen(false, display_width, display_height);
}
2021-03-29 15:59:14 +08:00
event click $(#screen) (_, me) {
if (pi.current_display == me.index) return;
handler.switch_display(me.index);
}
event click $(#transfer-file) {
handler.transfer_file();
}
2022-05-12 17:35:25 +08:00
event click $(#os-password) (evt) {
if (is_edit_os_password) {
is_edit_os_password = false;
return;
}
var p = handler.get_option('os-password');
if (!p) editOSPassword(true);
else handler.input_os_password(p, true);
}
2021-03-29 15:59:14 +08:00
event click $(#tunnel) {
handler.tunnel();
}
2022-05-12 17:35:25 +08:00
event click $(#note) {
var self = this;
msgbox("custom", "Note", <div .form>
<textarea .outline-focus spellcheck="false" name="text" novalue="input note here" style="overflow: scroll-indicator; width:*; height: 140px; font-size: 1.2em; padding: 0.5em;">{self.conn_note}</textarea>
</div>, "", function(res=null) {
2022-05-12 17:35:25 +08:00
if (!res) return;
if (!res.text) return;
self.conn_note = res.text;
handler.send_note(res.text);
}, 280);
}
2021-03-29 15:59:14 +08:00
event click $(#ctrl-alt-del) {
handler.ctrl_alt_del();
}
2022-01-15 02:16:00 +08:00
event click $(#restart_remote_device) {
msgbox(
"restart-confirmation",
translate("Restart Remote Device"),
translate("Are you sure you want to restart") + " " + pi.username + "@" + pi.hostname + "(" + get_id() + ") ?",
"",
function(res=null) {
if (res != null) handler.restart_remote_device();
}
);
}
2021-03-29 15:59:14 +08:00
event click $(#lock-screen) {
handler.lock_screen();
}
event click $(#refresh) {
handler.refresh_video();
}
event click $(#block-input) {
if (!input_blocked) {
handler.toggle_option("block-input");
input_blocked = true;
2022-01-15 18:27:15 +08:00
$(#block-input).text = translate("Unblock user input");
2021-03-29 15:59:14 +08:00
} else {
handler.toggle_option("unblock-input");
input_blocked = false;
2022-01-15 18:27:15 +08:00
$(#block-input).text = translate("Block user input");
2021-03-29 15:59:14 +08:00
}
}
event click $(menu#display-options li) (_, me) {
2021-03-29 15:59:14 +08:00
if (me.id == "custom") {
handle_custom_image_quality();
} else if (me.id == "privacy-mode") {
togglePrivacyMode(me.id);
2022-06-23 17:42:30 +08:00
} else if (me.id == "show-quality-monitor") {
toggleQualityMonitor(me.id);
2023-01-30 23:42:38 +08:00
} else if (me.attributes.hasClass("toggle-option")) {
2021-03-29 15:59:14 +08:00
handler.toggle_option(me.id);
toggleMenuState();
} else if (!me.attributes.hasClass("selected")) {
var type = me.attributes["type"];
if (type == "image-quality") {
handler.save_image_quality(me.id);
} else if (type == "view-style") {
handler.save_view_style(me.id);
adaptDisplay();
} else if (type == "codec-preference") {
handler.set_option("codec-preference", me.id);
handler.change_prefer_codec();
2021-03-29 15:59:14 +08:00
}
toggleMenuState();
}
}
2022-07-23 20:51:01 +08:00
event click $(menu#keyboard-options>li) (_, me) {
if (me.id == "legacy") {
handler.save_keyboard_mode("legacy");
} else if (me.id == "map") {
handler.save_keyboard_mode("map");
2022-08-03 14:34:05 +08:00
} else if (me.id == "translate") {
handler.save_keyboard_mode("translate");
2022-07-23 20:51:01 +08:00
}
toggleMenuState()
}
2021-03-29 15:59:14 +08:00
}
function handle_custom_image_quality() {
2022-06-27 21:23:14 +08:00
var tmp = handler.get_custom_image_quality();
2022-06-27 22:24:56 +08:00
var bitrate = (tmp[0] || 50);
2021-12-29 11:42:43 +08:00
msgbox("custom", "Custom Image Quality", "<div .form> \
2022-06-23 17:42:30 +08:00
<div><input type=\"hslider\" style=\"width: 50%\" name=\"bitrate\" max=\"100\" min=\"10\" value=\"" + bitrate + "\"/ buddy=\"bitrate-buddy\"><b #bitrate-buddy>x</b>% Bitrate</div> \
</div>", "", function(res=null) {
2021-03-29 15:59:14 +08:00
if (!res) return;
if (!res.bitrate) return;
2022-06-27 22:24:56 +08:00
handler.save_custom_image_quality(res.bitrate);
2021-03-29 15:59:14 +08:00
toggleMenuState();
});
}
function toggleMenuState() {
var values = [];
var q = handler.get_image_quality();
if (!q) q = "balanced";
values.push(q);
var s = handler.get_view_style();
if (!s) s = "original";
values.push(s);
2022-07-23 20:51:01 +08:00
var k = handler.get_keyboard_mode();
values.push(k);
var c = handler.get_option("codec-preference");
if (!c) c = "auto";
values.push(c);
for (var el in $$(menu#display-options li)) {
2021-03-29 15:59:14 +08:00
el.attributes.toggleClass("selected", values.indexOf(el.id) >= 0);
}
2022-07-23 20:51:01 +08:00
for (var el in $$(menu#keyboard-options>li)) {
el.attributes.toggleClass("selected", values.indexOf(el.id) >= 0);
}
2023-02-25 10:41:02 +08:00
for (var id in ["show-remote-cursor", "show-quality-monitor", "disable-audio", "enable-file-transfer", "disable-clipboard", "lock-after-session-end", "allow_swap_key"]) {
2021-03-29 15:59:14 +08:00
var el = self.select('#' + id);
if (el) {
2022-01-15 18:27:15 +08:00
var value = handler.get_toggle_option(id);
el.attributes.toggleClass("selected", value);
2021-03-29 15:59:14 +08:00
}
}
}
if (is_osx) {
$(header).content(<Header />);
$(header).attributes["role"] = "window-caption";
} else {
if (is_file_transfer || is_port_forward) {
$(caption).content(<Header />);
} else {
$(div.window-toolbar).content(<Header />);
}
setWindowButontsAndIcon();
}
if (!(is_file_transfer || is_port_forward)) {
$(header).style.set {
height: "32px",
};
if (!is_osx) {
$(div.window-icon).style.set {
size: "32px",
};
}
}
handler.updatePi = function(v) {
pi = v;
header.update();
if (is_port_forward) {
view.windowState = View.WINDOW_MINIMIZED;
}
}
handler.updateDisplays = function(v) {
pi.displays = v;
header.update();
if (is_port_forward) {
view.windowState = View.WINDOW_MINIMIZED;
}
}
function updatePrivacyMode() {
var el = $(li#privacy-mode);
if (el) {
var supported = handler.is_privacy_mode_supported();
if (!supported) {
// el.attributes.toggleClass("line-through", true);
el.style["display"]="none";
} else {
var value = handler.get_toggle_option("privacy-mode");
el.attributes.toggleClass("selected", value);
var el = $(li#block-input);
if (el) {
el.state.disabled = value;
}
}
}
}
handler.updatePrivacyMode = updatePrivacyMode;
function togglePrivacyMode(privacy_id) {
var supported = handler.is_privacy_mode_supported();
if (!supported) {
msgbox("nocancel", translate("Privacy mode"), translate("Unsupported"), "", function() { });
} else {
handler.toggle_option(privacy_id);
}
}
2022-06-23 17:42:30 +08:00
function toggleQualityMonitor(name) {
var show = handler.get_toggle_option(name);
if (show) {
$(#quality-monitor).style.set{ display: "none" };
} else {
$(#quality-monitor).style.set{ display: "block" };
}
handler.toggle_option(name);
toggleMenuState();
}
handler.updateBlockInputState = function(input_blocked) {
if (!input_blocked) {
handler.toggle_option("block-input");
input_blocked = true;
$(#block-input).text = translate("Unblock user input");
} else {
handler.toggle_option("unblock-input");
input_blocked = false;
$(#block-input).text = translate("Block user input");
}
}
2021-03-29 15:59:14 +08:00
handler.switchDisplay = function(i) {
pi.current_display = i;
header.update();
}
function updateWindowToolbarPosition() {
if (is_osx) return;
self.timer(1ms, function() {
var el = $(div.window-toolbar);
var w1 = el.box(#width, #border);
var w2 = $(header).box(#width, #border);
2022-05-12 17:35:25 +08:00
var x = (w2 - w1) / 2 / scaleFactor;
2021-03-29 15:59:14 +08:00
el.style.set {
left: x + "px",
display: "block",
};
});
}
view.on("size", function() {
// ensure size is done, so add timer
self.timer(1ms, function() {
updateWindowToolbarPosition();
adaptDisplay();
});
});
handler.newMessage = function(text) {
chat_msgs.push({text: text, name: pi.username || "", time: getNowStr()});
startChat();
}
function sendMsg(text) {
chat_msgs.push({text: text, name: "me", time: getNowStr()});
handler.send_chat(text);
if (chatbox) chatbox.refresh();
}
var chatbox;
function startChat() {
if (chatbox) {
chatbox.windowState = View.WINDOW_SHOWN;
chatbox.refresh();
return;
}
var icon = handler.get_icon();
var (sx, sy, sw, sh) = view.screenBox(#workarea, #rectw);
2022-05-12 17:35:25 +08:00
var w = scaleIt(300);
var h = scaleIt(400);
2021-03-29 15:59:14 +08:00
var x = (sx + sw - w) / 2;
2022-05-12 17:35:25 +08:00
var y = sy + scaleIt(80);
2021-03-29 15:59:14 +08:00
var params = {
type: View.FRAME_WINDOW,
x: x,
y: y,
width: w,
height: h,
client: true,
parameters: { msgs: chat_msgs, callback: sendMsg, icon: icon },
2021-12-27 02:28:25 +08:00
caption: get_id(),
2021-03-29 15:59:14 +08:00
};
var html = handler.get_chatbox();
if (html) params.html = html;
else params.url = self.url("chatbox.html");
chatbox = view.window(params);
}
handler.setConnectionType = function(secured, direct) {
header.update({
secure_connection: secured,
direct_connection: direct,
});
}