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;
}
function stupidUpdate(me) {
/* hidden is workaround of stupid sciter bug */
me.hidden = true;
me.update();
self.timer(60ms, function() {
me.hidden = false;
me.update();
});
}
class SearchBar: Reactor.Component {
this var parent;
this var value = "";
function this(params) {
this.parent = params.parent;
}
function render() {
return
{search_icon}
{this.value && {clear_icon}}
;
}
event click $(span.clear-input) {
this.search_id.value = '';
this.onChange('');
}
event change $(input) (_, el) {
this.onChange(el.value.trim());
}
function onChange(v) {
this.value = v;
this.update();
this.parent.filter(v);
}
}
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_option(option, sessionsStyle == "tile" ? "list" : "tile");
//stupidUpdate(app); // seems fixed in new sciter
app.update();
}
}
class SessionList: Reactor.Component {
this var sessions = [];
this var type = "";
this var style;
this var filterPattern = "";
function this(params) {
this.sessions = params.sessions;
this.type = params.type;
this.style = getSessionsStyle(params.type);
}
function filter(v) {
this.filterPattern = v;
this.update();
}
function getSessions() {
var p = this.filterPattern;
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 ;
var me = this;
sessions = sessions.map(function(x) { return me.getSession(x); });
return
{translate('Connect')}
{translate('Transfer File')}
{translate('TCP Tunneling')}
RDP
{translate('Rename')}
{translate('Remove')}
{is_win &&
{translate('Create Desktop Shortcut')}
}
{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
{platformSvg(platform, "white")}
{alias ? alias : formatId(id)}
{username}@{hostname}
{svg_menu}
;
}
return
{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"];
$(#rdp).style.set{
display: (platform == "Windows" && is_win) ? "block" : "none",
};
// https://sciter.com/forums/topic/replacecustomize-context-menu/
var menu = this.$(menu#remote-context);
menu.attributes["remote-id"] = id;
me.popup(menu);
}
event click $(menu#remote-context li) (evt, me) {
var action = me.id;
var 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.remove_peer(id);
app.update();
}
} else if (action == "shortcut") {
handler.create_shortcut(id);
} else if (action == "rdp") {
createNewConnect(id, "rdp");
} 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();
});
}
}
}