var svg_tile = ; var svg_list = ; var search_icon = ; var clear_icon = ; function getSessionsStyleOption(type) { return (type || "recent") + "-sessions-style"; } function getSessionsStyle(type) { var v = handler.get_local_option(getSessionsStyleOption(type)); if (!v) v = type == "ab" ? "list" : "tile"; return v; } var searchPatterns = {}; var current_menu_peer_id = ''; class SearchBar: Reactor.Component { this var type = ""; function this(params) { this.type = (params || {}).type || ""; } function render() { var value = searchPatterns[this.type] || ""; var me = this; self.timer(1ms, function() { (me.search_id || {}).value = value; }); return
{search_icon} {value && {clear_icon}}
; } event click $(span.clear-input) { this.onChange(''); } event change $(input) (_, el) { this.onChange(el.value.trim()); } function onChange(v) { searchPatterns[this.type] = v; app.multipleSessions.update(); } } class SessionStyle: Reactor.Component { this var type = ""; function this(params) { this.type = (params || {}).type || ""; } function render() { var sessionsStyle = getSessionsStyle(this.type); return
{svg_tile} {svg_list}
; } event click $(span.inactive) { var option = getSessionsStyleOption(this.type); var sessionsStyle = getSessionsStyle(this.type); handler.set_local_option(option, sessionsStyle == "tile" ? "list" : "tile"); app.multipleSessions.update(); } } class SessionList: Reactor.Component { this var sessions = []; this var type = ""; this var style; function this(params) { this.sessions = params.sessions; this.type = params.type || ""; this.style = getSessionsStyle(this.type); } function getSessions() { var p = searchPatterns[this.type]; if (!p) return this.sessions; var tmp = []; this.sessions.map(function(s) { var name = s[4] || s.alias || s[0] || s.id || ""; if (name.indexOf(p) >= 0) tmp.push(s); }); return tmp; } function render() { var sessions = this.getSessions(); if (sessions.length == 0) { return
{translate("Empty")}
; } var me = this; sessions = sessions.map(function(x) { return me.getSession(x); }); return
  • {translate('Connect')}
  • {translate('Transfer File')}
  • {translate('TCP Tunneling')}
  • RDP
  • {translate('Rename')}
  • {this.type != "fav" && this.type != "lan" &&
  • {translate('Remove')}
  • } {is_win &&
  • {translate('Create Desktop Shortcut')}
  • }
  • {translate('Unremember Password')}
  • {(!this.type || this.type == "fav") &&
  • {translate('Add to Favorites')}
  • } {(!this.type || this.type == "fav") &&
  • {translate('Remove from Favorites')}
  • } {sessions}
    ; } function getSession(s) { var id = s[0] || s.id || ""; var username = s[1] || s.username || ""; var hostname = s[2] || s.hostname || ""; var platform = s[3] || s.platform || ""; var alias = s[4] || s.alias || ""; if (this.style == "list") { return
    {platform && platformSvg(platform, "white")}
    {alias ? alias : formatId(id)}
    {username}@{hostname}
    {svg_menu}
    ; } return
    {platform && platformSvg(platform, "white")}
    {username}@{hostname}
    {alias ? alias : formatId(id)}
    {svg_menu}
    ; } event dblclick $(div.remote-session-link) (evt, me) { createNewConnect(me.id, "connect"); } event click $(#menu) (_, me) { var id = me.parent.parent.id; var platform = me.parent.parent.attributes["platform"]; this.$(#rdp).style.set{ display: (platform == "Windows" && is_win) ? "block" : "none", }; this.$(#forget-password).style.set{ display: handler.peer_has_password(id) ? "block" : "none", }; if (!this.type || this.type == "fav") { var in_fav = handler.get_fav().indexOf(id) >= 0; this.$(#add-fav).style.set{ display: in_fav ? "none" : "block", }; this.$(#remove-fav).style.set{ display: in_fav ? "block" : "none", }; } // https://sciter.com/forums/topic/replacecustomize-context-menu/ var menu = this.$(menu#remote-context); current_menu_peer_id = id; var conn = this.$(menu #connect); if (conn) { var alias = me.parent.parent.$(#alias); if (alias) { alias = alias.text.replace(' ', ''); if (alias != id) { conn.text = translate('Connect') + ' ' + id; } else { conn.text = translate('Connect'); } } } me.popup(menu); } event click $(menu#remote-context li) (evt, me) { var action = me.id; var id = current_menu_peer_id; if (action == "connect") { createNewConnect(id, "connect"); } else if (action == "transfer") { createNewConnect(id, "file-transfer"); } else if (action == "remove") { if (!this.type) { handler.remove_peer(id); app.update(); } } else if (action == "forget-password") { handler.forget_password(id); } else if (action == "shortcut") { handler.create_shortcut(id); } else if (action == "rdp") { createNewConnect(id, "rdp"); } else if (action == "add-fav") { var favs = handler.get_fav(); if (favs.indexOf(id) < 0) { favs = [id].concat(favs); handler.store_fav(favs); } app.multipleSessions.update(); app.update(); } else if (action == "remove-fav") { var favs = handler.get_fav(); var i = favs.indexOf(id); favs.splice(i, 1); handler.store_fav(favs); app.multipleSessions.update(); } else if (action == "tunnel") { createNewConnect(id, "port-forward"); } else if (action == "rename") { var old_name = handler.get_peer_option(id, "alias"); msgbox("custom-rename", "Rename", "
    \
    \
    \ ", function(res=null) { if (!res) return; var name = (res.name || "").trim(); if (name != old_name) { handler.set_peer_option(id, "alias", name); } app.update(); }); } } } function getSessionsType() { return handler.get_local_option("show-sessions-type"); } class Favorites: Reactor.Component { function render() { var sessions = handler.get_fav().map(function(f) { return handler.get_peer(f); }); return ; } } class MultipleSessions: Reactor.Component { function render() { var type = getSessionsType(); return
    {translate('Recent Sessions')} {translate('Favorites')} {handler.is_installed() && {translate('Discovered')}}
    {!this.hidden && } {!this.hidden && }
    {!this.hidden && ((type == "fav" && ) || (type == "lan" && handler.is_installed() && ) || )}
    ; } function stupidUpdate() { /* hidden is workaround of stupid sciter bug */ this.hidden = true; this.update(); var me = this; self.timer(60ms, function() { me.hidden = false; me.update(); self.timer(30ms, function() { me.onSize(); }); }); } event click $(div#sessions-type span.inactive) (_, el) { if (el.id == "lan") { discover(); } handler.set_local_option('show-sessions-type', el.id || ""); this.stupidUpdate(); } function onSize() { var w = this.$(.sessions-bar .sessions-tab).box(#width); var len = translate('Recent Sessions').length; var totalChars = 0; var nEle = 0; for (var el in this.$$(#sessions-type span)) { nEle += 1; totalChars += el.text.length; } for (var el in this.$$(#sessions-type span)) { var maxWidth = (w - nEle * 2 * 8) * el.text.length / totalChars; if (maxWidth < 0) maxWidth = 36; el.style.set{ "max-width": maxWidth + "px", }; } } } function discover() { handler.discover(); var tries = 15; function update() { self.timer(300ms, function() { tries -= 1; if (tries == 0) return; update(); var p = (app || {}).multipleSessions; if (p) { p.update(); } }); } update(); } if (getSessionsType() == "lan" && handler.is_installed()) { discover(); } class LanPeers: Reactor.Component { function render() { var sessions = []; try { sessions = JSON.parse(handler.get_lan_peers()); } catch (_) {} return ; } } view.on("size", function() { if (app && app.multipleSessions) app.multipleSessions.onSize(); });