import { handler, string2RGB, platformSvg, msgbox,translate } from "./common.js"; import { app, formatId, createNewConnect,svg_menu } from "./index.js"; // TODO check app obj // TODO transform const svg_tile = ; const svg_list = ; const search_icon = ; const clear_icon = ; function getSessionsStyleOption(type) { return (type || "recent") + "-sessions-style"; } export function getSessionsStyle(type) { var v = handler.xcall("get_local_option",getSessionsStyleOption(type)); if (!v) v = type == "ab" ? "list" : "tile"; return v; } // Fixed // function stupidUpdate(me) { // /* hidden is workaround of stupid sciter bug */ // me.hidden = true; // me.update(); // self.timer(60ms, function() { // me.hidden = false; // me.update(); // }); // } export class SearchBar extends Element { parent; value = ""; this(props) { this.parent = props.parent; } render() { // TODO @{this.search_id} TIS: return (
{search_icon} {this.value && {clear_icon}}
); } ["on click at span.clear-input"](_) { this.search_id.value = ''; this.onChange(''); } // TODO TEST params ["on change at input"](_, el) { this.onChange(el.value.trim()); } onChange(v) { this.value = v; this.update(); // TODO update() this.parent.filter(v); } } export class SessionStyle extends Element { type = ""; this(props) { this.type = (props || {}).type; } render() { let sessionsStyle = getSessionsStyle(this.type); return (
{svg_tile} {svg_list}
); } ["on click at span.inactive"](_) { let option = getSessionsStyleOption(this.type); let sessionsStyle = getSessionsStyle(this.type); handler.xcall("set_option", option, sessionsStyle == "tile" ? "list" : "tile"); //stupidUpdate(app); // seems fixed in new sciter app.update(); } } export class SessionList extends Element { sessions = []; type = ""; style; filterPattern = ""; this(props) { this.sessions = props.sessions; this.type = props.type; this.style = getSessionsStyle(props.type); } filter(v) { this.filterPattern = v; this.update(); // TODO update } getSessions() { let p = this.filterPattern; if (!p) return this.sessions; let tmp = []; this.sessions.map(function (s) { let name = s[4] || s.alias || s[0] || s.id || ""; if (name.indexOf(p) >= 0) tmp.push(s); }); return tmp; } render() { let sessions = this.getSessions(); if (!sessions || sessions.length == 0) return ; // TODO property 'length' of undefined sessions = sessions.map((x) => this.getSession(x)); // TODO is_win return
  • {translate('Connect')}
  • {translate('Transfer File')}
  • {translate('TCP Tunneling')}
  • RDP
  • {translate('Rename')}
  • {translate('Remove')}
  • {is_win &&
  • {translate('Create Desktop Shortcut')}
  • }
    {sessions}
    ; } getSession(s) { let id = s[0] || s.id || ""; let username = s[1] || s.username || ""; let hostname = s[2] || s.hostname || ""; let platform = s[3] || s.platform || ""; let alias = s[4] || s.alias || ""; if (this.style == "list") { return (); } return (); } // TEST dbclick ["on dbclick at div.remote-session-link"](evt, me) { createNewConnect(me.id, "connect"); } // TODO #menu ["on click at #menu"](_, me) { let id = me.parent.parent.id; let platform = me.parent.parent.attributes["platform"]; // TODO attributes["platform"] this.$("#rdp").style.setProperty("display", (platform == "Windows" && is_win) ? "block" : "none"); // https://sciter.com/forums/topic/replacecustomize-context-menu/ let menu = this.$("menu#remote-context"); menu.attributes["remote-id"] = id; // // TODO attributes["remote-id"] me.popup(menu); } // TODO li ["on click at menu#remote-context li"](evt, me) { let action = me.id; let id = me.parent.attributes["remote-id"]; if (action == "connect") { createNewConnect(id, "connect"); } else if (action == "transfer") { createNewConnect(id, "file-transfer"); } else if (action == "remove") { if (!this.type) { handler.xcall("remove_peer", id); app.update(); // TODO app.update() } } else if (action == "forget-password") { handler.forget_password(id); } else if (action == "shortcut") { handler.xcall("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") { let old_name = handler.xcall("get_peer_option", id, "alias"); msgbox("custom-rename", "Rename", "
    \
    \
    \ ", function (res = null) { if (!res) return; let name = (res.name || "").trim(); if (name != old_name) { handler.xcall("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')}
    {!this.hidden && } {!this.hidden && }
    {!this.hidden && ((type == "fav" && ) || )}
    ; } 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(); }); } event click $(div#sessions-type span.inactive) (_, el) { handler.set_option('show-sessions-type', el.id || ""); this.stupidUpdate(); } function onSize() { var w = this.$(.sessions-bar).box(#width) - 220; this.$(#sessions-type span).style.set{ "max-width": (w / 2) + "px", }; } } view.on("size", function() { if (app && app.multipleSessions) app.multipleSessions.onSize(); });