`)}_updatePeers(){let e=G,{elements:t,torrents:r}=this,{tbody:o}=t.peers,n=[(a,l)=>{l.dataset.encrypted=a.isEncrypted},(a,l)=>h(l,a.rateToPeer?e.speedBps(a.rateToPeer):""),(a,l)=>h(l,a.rateToClient?e.speedBps(a.rateToClient):""),(a,l)=>h(l,`${Math.floor(a.progress*100)}%`),(a,l)=>{h(l,a.flagStr),l.setAttribute("title",s._peerStatusTitle(a.flagStr))},(a,l)=>{h(l,a.address),l.setAttribute("title",a.address)},(a,l)=>{h(l,a.clientName),l.setAttribute("title",a.clientName)}],i=[];for(let a of r){let l=document.createElement("tr");l.classList.add("torrent-row");let c=document.createElement("td");c.setAttribute("colspan",n.length),h(c,a.getName()),l.append(c),i.push(l);for(let u of a.getPeers()){let g=document.createElement("tr");g.classList.add("peer-row");for(let[d,p]of n.entries()){let b=document.createElement("td");b.classList.add(Yt[d]),p(u,b),g.append(b)}i.push(g)}for(;o.firstChild;)o.firstChild.remove();o.append(...i)}}static getAnnounceState(e){switch(e.announceState){case f._TrackerActive:return"Announce in progress";case f._TrackerWaiting:{let t=Math.max(0,e.nextAnnounceTime-Date.now()/1e3);return`Nextannouncein${G.timeInterval(t)}`}case f._TrackerQueued:return"Announce is queued";case f._TrackerInactive:return e.isBackup?"Tracker will be used as a backup":"Announce not scheduled";default:return`unknownannouncestate:${e.announceState}`}}static lastAnnounceStatus(e){let t="Last Announce",r=["N/A"];if(e.hasAnnounced){let o=G.timestamp(e.lastAnnounceTime);e.lastAnnounceSucceeded?r=[o," (got ",G.countString("peer","peers",e.lastAnnouncePeerCount),")"]:(t="Announce error",r=[e.lastAnnounceResult?`${e.lastAnnounceResult}-`:"",o])}return{label:t,value:r.join("")}}static lastScrapeStatus(e){let t="Last Scrape",r="N/A";if(e.hasScraped){let o=G.timestamp(e.lastScrapeTime);e.lastScrapeSucceeded?r=o:(t="Scrape error",r=(e.lastScrapeResult?`${e.lastScrapeResult}-`:"")+o)}return{label:t,value:r}}static _getOrigin(e){try{let t="udp://";if(e.announce.startsWith(t)){let o="http://",n=e.announce.replace(t,o);return new URL(n).origin.replace(o,t)}return new URL(e.announce).origin}catch{return[e.sitename||e.host||e.announce]}}_updateTiers(){let e="N/A",{list:t}=this.elements.tiers,{torrents:r}=this,o=[];for(let n of r){if(r.length>1){let i=document.createElement("div");i.classList.add("tier-list-torrent"),h(i,n.getName()),o.push(i)}for(let i of n.getTrackers()){let a=s.getAnnounceState(i),l=s.lastAnnounceStatus(i),c=s.lastScrapeStatus(i),u=document.createElement("div");u.classList.add("tier-list-row");let g=document.createElement("div"),d=s._getOrigin(i);g.classList.add("tier-list-tracker"),h(g,`${d}-tier${i.tier+1}`),g.setAttribute("title",i.announce),u.append(g),g=document.createElement("div"),g.classList.add("tier-announce"),h(g,`${l.label}:${l.value}`),u.append(g),g=document.createElement("div"),g.classList.add("tier-seeders"),h(g,`Seeders:${i.seederCount>-1?i.seederCount:e}`),u.append(g),g=document.createElement("div"),g.classList.add("tier-state"),h(g,a),u.append(g),g=document.createElement("div"),g.classList.add("tier-leechers"),h(g,`Leechers:${i.leecherCount>-1?i.leecherCount:e}`),u.append(g),g=document.createElement("div"),g.classList.add("tier-scrape"),h(g,`${c.label}:${c.value}`),u.append(g),g=document.createElement("div"),g.classList.add("tier-downloads"),h(g,`Downloads:${i.downloadCount>-1?i.downloadCount:e}`),u.append(g),o.push(u)}}for(;t.firstChild;)t.firstChild.remove();t.append(...o)}_changeFileCommand(e,t){let{controller:r,file_torrent:o}=this,n=o.getId();r.changeFileCommand(n,e,t)}_onFileWantedToggled(e){let{indices:t,wanted:r}=e;this._changeFileCommand(t,r?"files-wanted":"files-unwanted")}_onFilePriorityToggled(e){let{indices:t,priority:r}=e,o=null;switch(r.toString()){case"-1":o="priority-low";break;case"1":o="priority-high";break;default:o="priority-normal";break}this._changeFileCommand(t,o)}_clearFileList(){let{list:e}=this.elements.files;for(;e.firstChild;)e.firstChild.remove();this.file_torrent=null,this.file_torrent_n=null,this.file_rows=null}static createFileTreeModel(e){let t=[],r={children:
`).map(i=>i.trim()).filter(i=>s._isValidURL(i)))this.remote.addTorrentByUrl(n,t);let{files:o}=e.dataTransfer;return o.length>0&&(this.openDialog=new $(this,this.remote,"",o)),e.preventDefault(),!1}togglePeriodicSessionRefresh(e){!e&&this.sessionInterval&&(clearInterval(this.sessionInterval),delete this.sessionInterval),e&&(this.loadDaemonPrefs(),this.sessionInterval||(this.sessionInterval=setInterval(this.loadDaemonPrefs.bind(this),8e3)))}_setFilterText(e){this.filterText=e?e.trim():null,this.refilterAllSoon()}_onTorrentChanged(e){this.changeStatus&&(this._dispatchSelectionChanged(),this.changeStatus=!1);let t=e.currentTarget;this.dirtyTorrents.add(t.getId()),this.refilterSoon()}updateTorrents(e,t){this.remote.updateTorrents(e,t,(r,o)=>{let n=[],i=r.shift(),a={};for(let l of r){for(let[g,d]of i.entries())a[d]=l[g];let{id:c}=a,u=this._torrents[c];if(u){let g=u.needsMetaData();u.refresh(a),g&&!u.needsMetaData()&&n.push(c)}else u=this._torrents[c]=new f(a),u.addEventListener("dataChanged",this._onTorrentChanged.bind(this)),this.dirtyTorrents.add(c),(!("name"in u.fields)||!("status"in u.fields))&&n.push(c)}if(n.length>0){let l=["id",...f.Fields.Metadata,...f.Fields.Stats];this.updateTorrents(n,l),this.refilterSoon()}o&&(this._deleteTorrents(o),this.refilterSoon())})}refreshTorrents(){let e=["id",...f.Fields.Stats];this.updateTorrents("recently-active",e)}_initializeTorrents(){let e=["id",...f.Fields.Metadata,...f.Fields.Stats];this.updateTorrents(null,e)}_onRowClicked(e){let t=e.metaKey||e.ctrlKey,{row:r}=e.currentTarget;if(this.popup&&this.popup.name!=="inspector"&&this.setCurrentPopup(null),e.target.classList.contains("torrent-pauseresume-button"))switch(e.target.dataset.action){case"pause":this._stopTorrents([r.getTorrent()]);break;case"resume":this._startTorrents([r.getTorrent()]);break;default:break}e.stopPropagation(),e.shiftKey?(this._selectRange(r),window.focus()):!r.isSelected()&&t?this._selectRow(r):r.isSelected()?r.isSelected()&&t?this._deselectRow(r):r.isSelected()&&this._setSelectedRow(r):this._setSelectedRow(r),this._last_torrent_clicked=r.getTorrentId()}_deleteTorrents(e){if(e&&e.length>0){for(let t of e)this.dirtyTorrents.add(t),delete this._torrents[t];this.refilterSoon()}}_removeSelectedTorrents(e){let t=this.getSelectedTorrents();t.length>0&&this.setCurrentPopup(new Qe({remote:this.remote,torrents:t,trash:e}))}_startSelectedTorrents(e){this._startTorrents(this.getSelectedTorrents(),e)}_startTorrents(e,t){this.changeStatus=!0,this.remote.startTorrents(s._getTorrentIds(e),t,this.refreshTorrents,this)}_verifyTorrents(e){this.remote.verifyTorrents(s._getTorrentIds(e),this.refreshTorrents,this)}_reannounceTorrents(e){this.remote.reannounceTorrents(s._getTorrentIds(e),this.refreshTorrents,this)}_stopTorrents(e){this.changeStatus=!0,this.remote.stopTorrents(s._getTorrentIds(e),()=>{setTimeout(()=>{this.refreshTorrents()},500)},this)}changeFileCommand(e,t,r){this.remote.changeFileCommand(e,t,r)}_moveTop(){this.remote.moveTorrentsToTop(this._getSelectedTorrentIds(),this.refreshTorrents,this)}_moveUp(){this.remote.moveTorrentsUp(this._getSelectedTorrentIds(),this.refreshTorrents,this)}_moveDown(){this.remote.moveTorrentsDown(this._getSelectedTorrentIds(),this.refreshTorrents,this)}_moveBottom(){this.remote.moveTorrentsToBottom(this._getSelectedTorrentIds(),this.refreshTorrents,this)}_updateGuiFromSession(e){let[,t,r]=e.version.match(/(.*)\s\(([\da-f]+)\)/);this.version_info={checksum:r,version:t},document.querySelector("#toolbar-overflow").classList.toggle("alt-speed-enabled",e[X._TurtleState])}_updateStatusbar(){let e=G,t=this._getAllTorrents(),r=t.reduce((i,a)=>i+a.getUploadSpeed(),0),o=t.reduce((i,a)=>i+a.getDownloadSpeed(),0),n=e.countString("Transfer","Transfers",this._rows.length);h(document.querySelector("#speed-up-label"),e.speedBps(r)),h(document.querySelector("#speed-dn-label"),e.speedBps(o)),h(document.querySelector("#filter-count"),n)}static _displayName(e){let t=e;return t.length>0&&(t=t.charAt(0).toUpperCase()+t.slice(1)),t}_updateFilterSelect(){let e=this._getTrackerCounts(),t=Object.keys(e).sort(),r