diff --git a/CHANGELOG.md b/CHANGELOG.md index ea23904..daba53e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,11 @@ Keep this file updated in the same PR/commit as the code. GitHub Releases should _Nothing yet._ +## 4.5.9 + +- Restore **top-docked** switcher so the Android keyboard no longer covers the list (v4.5.8 bottom ActionSheet regression) +- Keep Stealmoji dismiss-then-`openUrl` jump path; no full-screen touch scrim; Filter field does not auto-focus + ## 4.5.8 - Rewrite switcher UI to match known-good Revenge plugins (**Stealmoji** / **Bunny ActionSheet** / **JumpTo**): open Discord’s native `ActionSheet` via `openLazy`, call `hideActionSheet()` before `openUrl` diff --git a/OPTIONS.md b/OPTIONS.md index 9ffa0aa..0678cd7 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -16,7 +16,7 @@ Every option below must include an explicit **Risk** value. | ID | Option | Risk | Why blocked | Notes | |----|--------|------|-------------|-------| -| **A1** | Device QA | **Low** (process) | Requires a Revenge Discord client and manual checklist | **v4.5.8**. Retest: native ActionSheet UI; after jump, taps must work. Logs: `v4.5.8` + `openUrl`. | +| **A1** | Device QA | **Low** (process) | Requires a Revenge Discord client and manual checklist | **v4.5.9**. Retest: top-docked switcher stays above keyboard; after jump, taps still work. Logs: `v4.5.9` + `openUrl`. | --- @@ -40,8 +40,8 @@ Every option below must include an explicit **Risk** value. | **B14** | `/servers` missing from slash menu | **Done** (v4.4.5) | **Low** | Revenge inverted `shouldHide` filter; omit it + fill command metadata. | | **B15** | `/servers` silent + duplicate | **Done** (v4.4.7) | **Low** | `sendBotMessage` replies; unregister-before-register. | | **B16** | `/servers query` silent no-op | **Done** (v4.4.7) | **Medium** | Jump/error bot replies + harder nav + arg unwrap. | -| **B17** | Switcher sheet + tappable picks (C5/C8) | **Done** (v4.5.8) | **Medium** | Native Discord ActionSheet + simple sheet; bot-message fallback. | -| **B18** | Freeze / dead UI after jump | **Done** (v4.5.8) | **High** | Native Discord ActionSheet + hideActionSheet before openUrl (Stealmoji/JumpTo); no custom overlay hosts. | +| **B17** | Switcher sheet + tappable picks (C5/C8) | **Done** (v4.5.9) | **Medium** | Top-docked searchable panel + simple sheet; bot-message fallback. | +| **B18** | Freeze / dead UI after jump | **Done** (v4.5.9) | **High** | dismiss-then-openUrl (Stealmoji); top-dock for keyboard; no full-screen scrim. | --- @@ -122,7 +122,7 @@ Every option below must include an explicit **Risk** value. ### C8 — Dedicated switcher UI (not in-channel) -**Status:** **Done** (v4.5.8) — `/servers` opens Discord’s native ActionSheet (Stealmoji/Bunny pattern); settings has **Open switcher**; bot-message list remains fallback when sheet APIs are missing. +**Status:** **Done** (v4.5.9) — `/servers` opens a **top-docked** searchable panel (keyboard-safe) with Stealmoji-style dismiss-then-jump; settings has **Open switcher**; bot-message list remains fallback when sheet APIs are missing. **What it is:** Open a real UI surface for `/servers` instead of posting bot messages into the current channel. diff --git a/TESTING.md b/TESTING.md index 73c3a78..71f731e 100644 --- a/TESTING.md +++ b/TESTING.md @@ -48,7 +48,7 @@ All steps exit with code 0. You should see: ``` Tests 86 passed (86) dist/index.js ~18kb -manifest ok (v4.5.8) +manifest ok (v4.5.9) ``` ### Individual commands @@ -369,7 +369,7 @@ If local verification fails, fix the issue before testing on device. | Markdown in names | Server name with `_` or `*` | Listed names escaped in `/servers` output (no broken markdown) | | Long server names | Name > 100 chars | Truncated safely in lists and toasts | | Plugin reload | Disable plugin, re-enable, reload Discord | `/servers` and settings still work | -| Version | Check plugin metadata if Revenge shows it | **4.5.8** | +| Version | Check plugin metadata if Revenge shows it | **4.5.9** | | Ambiguous search | Two servers sharing a prefix, query that prefix | Pick list + refine toast; no jump | | Excluded search | Exclude one of two similar names, query shared fragment | Only non-excluded server matches | | Debug logging | Enable in settings, run `/servers` / toggle flat sidebar | No crash; diagnostics appear in Revenge logs when supported | @@ -391,17 +391,17 @@ For device-only bugs, note that local tests passed — that helps separate Reven --- -## Quick checklist — v4.5.8 device QA (A1) +## Quick checklist — v4.5.9 device QA (A1) Copy this for the release candidate. Prefer a fresh plugin install/update from the **raw** GitHub URL, then full Discord reload. -**Already confirmed:** `openUrl` jumps to the right guild. v4.5.6–4.5.7 left taps dead (custom overlay host). +**Already confirmed:** `openUrl` jumps work and taps stay alive (v4.5.8). Bottom ActionSheet was covered by the keyboard. -**Still needs human testing:** `/servers` should open a **native bottom ActionSheet** (not a top floating panel). After jump, sidebar / channels / composer taps must work. +**Still needs human testing:** `/servers` opens a **top-docked** panel; Filter does not auto-open the keyboard; if you tap Filter, the list stays usable above the keyboard; after jump, taps still work. ``` [ ] make verify — all green locally (or CI green on main) -[ ] Plugin installs / updates on Revenge without crash (shows 4.5.8 if version visible) +[ ] Plugin installs / updates on Revenge without crash (shows 4.5.9 if version visible) Install URL: https://raw.githubusercontent.com/djbclark/RevengeQuickSwitcher/main/ [ ] Smoke plugin installs and ENABLES (toggle on, no X) Smoke URL: https://raw.githubusercontent.com/djbclark/RevengeQuickSwitcher/main/smoke/ diff --git a/dist/index.js b/dist/index.js index 9036527..ca5ae98 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,36 +1,36 @@ -(function(exports){var module={exports:exports};"use strict";var It=Object.create;var q=Object.defineProperty,Lt=Object.defineProperties,Rt=Object.getOwnPropertyDescriptor,Mt=Object.getOwnPropertyDescriptors,Nt=Object.getOwnPropertyNames,_e=Object.getOwnPropertySymbols,zt=Object.getPrototypeOf,Fe=Object.prototype.hasOwnProperty,Gt=Object.prototype.propertyIsEnumerable;var Pe=(e,t,n)=>t in e?q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,G=(e,t)=>{for(var n in t||(t={}))Fe.call(t,n)&&Pe(e,n,t[n]);if(_e)for(var n of _e(t))Gt.call(t,n)&&Pe(e,n,t[n]);return e},H=(e,t)=>Lt(e,Mt(t));var Ht=(e,t)=>{for(var n in t)q(e,n,{get:t[n],enumerable:!0})},Be=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Nt(t))!Fe.call(e,i)&&i!==n&&q(e,i,{get:()=>t[i],enumerable:!(r=Rt(t,i))||r.enumerable});return e};var Ue=(e,t,n)=>(n=e!=null?It(zt(e)):{},Be(t||!e||!e.__esModule?q(n,"default",{value:e,enumerable:!0}):n,e)),$t=e=>Be(q({},"__esModule",{value:!0}),e);var De=(e,t,n)=>new Promise((r,i)=>{var o=s=>{try{g(n.next(s))}catch(d){i(d)}},l=s=>{try{g(n.throw(s))}catch(d){i(d)}},g=s=>s.done?r(s.value):Promise.resolve(s.value).then(o,l);g((n=n.apply(e,t)).next())});var Rn={};Ht(Rn,{default:()=>Ln});module.exports=$t(Rn);var p=Ue((vendetta.metro.common.React||window.React)),k=vendetta.metro,vt=vendetta.patcher,f={showToast:function(message,_type){return vendetta.ui.toasts.showToast(String(message));}},v=vendetta,Ct=vendetta.commands,u=vendetta.plugin,kt=vendetta.storage,wt=vendetta.ui.components,m=(vendetta.metro.common.ReactNative||window.ReactNative);var I=e=>e.replace(/[\\_*~`|[\]()]/g,"\\$&"),_=e=>e?Array.from(String(e)).slice(0,100).join("").replace(/[\u200B-\u200D\uFEFF\u202A-\u202E\u2066-\u2069]/g,"").trim()||"Unnamed":"Unknown",N=e=>e.normalize("NFKC").toLowerCase(),$=e=>typeof e=="string"?e:e&&(e.id||e.guildId||e.guild_id)||null,_t=(e,t)=>{for(let n=0;n{var r,i;for(let o of e){if((o==null?void 0:o.type)==="folder"){let s=$(o);n(`folder:${s!=null?s:"?"}`),Array.isArray(o.guilds)&&Oe(o.guilds,t,n);continue}let l=$(o);if(!l)continue;let g=(i=(r=t==null?void 0:t(l))!=null?r:o.name)!=null?i:"";n(l),g&&n(g)}},je=(e,t)=>{let n=2166136261;return Oe(e,t,r=>{n=_t(n,r)}),n},Pt=(e,t)=>{let n=0;for(let r=0;r{let t=new Map;return e&&e.split(` -`).forEach(n=>{let r=n.indexOf("=");if(r<=0)return;let i=N(n.slice(0,r).trim()),o=N(n.slice(r+1).trim());i&&o&&t.set(i,o)}),t},Ve=(e,t)=>{let n=N(e).trim();return t.has(n)&&(n=t.get(n)),n},Ft=(e,t)=>t===e?100:t.startsWith(e)?50:t.includes(e)?10:e.length>=3&&Pt(e,t)?5:0,We=(e,t)=>{let n=0,r=[];for(let i=0;in){n=o,r.length=0,r.push(i);continue}o===n&&r.push(i)}}return{score:n,indexes:r,matches:r.map(i=>t[i])}};var Qe=(e,t)=>{let n=`### Multiple matches for \`${I(e)}\` -`,r=t.map(l=>`\u2022 ${I(l)}`),i=` +(function(exports){var module={exports:exports};"use strict";var It=Object.create;var Q=Object.defineProperty,Lt=Object.defineProperties,Rt=Object.getOwnPropertyDescriptor,Mt=Object.getOwnPropertyDescriptors,Nt=Object.getOwnPropertyNames,De=Object.getOwnPropertySymbols,zt=Object.getPrototypeOf,Be=Object.prototype.hasOwnProperty,Gt=Object.prototype.propertyIsEnumerable;var Oe=(e,t,n)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,A=(e,t)=>{for(var n in t||(t={}))Be.call(t,n)&&Oe(e,n,t[n]);if(De)for(var n of De(t))Gt.call(t,n)&&Oe(e,n,t[n]);return e},I=(e,t)=>Lt(e,Mt(t));var Pt=(e,t)=>{for(var n in t)Q(e,n,{get:t[n],enumerable:!0})},Ve=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Nt(t))!Be.call(e,i)&&i!==n&&Q(e,i,{get:()=>t[i],enumerable:!(r=Rt(t,i))||r.enumerable});return e};var je=(e,t,n)=>(n=e!=null?It(zt(e)):{},Ve(t||!e||!e.__esModule?Q(n,"default",{value:e,enumerable:!0}):n,e)),$t=e=>Ve(Q({},"__esModule",{value:!0}),e);var We=(e,t,n)=>new Promise((r,i)=>{var o=s=>{try{d(n.next(s))}catch(u){i(u)}},l=s=>{try{d(n.throw(s))}catch(u){i(u)}},d=s=>s.done?r(s.value):Promise.resolve(s.value).then(o,l);d((n=n.apply(e,t)).next())});var Mn={};Pt(Mn,{default:()=>Rn});module.exports=$t(Mn);var p=je((vendetta.metro.common.React||window.React)),w=vendetta.metro,Tt=vendetta.patcher,h={showToast:function(message,_type){return vendetta.ui.toasts.showToast(String(message));}},T=vendetta,Ct=vendetta.commands,g=vendetta.plugin,kt=vendetta.storage,wt=vendetta.ui.components,f=(vendetta.metro.common.ReactNative||window.ReactNative);var R=e=>e.replace(/[\\_*~`|[\]()]/g,"\\$&"),$=e=>e?Array.from(String(e)).slice(0,100).join("").replace(/[\u200B-\u200D\uFEFF\u202A-\u202E\u2066-\u2069]/g,"").trim()||"Unnamed":"Unknown",N=e=>e.normalize("NFKC").toLowerCase(),P=e=>typeof e=="string"?e:e&&(e.id||e.guildId||e.guild_id)||null,_t=(e,t)=>{for(let n=0;n{var r,i;for(let o of e){if((o==null?void 0:o.type)==="folder"){let s=P(o);n(`folder:${s!=null?s:"?"}`),Array.isArray(o.guilds)&&qe(o.guilds,t,n);continue}let l=P(o);if(!l)continue;let d=(i=(r=t==null?void 0:t(l))!=null?r:o.name)!=null?i:"";n(l),d&&n(d)}},Qe=(e,t)=>{let n=2166136261;return qe(e,t,r=>{n=_t(n,r)}),n},Ft=(e,t)=>{let n=0;for(let r=0;r{let t=new Map;return e&&e.split(` +`).forEach(n=>{let r=n.indexOf("=");if(r<=0)return;let i=N(n.slice(0,r).trim()),o=N(n.slice(r+1).trim());i&&o&&t.set(i,o)}),t},Ye=(e,t)=>{let n=N(e).trim();return t.has(n)&&(n=t.get(n)),n},Ht=(e,t)=>t===e?100:t.startsWith(e)?50:t.includes(e)?10:e.length>=3&&Ft(e,t)?5:0,Xe=(e,t)=>{let n=0,r=[];for(let i=0;in){n=o,r.length=0,r.push(i);continue}o===n&&r.push(i)}}return{score:n,indexes:r,matches:r.map(i=>t[i])}};var Je=(e,t)=>{let n=`### Multiple matches for \`${R(e)}\` +`,r=t.map(l=>`\u2022 ${R(l)}`),i=` *Refine your query or use a custom alias.*`,o=n+r.join(` -`)+i;if(o.length>1900){let l=1900-n.length-i.length-20,g=[],s=0;for(let a of r){let c=g.length>0?1+a.length:a.length;if(s+c>l)break;g.push(a),s+=c}let d=r.length-g.length;o=n+g.join(` -`)+(d>0?` -\u2022 \u2026and ${d} more`:"")+i}return{kind:"pick-list",content:o,count:t.length}};var Bt=e=>{let t=`### Servers (${e.length}) -`.length,n=Math.max(32,1900-t-90),r=[],i=[],o=0;for(let l of e){let g=`\u2022 ${I(l)}`,s=i.length>0?1+g.length:g.length,d=i.length>0&&o+s>n,a=i.length>=40;(d||a)&&(r.push(i),i=[],o=0),i.push(l),o+=i.length===1?g.length:1+g.length}return(i.length>0||r.length===0)&&r.push(i),r},qe=(e,t)=>{var s;let n=Bt(e),r=n.length,i=t!=null&&Number.isFinite(t)?t:1,o=Math.min(r,Math.max(1,i)),l=(s=n[o-1])!=null?s:[],g=`### Servers (${e.length}) -`;return g+=l.map(d=>`\u2022 ${I(d)}`).join(` -`),g+=` +`)+i;if(o.length>1900){let l=1900-n.length-i.length-20,d=[],s=0;for(let a of r){let c=d.length>0?1+a.length:a.length;if(s+c>l)break;d.push(a),s+=c}let u=r.length-d.length;o=n+d.join(` +`)+(u>0?` +\u2022 \u2026and ${u} more`:"")+i}return{kind:"pick-list",content:o,count:t.length}};var Ut=e=>{let t=`### Servers (${e.length}) +`.length,n=Math.max(32,1900-t-90),r=[],i=[],o=0;for(let l of e){let d=`\u2022 ${R(l)}`,s=i.length>0?1+d.length:d.length,u=i.length>0&&o+s>n,a=i.length>=40;(u||a)&&(r.push(i),i=[],o=0),i.push(l),o+=i.length===1?d.length:1+d.length}return(i.length>0||r.length===0)&&r.push(i),r},Ke=(e,t)=>{var s;let n=Ut(e),r=n.length,i=t!=null&&Number.isFinite(t)?t:1,o=Math.min(r,Math.max(1,i)),l=(s=n[o-1])!=null?s:[],d=`### Servers (${e.length}) +`;return d+=l.map(u=>`\u2022 ${R(u)}`).join(` +`),d+=` -**Page ${o} of ${r}**`,o1&&(g+=` -*Use /servers 1 to return to the start.*`),{kind:"page",content:g,currentPage:o,totalPages:r}};var Ye=e=>{if(!e)return"";let t=P(e);return Array.from(t.entries()).map(([n,r])=>`${n}=${r}`).sort((n,r)=>n.localeCompare(r)).join(` -`)},Xe=(e,t)=>{let n=P(e),r=P(t),i=0,o=0;for(let s of t.split(` -`)){let d=s.trim();if(!d)continue;let a=d.indexOf("=");if(a<=0){o+=1;continue}let c=d.slice(0,a).trim(),S=d.slice(a+1).trim();if(!c||!S){o+=1;continue}i+=1}let l=new Map([...n,...r]);return{text:Array.from(l.entries()).map(([s,d])=>`${s}=${d}`).sort((s,d)=>s.localeCompare(d)).join(` -`),imported:i,skipped:o,total:l.size}},fe=e=>P(e).size;var Dt=e=>/^\d{5,}$/.test(e),he=e=>{if(!e)return[];let t=[];for(let n of e.split(` -`)){let r=n.trim();if(!r||r.startsWith("#"))continue;if(Dt(r)){t.push({type:"id",value:r});continue}if(r.startsWith("~")){let o=N(r.slice(1).trim());o.length>=2&&t.push({type:"name",value:o,mode:"contains"});continue}let i=N(r);i&&t.push({type:"name",value:i,mode:"exact"})}return t},Je=(e,t,n)=>{if(!n.length)return!1;for(let r of n){if(r.type==="id"){if(e&&e===r.value)return!0;continue}if(t&&(r.mode==="exact"&&t===r.value||r.mode==="contains"&&t.includes(r.value)))return!0}return!1},Ze=e=>he(e).length,Ke=()=>"One per line: server name, Discord id, or ~partial name. Lines starting with # are comments.";var X=10,jt=1,Vt=15,Y=e=>{let t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?Math.min(Vt,Math.max(jt,Math.trunc(t))):X},et=e=>{if(Array.isArray(e))return e.map(String).filter(Boolean);if(typeof e!="string"||!e.trim())return[];try{let t=JSON.parse(e);if(Array.isArray(t))return t.map(String).filter(Boolean)}catch(t){}return e.split(` -`).map(t=>t.trim()).filter(Boolean)},ye=e=>JSON.stringify(e),tt=(e,t,n)=>{if(!t)return e.slice(0,Y(n));let r=Y(n);return[t,...e.filter(i=>i!==t)].slice(0,r)},nt=e=>/^recent$/i.test(e.trim()),rt=e=>{let t=/^r(\d+)$/i.exec(e.trim());if(!t)return null;let n=parseInt(t[1],10);return n>=1?n:null},se=(e,t)=>{let n=[];for(let r of e){let i=t.get(r);i&&n.push({id:r,name:_(i.name)})}return n},it=e=>{if(e.length===0)return{kind:"recent-list",content:"### Recent servers\n*No recent jumps yet. Use `/servers query:\u2026` to jump; history is recorded only when this plugin navigates.*",count:0};let t=e.map((r,i)=>`${i+1}. ${I(r.name)} \u2014 \`/servers r${i+1}\``);return{kind:"recent-list",content:`### Recent servers (${e.length}) +**Page ${o} of ${r}**`,o1&&(d+=` +*Use /servers 1 to return to the start.*`),{kind:"page",content:d,currentPage:o,totalPages:r}};var Ze=e=>{if(!e)return"";let t=_(e);return Array.from(t.entries()).map(([n,r])=>`${n}=${r}`).sort((n,r)=>n.localeCompare(r)).join(` +`)},et=(e,t)=>{let n=_(e),r=_(t),i=0,o=0;for(let s of t.split(` +`)){let u=s.trim();if(!u)continue;let a=u.indexOf("=");if(a<=0){o+=1;continue}let c=u.slice(0,a).trim(),m=u.slice(a+1).trim();if(!c||!m){o+=1;continue}i+=1}let l=new Map([...n,...r]);return{text:Array.from(l.entries()).map(([s,u])=>`${s}=${u}`).sort((s,u)=>s.localeCompare(u)).join(` +`),imported:i,skipped:o,total:l.size}},ye=e=>_(e).size;var Ot=e=>/^\d{5,}$/.test(e),Se=e=>{if(!e)return[];let t=[];for(let n of e.split(` +`)){let r=n.trim();if(!r||r.startsWith("#"))continue;if(Ot(r)){t.push({type:"id",value:r});continue}if(r.startsWith("~")){let o=N(r.slice(1).trim());o.length>=2&&t.push({type:"name",value:o,mode:"contains"});continue}let i=N(r);i&&t.push({type:"name",value:i,mode:"exact"})}return t},tt=(e,t,n)=>{if(!n.length)return!1;for(let r of n){if(r.type==="id"){if(e&&e===r.value)return!0;continue}if(t&&(r.mode==="exact"&&t===r.value||r.mode==="contains"&&t.includes(r.value)))return!0}return!1},nt=e=>Se(e).length,rt=()=>"One per line: server name, Discord id, or ~partial name. Lines starting with # are comments.";var X=10,Vt=1,jt=15,Y=e=>{let t=typeof e=="number"?e:Number(e);return Number.isFinite(t)?Math.min(jt,Math.max(Vt,Math.trunc(t))):X},it=e=>{if(Array.isArray(e))return e.map(String).filter(Boolean);if(typeof e!="string"||!e.trim())return[];try{let t=JSON.parse(e);if(Array.isArray(t))return t.map(String).filter(Boolean)}catch(t){}return e.split(` +`).map(t=>t.trim()).filter(Boolean)},be=e=>JSON.stringify(e),ot=(e,t,n)=>{if(!t)return e.slice(0,Y(n));let r=Y(n);return[t,...e.filter(i=>i!==t)].slice(0,r)},st=e=>/^recent$/i.test(e.trim()),lt=e=>{let t=/^r(\d+)$/i.exec(e.trim());if(!t)return null;let n=parseInt(t[1],10);return n>=1?n:null},ce=(e,t)=>{let n=[];for(let r of e){let i=t.get(r);i&&n.push({id:r,name:$(i.name)})}return n},at=e=>{if(e.length===0)return{kind:"recent-list",content:"### Recent servers\n*No recent jumps yet. Use `/servers query:\u2026` to jump; history is recorded only when this plugin navigates.*",count:0};let t=e.map((r,i)=>`${i+1}. ${R(r.name)} \u2014 \`/servers r${i+1}\``);return{kind:"recent-list",content:`### Recent servers (${e.length}) `+t.join(` `)+` -*History updates only when Quick Server Switcher jumps you.*`,count:e.length}};var J=e=>{if(e==null)return null;if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(typeof e=="object"){let t=e;if("value"in t)return J(t.value);if(typeof t.text=="string")return t.text;if(typeof t.label=="string")return t.label}return e},Qt=e=>e==null?[]:Array.isArray(e)?e:typeof e=="object"?Object.keys(e).map(t=>({name:t,value:e[t]})):[],qt=e=>{var g,s,d,a;let t=Qt(e),n=t.find(c=>(c==null?void 0:c.name)==="query"),r=t.find(c=>(c==null?void 0:c.name)==="page"),i=J(n==null?void 0:n.value),o=J(r==null?void 0:r.value);if(i==null&&o==null&&t.length>0){let c=J((s=(g=t[0])==null?void 0:g.value)!=null?s:t[0]),S=t.length>1?J((a=(d=t[1])==null?void 0:d.value)!=null?a:t[1]):null;typeof c=="number"||typeof c=="string"&&/^\d+$/.test(c.trim())?o=c:c!=null&&c!==""&&(i=c,S!=null&&S!==""&&(o=S))}o==null&&i!=null&&/^\d+$/.test(String(i).trim())&&(o=parseInt(String(i).trim(),10),i=null);let l=o!=null?Number(o):null;return{query:i!=null&&String(i).length>0?String(i):null,page:l!=null&&Number.isFinite(l)?l:null}},ot=(e,t,n)=>{var l;let r=$(t);if(!r)return e.showToast("Could not resolve server id","danger"),{kind:"error",content:"Could not resolve server id"};e.navigateToGuild(r),(l=e.recordRecent)==null||l.call(e,r);let i=_(t.name),o=n!=null?n:`Jumped to ${i}`;return e.showToast(o,"success"),{kind:"jump",content:`\u2192 **${I(i)}**`,id:r,name:i}},Se=(e,t)=>{var B,O,ie,j,V,T,M,pe,$e;let{query:n,page:r}=qt(e),i=t.getGuilds(),o=he(t.excludes||"");if((B=t.debugLog)==null||B.call(t,"executeServersCommand",{query:n,page:r,guildCount:i.length,excludeRules:o.length}),!i.length){t.showToast("No servers found","danger");return}let l=i.map(y=>{let A=$(y)||"",oe=_(y.name),W=N(oe);return{original:y,id:A,sanitized:oe,normalized:W,excluded:Je(A,W,o)}}).sort((y,A)=>y.sanitized.localeCompare(A.sanitized,void 0,{sensitivity:"base"})),g=l.filter(y=>!y.excluded),s=t.hideExcludedFromList?g:l,d=new Map(l.filter(y=>y.id).map(y=>[y.id,y.original]));if(n!=null&&n.trim()){let y=n.trim();if(nt(y)){let U=(ie=(O=t.getRecentIds)==null?void 0:O.call(t))!=null?ie:[],D=se(U,d);(j=t.debugLog)==null||j.call(t,"recent list",{stored:U.length,resolved:D.length});let E=it(D);return H(G({},E),{items:D.map(Q=>({id:Q.id,name:Q.name}))})}let A=rt(y);if(A!=null){let U=(T=(V=t.getRecentIds)==null?void 0:V.call(t))!=null?T:[],E=se(U,d)[A-1];if(!E)return t.showToast(`No recent server in slot r${A}`,"danger"),{kind:"error",content:`No recent server in slot r${A}`};let Q=d.get(E.id);return Q?ot(t,Q):(t.showToast("Could not resolve server id","danger"),{kind:"error",content:"Could not resolve server id"})}if(!g.length)return t.showToast("All servers are excluded","danger"),{kind:"error",content:"All servers are excluded"};let oe=P(t.aliases),W=Ve(y,oe),{matches:z,score:At}=We(W,g);if((M=t.debugLog)==null||M.call(t,"search",{normalizedQuery:W,score:At,matchCount:z.length}),z.length===0)return t.showToast("No match found","danger"),{kind:"error",content:`No match for \`${I(y)}\``};if(z.length>1){t.showToast(`${z.length} matches \u2014 refine your query`,"danger");let U=z.filter(E=>E.id).map(E=>({id:E.id,name:E.sanitized})),D=Qe(y,z.map(E=>E.sanitized));return H(G({},D),{items:U,query:y})}return ot(t,z[0].original)}if(!s.length)return t.showToast("All servers are excluded","danger"),{kind:"error",content:"All servers are excluded"};let a=s.filter(y=>y.id).map(y=>({id:y.id,name:y.sanitized})),c=($e=(pe=t.getRecentIds)==null?void 0:pe.call(t))!=null?$e:[],S=se(c,d).map(y=>({id:y.id,name:y.name})),w=qe(s.map(y=>y.sanitized),r);return r!=null?H(G({},w),{items:a,recentItems:S}):{kind:"switcher",content:w.content,items:a,recentItems:S,count:a.length}};var Yt=e=>e.flatMap(t=>{var n;return t.type==="folder"?(n=t.guilds)!=null?n:[]:[t]}),Xt=(e,t)=>Yt(e).map(n=>{let r=$(n),i=r?t(r):null;return{node:n,name:i?_(i):""}}).sort((n,r)=>n.name.localeCompare(r.name,void 0,{sensitivity:"base"})).map(n=>n.node),be=()=>{let e=new WeakMap;return{clear(){e=new WeakMap},getOrCompute(t,n,r){let i=je(t,r),o=e.get(t);if((o==null?void 0:o.checksum)===i)return o.data;let l=n();return e.set(t,{checksum:i,data:l}),l}}},st=(e,t,n,r)=>!t||!Array.isArray(e)?e:r.getOrCompute(e,()=>Xt(e,n),n);var h=Ue((vendetta.metro.common.React||window.React)),L=vendetta.metro,x=(vendetta.metro.common.ReactNative||window.ReactNative),ct="quick-switcher-sheet",dt="quick-switcher-simple",xe=12,ut=8,Jt=(e,t=ut)=>Math.max(1,Math.ceil(Math.max(0,e)/t)),Zt=(e,t,n=ut)=>{let r=Jt(e.length,n),i=Math.min(Math.max(1,t),r),o=(i-1)*n;return{pageItems:e.slice(o,o+n),page:i,totalPages:r}},Kt=(e,t)=>{let n=t.trim().toLowerCase();return n?e.filter(r=>r.name.toLowerCase().includes(n)):e},Z,K,gt,le,mt,lt=!1,ae=()=>{if(Z)return Z;try{Z=(0,L.findByProps)("openLazy","hideActionSheet")||(0,L.findByProps)("hideActionSheet")}catch(e){Z=void 0}return Z},en=()=>{if(K)return K;try{K=(0,L.findByProps)("hideActionSheet","showSimpleActionSheet")||(0,L.findByProps)("showSimpleActionSheet")}catch(e){K=void 0}return K},pt=()=>{if(!lt){lt=!0;try{let e=(0,L.findByProps)("ActionSheet");gt=e==null?void 0:e.ActionSheet}catch(e){}try{let e=(0,L.findByProps)("ActionSheetTitleHeader");le=e==null?void 0:e.ActionSheetTitleHeader}catch(e){}if(!le)try{let e=(0,L.findByProps)("BottomSheetTitleHeader");le=e==null?void 0:e.BottomSheetTitleHeader}catch(e){}try{let e=(0,L.findByProps)("ActionSheetCloseButton");mt=e==null?void 0:e.ActionSheetCloseButton}catch(e){}}},Te=()=>{var e,t,n,r,i,o;try{(t=(e=ae())==null?void 0:e.hideActionSheet)==null||t.call(e,ct)}catch(l){}try{(r=(n=ae())==null?void 0:n.hideActionSheet)==null||r.call(n,dt)}catch(l){}try{(o=(i=ae())==null?void 0:i.hideActionSheet)==null||o.call(i)}catch(l){}},ft=(e,t=160)=>{try{Te()}catch(n){}setTimeout(()=>{try{e()}catch(n){}},t)};var tn={text:"#DBDEE1",muted:"#A3A6AA",faint:"#80848E",panel:"#2B2D31",border:"#1E1F22",accent:"#5865F2"},nn=e=>{let[t,n]=h.default.useState(e.initialQuery||""),[r,i]=h.default.useState(1),o=tn,l=e.recentItems||[],g=Kt(e.items,t),{pageItems:s,page:d,totalPages:a}=Zt(g,r);h.default.useEffect(()=>{i(1)},[t]);let c=T=>{ft(()=>{var M;try{(M=e.onClose)==null||M.call(e)}catch(pe){}e.onPick(T)})},S=()=>{var T;Te();try{(T=e.onClose)==null||T.call(e)}catch(M){}};pt();let w=gt,B=le,O=mt,ie=B&&O?h.default.createElement(B,{title:e.title,subtitle:e.subtitle,trailing:h.default.createElement(O,{onPress:S})}):h.default.createElement(x.View,{style:{flexDirection:"row",alignItems:"center",paddingHorizontal:16,paddingVertical:12}},h.default.createElement(x.Text,{style:{color:o.text,fontSize:18,fontWeight:"700",flex:1}},e.title),h.default.createElement(x.Pressable,{onPress:S,hitSlop:12,accessibilityRole:"button",accessibilityLabel:"Close"},h.default.createElement(x.Text,{style:{color:o.accent,fontWeight:"600"}},"Close"))),j=(T,M)=>h.default.createElement(x.Pressable,{key:`${M}:${T.id}`,onPress:()=>c(T),style:{paddingVertical:14,paddingHorizontal:16,borderBottomWidth:1,borderBottomColor:o.border},accessibilityRole:"button",accessibilityLabel:`Jump to ${T.name}`},h.default.createElement(x.Text,{style:{color:o.text,fontSize:16}},T.name)),V=h.default.createElement(h.default.Fragment,null,ie,e.subtitle&&!B?h.default.createElement(x.Text,{style:{color:o.muted,fontSize:13,paddingHorizontal:16,marginBottom:8}},e.subtitle):null,h.default.createElement(x.TextInput,{value:t,onChangeText:n,placeholder:"Filter servers",placeholderTextColor:o.faint,autoFocus:!1,style:{marginHorizontal:16,marginBottom:8,backgroundColor:"#1E1F22",color:o.text,borderRadius:8,paddingHorizontal:12,paddingVertical:10}}),h.default.createElement(x.ScrollView,{style:{maxHeight:360},keyboardShouldPersistTaps:"handled",nestedScrollEnabled:!0},!t.trim()&&l.length>0&&d===1?h.default.createElement(x.View,{style:{marginBottom:8}},h.default.createElement(x.Text,{style:{color:o.muted,fontSize:11,fontWeight:"700",textTransform:"uppercase",paddingHorizontal:16,marginBottom:4}},"Recent"),l.slice(0,5).map(T=>j(T,"recent"))):null,h.default.createElement(x.Text,{style:{color:o.muted,fontSize:11,fontWeight:"700",textTransform:"uppercase",paddingHorizontal:16,marginBottom:4}},t.trim()?`Matches (${g.length})`:`Servers (${g.length}) \xB7 page ${d}/${a}`),s.length===0?h.default.createElement(x.Text,{style:{color:o.faint,padding:16}},"No servers match."):s.map(T=>j(T,"all"))),a>1?h.default.createElement(x.View,{style:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",paddingHorizontal:16,paddingVertical:12,paddingBottom:20}},h.default.createElement(x.Pressable,{onPress:()=>i(T=>Math.max(1,T-1)),disabled:d<=1,style:{flex:1,marginRight:6,paddingVertical:10,borderRadius:8,backgroundColor:d<=1?"#3A3C41":o.accent,alignItems:"center",opacity:d<=1?.5:1},accessibilityRole:"button",accessibilityLabel:"Previous page"},h.default.createElement(x.Text,{style:{color:o.text,fontWeight:"600"}},"Previous")),h.default.createElement(x.Text,{style:{color:o.muted,fontSize:13,minWidth:72,textAlign:"center"}},d," / ",a),h.default.createElement(x.Pressable,{onPress:()=>i(T=>Math.min(a,T+1)),disabled:d>=a,style:{flex:1,marginLeft:6,paddingVertical:10,borderRadius:8,backgroundColor:d>=a?"#3A3C41":o.accent,alignItems:"center",opacity:d>=a?.5:1},accessibilityRole:"button",accessibilityLabel:"Next page"},h.default.createElement(x.Text,{style:{color:o.text,fontWeight:"600"}},"Next"))):h.default.createElement(x.View,{style:{height:16}}));return w?h.default.createElement(w,{scrollable:!0},V):h.default.createElement(x.View,{style:{backgroundColor:o.panel}},V)},at=(e,t,n)=>{try{let r=en(),i=r==null?void 0:r.showSimpleActionSheet;if(typeof i!="function"||t.length===0)return!1;let o=t.slice(0,xe);return i({key:dt,header:{title:e,onClose:()=>Te()},options:o.map(l=>({label:l.name,onPress:()=>{ft(()=>n(l),120)}}))}),!0}catch(r){return!1}},rn=e=>{try{pt();let t=ae();return typeof(t==null?void 0:t.openLazy)!="function"?!1:(t.openLazy(Promise.resolve({default:nn}),ct,e),!0)}catch(t){return!1}},ee=e=>{let t=!!e.preferSimple&&e.items.length>0&&e.items.length<=xe;return t&&at(e.title,e.items,e.onPick)?"simple":rn(e)?"sheet":!t&&e.items.length>0&&e.items.length<=xe&&at(e.title,e.items,e.onPick)?"simple":null};var ke=vendetta.metro,ce={textMuted:"#A3A6AA",textNormal:"#DBDEE1",textFaint:"#80848E",backgroundSecondary:"#2B2D31"},ve,Ce,on=()=>ve!=null?ve:ve=(0,ke.findByProps)("colors","unsafe_rawColors"),sn=()=>Ce!=null?Ce:Ce=(0,ke.findByProps)("theme","darkTheme"),ln=()=>{var t,n,r,i;let e=sn();return(i=(r=e==null?void 0:e.theme)!=null?r:(n=(t=e==null?void 0:e.getState)==null?void 0:t.call(e))==null?void 0:n.theme)!=null?i:"dark"},an=(e,t)=>typeof e=="string"&&e.length>0?e:typeof e=="number"?`#${(e>>>0).toString(16).padStart(8,"0").slice(2)}`:t,de=(e,t)=>{var o,l,g;let n=on(),r=(g=(o=n==null?void 0:n.meta)==null?void 0:o.resolveSemanticColor)!=null?g:(l=n==null?void 0:n.internal)==null?void 0:l.resolveSemanticColor;if(!r)return t;let i=ln();for(let s of e)try{let d=r(i,s);if(d!=null&&d!=="")return an(d,t)}catch(d){}return t},ht=()=>({textMuted:de(["HEADER_SECONDARY","TEXT_MUTED","INTERACTIVE_MUTED"],ce.textMuted),textNormal:de(["TEXT_NORMAL","HEADER_PRIMARY"],ce.textNormal),textFaint:de(["TEXT_MUTED","INTERACTIVE_MUTED"],ce.textFaint),backgroundSecondary:de(["BACKGROUND_SECONDARY","BG_BASE_SECONDARY","BACKGROUND_SECONDARY_ALT"],ce.backgroundSecondary)});var we,Ee,Ae,Ie,Le,Re,Me,Ne,Ge=()=>we!=null?we:we=(0,k.findByProps)("getGuild","getGuilds"),cn=()=>Ee!=null?Ee:Ee=(0,k.findByProps)("getSortedGuilds"),He=()=>Ae!=null?Ae:Ae=(0,k.findByProps)("setString","getString"),dn=()=>Ie!=null?Ie:Ie=(0,k.findByProps)("sendBotMessage"),un=()=>Le!=null?Le:Le=(0,k.findByProps)("getLastSelectedChannelId")||(0,k.findByProps)("getChannelId","getVoiceChannelId"),gn=()=>Re!=null?Re:Re=(0,k.findByProps)("getChannels","getDefaultChannel")||(0,k.findByProps)("getDefaultChannel"),mn=()=>Me!=null?Me:Me=(0,k.findByProps)("getGuildId","getLastSelectedGuildId"),pn=()=>Ne!=null?Ne:Ne=(0,k.findByProps)("openUrl")||(0,k.findByProps)("openURL","openDeeplink")||(0,k.findByProps)("openURL"),yt=()=>{var e,t,n;try{return(n=(t=(e=mn())==null?void 0:e.getGuildId)==null?void 0:t.call(e))!=null?n:null}catch(r){return null}},ue=(e,t)=>{if(!e||!t)return;let n=dn();if(n!=null&&n.sendBotMessage){n.sendBotMessage(e,t);return}if(n!=null&&n.sendMessage){n.sendMessage(e,{content:t},void 0,{nonce:Date.now().toString()});return}(0,f.showToast)("Could not post /servers reply in this channel","danger")},F="4.5.8",St=()=>{var e,t;try{u.storage.flatSidebar===void 0&&(u.storage.flatSidebar=!1),u.storage.aliases===void 0&&(u.storage.aliases=""),u.storage.debugLogging===void 0&&(u.storage.debugLogging=!1),u.storage.recentIds===void 0&&(u.storage.recentIds="[]"),u.storage.recentHistorySize===void 0&&(u.storage.recentHistorySize=X),u.storage.excludes===void 0&&(u.storage.excludes=""),u.storage.hideExcludedFromList===void 0&&(u.storage.hideExcludedFromList=!1)}catch(n){(t=(e=v.logger).error)==null||t.call(e,"Failed to initialize plugin storage",n)}},ze=be(),bt=!1,R,te,xt=()=>{ze.clear(),ze=be()},Et=80,C=[],Tt=!1,fn=()=>{C.length=0;try{u.storage.debugLogText="",u.storage.debugLogPluginVersion=F}catch(e){}},re=()=>{if(!Tt){Tt=!0;try{if(u.storage.debugLogPluginVersion!==F){fn();return}let e=u.storage.debugLogText;if(typeof e!="string"||!e.trim())return;let t=e.includes(` +*History updates only when Quick Server Switcher jumps you.*`,count:e.length}};var J=e=>{if(e==null)return null;if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(typeof e=="object"){let t=e;if("value"in t)return J(t.value);if(typeof t.text=="string")return t.text;if(typeof t.label=="string")return t.label}return e},qt=e=>e==null?[]:Array.isArray(e)?e:typeof e=="object"?Object.keys(e).map(t=>({name:t,value:e[t]})):[],Qt=e=>{var d,s,u,a;let t=qt(e),n=t.find(c=>(c==null?void 0:c.name)==="query"),r=t.find(c=>(c==null?void 0:c.name)==="page"),i=J(n==null?void 0:n.value),o=J(r==null?void 0:r.value);if(i==null&&o==null&&t.length>0){let c=J((s=(d=t[0])==null?void 0:d.value)!=null?s:t[0]),m=t.length>1?J((a=(u=t[1])==null?void 0:u.value)!=null?a:t[1]):null;typeof c=="number"||typeof c=="string"&&/^\d+$/.test(c.trim())?o=c:c!=null&&c!==""&&(i=c,m!=null&&m!==""&&(o=m))}o==null&&i!=null&&/^\d+$/.test(String(i).trim())&&(o=parseInt(String(i).trim(),10),i=null);let l=o!=null?Number(o):null;return{query:i!=null&&String(i).length>0?String(i):null,page:l!=null&&Number.isFinite(l)?l:null}},ct=(e,t,n)=>{var l;let r=P(t);if(!r)return e.showToast("Could not resolve server id","danger"),{kind:"error",content:"Could not resolve server id"};e.navigateToGuild(r),(l=e.recordRecent)==null||l.call(e,r);let i=$(t.name),o=n!=null?n:`Jumped to ${i}`;return e.showToast(o,"success"),{kind:"jump",content:`\u2192 **${R(i)}**`,id:r,name:i}},xe=(e,t)=>{var B,se,V,le,v,z,j,He,Ue;let{query:n,page:r}=Qt(e),i=t.getGuilds(),o=Se(t.excludes||"");if((B=t.debugLog)==null||B.call(t,"executeServersCommand",{query:n,page:r,guildCount:i.length,excludeRules:o.length}),!i.length){t.showToast("No servers found","danger");return}let l=i.map(S=>{let L=P(S)||"",ae=$(S.name),W=N(ae);return{original:S,id:L,sanitized:ae,normalized:W,excluded:tt(L,W,o)}}).sort((S,L)=>S.sanitized.localeCompare(L.sanitized,void 0,{sensitivity:"base"})),d=l.filter(S=>!S.excluded),s=t.hideExcludedFromList?d:l,u=new Map(l.filter(S=>S.id).map(S=>[S.id,S.original]));if(n!=null&&n.trim()){let S=n.trim();if(st(S)){let H=(V=(se=t.getRecentIds)==null?void 0:se.call(t))!=null?V:[],U=ce(H,u);(le=t.debugLog)==null||le.call(t,"recent list",{stored:H.length,resolved:U.length});let E=at(U);return I(A({},E),{items:U.map(q=>({id:q.id,name:q.name}))})}let L=lt(S);if(L!=null){let H=(z=(v=t.getRecentIds)==null?void 0:v.call(t))!=null?z:[],E=ce(H,u)[L-1];if(!E)return t.showToast(`No recent server in slot r${L}`,"danger"),{kind:"error",content:`No recent server in slot r${L}`};let q=u.get(E.id);return q?ct(t,q):(t.showToast("Could not resolve server id","danger"),{kind:"error",content:"Could not resolve server id"})}if(!d.length)return t.showToast("All servers are excluded","danger"),{kind:"error",content:"All servers are excluded"};let ae=_(t.aliases),W=Ye(S,ae),{matches:G,score:At}=Xe(W,d);if((j=t.debugLog)==null||j.call(t,"search",{normalizedQuery:W,score:At,matchCount:G.length}),G.length===0)return t.showToast("No match found","danger"),{kind:"error",content:`No match for \`${R(S)}\``};if(G.length>1){t.showToast(`${G.length} matches \u2014 refine your query`,"danger");let H=G.filter(E=>E.id).map(E=>({id:E.id,name:E.sanitized})),U=Je(S,G.map(E=>E.sanitized));return I(A({},U),{items:H,query:S})}return ct(t,G[0].original)}if(!s.length)return t.showToast("All servers are excluded","danger"),{kind:"error",content:"All servers are excluded"};let a=s.filter(S=>S.id).map(S=>({id:S.id,name:S.sanitized})),c=(Ue=(He=t.getRecentIds)==null?void 0:He.call(t))!=null?Ue:[],m=ce(c,u).map(S=>({id:S.id,name:S.name})),k=Ke(s.map(S=>S.sanitized),r);return r!=null?I(A({},k),{items:a,recentItems:m}):{kind:"switcher",content:k.content,items:a,recentItems:m,count:a.length}};var Yt=e=>e.flatMap(t=>{var n;return t.type==="folder"?(n=t.guilds)!=null?n:[]:[t]}),Xt=(e,t)=>Yt(e).map(n=>{let r=P(n),i=r?t(r):null;return{node:n,name:i?$(i):""}}).sort((n,r)=>n.name.localeCompare(r.name,void 0,{sensitivity:"base"})).map(n=>n.node),ve=()=>{let e=new WeakMap;return{clear(){e=new WeakMap},getOrCompute(t,n,r){let i=Qe(t,r),o=e.get(t);if((o==null?void 0:o.checksum)===i)return o.data;let l=n();return e.set(t,{checksum:i,data:l}),l}}},dt=(e,t,n,r)=>!t||!Array.isArray(e)?e:r.getOrCompute(e,()=>Xt(e,n),n);var y=je((vendetta.metro.common.React||window.React)),O=vendetta.metro,b=(vendetta.metro.common.ReactNative||window.ReactNative);var Te="quick-switcher-sheet",de="quick-switcher-top",gt="quick-switcher-simple",Ce=12,mt=8,Jt=(e,t=mt)=>Math.max(1,Math.ceil(Math.max(0,e)/t)),Kt=(e,t,n=mt)=>{let r=Jt(e.length,n),i=Math.min(Math.max(1,t),r),o=(i-1)*n;return{pageItems:e.slice(o,o+n),page:i,totalPages:r}},Zt=(e,t)=>{let n=t.trim().toLowerCase();return n?e.filter(r=>r.name.toLowerCase().includes(n)):e},K,Z,ee,D,te=()=>{if(K)return K;try{K=(0,O.findByProps)("openLazy","hideActionSheet")||(0,O.findByProps)("hideActionSheet")}catch(e){K=void 0}return K},ue=()=>{if(Z)return Z;try{Z=(0,O.findByProps)("openAlert","dismissAlert")}catch(e){Z=void 0}return Z},en=()=>{if(ee)return ee;try{ee=(0,O.findByProps)("hideActionSheet","showSimpleActionSheet")||(0,O.findByProps)("showSimpleActionSheet")}catch(e){ee=void 0}return ee},ke=()=>{var e,t,n,r,i,o,l,d,s,u;try{D==null||D()}catch(a){}D=void 0;try{(t=(e=ue())==null?void 0:e.dismissAlert)==null||t.call(e,de)}catch(a){}try{(r=(n=ue())==null?void 0:n.dismissAlert)==null||r.call(n)}catch(a){}try{(o=(i=te())==null?void 0:i.hideActionSheet)==null||o.call(i,Te)}catch(a){}try{(d=(l=te())==null?void 0:l.hideActionSheet)==null||d.call(l,gt)}catch(a){}try{(u=(s=te())==null?void 0:s.hideActionSheet)==null||u.call(s)}catch(a){}},ft=(e,t=200)=>{try{ke()}catch(n){}setTimeout(()=>{try{e()}catch(n){}},t)};var tn={text:"#DBDEE1",muted:"#A3A6AA",faint:"#80848E",panel:"#2B2D31",border:"#1E1F22",accent:"#5865F2"},pt=e=>{let[t,n]=y.default.useState(!0),[r,i]=y.default.useState(e.initialQuery||""),[o,l]=y.default.useState(1),d=y.default.useRef(!1),s=tn,u=e.recentItems||[],a=Zt(e.items,r),{pageItems:c,page:m,totalPages:k}=Kt(a,o);y.default.useEffect(()=>{l(1)},[r]);let B=y.default.useCallback(v=>{var z;if(!d.current){d.current=!0,n(!1);try{e.onRequestClose()}catch(j){}try{ke()}catch(j){}try{(z=e.onClose)==null||z.call(e)}catch(j){}v&&ft(v,200)}},[e.onRequestClose,e.onClose]),se=v=>{B(()=>e.onPick(v))};if(!t)return null;let V=(v,z)=>y.default.createElement(b.Pressable,{key:`${z}:${v.id}`,onPress:()=>se(v),style:{paddingVertical:12,paddingHorizontal:4,borderBottomWidth:1,borderBottomColor:s.border},accessibilityRole:"button",accessibilityLabel:`Jump to ${v.name}`},y.default.createElement(b.Text,{style:{color:s.text,fontSize:16}},v.name)),le=k>1?y.default.createElement(b.View,{style:{flexDirection:"row",alignItems:"center",justifyContent:"space-between",marginTop:10}},y.default.createElement(b.Pressable,{onPress:()=>l(v=>Math.max(1,v-1)),disabled:m<=1,style:{flex:1,marginRight:6,paddingVertical:10,borderRadius:8,backgroundColor:m<=1?"#3A3C41":s.accent,alignItems:"center",opacity:m<=1?.5:1},accessibilityRole:"button",accessibilityLabel:"Previous page"},y.default.createElement(b.Text,{style:{color:s.text,fontWeight:"600"}},"Previous")),y.default.createElement(b.Text,{style:{color:s.muted,fontSize:13,minWidth:72,textAlign:"center"}},m," / ",k),y.default.createElement(b.Pressable,{onPress:()=>l(v=>Math.min(k,v+1)),disabled:m>=k,style:{flex:1,marginLeft:6,paddingVertical:10,borderRadius:8,backgroundColor:m>=k?"#3A3C41":s.accent,alignItems:"center",opacity:m>=k?.5:1},accessibilityRole:"button",accessibilityLabel:"Next page"},y.default.createElement(b.Text,{style:{color:s.text,fontWeight:"600"}},"Next"))):null;return y.default.createElement(b.View,{pointerEvents:"box-none",style:{flex:1,justifyContent:"flex-start"}},y.default.createElement(b.View,{style:{marginTop:b.Platform.OS==="ios"?48:28,marginHorizontal:12,backgroundColor:s.panel,borderRadius:12,paddingHorizontal:14,paddingTop:12,paddingBottom:14,maxHeight:380,borderWidth:1,borderColor:s.border}},y.default.createElement(b.View,{style:{flexDirection:"row",alignItems:"center",marginBottom:4}},y.default.createElement(b.Text,{style:{color:s.text,fontSize:18,fontWeight:"700",flex:1}},e.title),y.default.createElement(b.Pressable,{onPress:()=>B(),accessibilityRole:"button",accessibilityLabel:"Close switcher",hitSlop:12,style:{paddingHorizontal:12,paddingVertical:8,borderRadius:8,backgroundColor:"#3A3C41"}},y.default.createElement(b.Text,{style:{color:s.text,fontSize:15,fontWeight:"600"}},"Close"))),e.subtitle?y.default.createElement(b.Text,{style:{color:s.muted,fontSize:13,marginBottom:10}},e.subtitle):null,y.default.createElement(b.TextInput,{value:r,onChangeText:i,placeholder:"Filter servers",placeholderTextColor:s.faint,autoFocus:!1,style:{backgroundColor:"#1E1F22",color:s.text,borderRadius:8,paddingHorizontal:12,paddingVertical:10,marginBottom:10}}),y.default.createElement(b.ScrollView,{keyboardShouldPersistTaps:"handled",style:{flexGrow:0},nestedScrollEnabled:!0},!r.trim()&&u.length>0&&m===1?y.default.createElement(b.View,{style:{marginBottom:10}},y.default.createElement(b.Text,{style:{color:s.muted,fontSize:11,fontWeight:"700",textTransform:"uppercase",marginBottom:4}},"Recent"),u.slice(0,5).map(v=>V(v,"recent"))):null,y.default.createElement(b.Text,{style:{color:s.muted,fontSize:11,fontWeight:"700",textTransform:"uppercase",marginBottom:4}},r.trim()?`Matches (${a.length})`:`Servers (${a.length}) \xB7 page ${m}/${k}`),c.length===0?y.default.createElement(b.Text,{style:{color:s.faint,paddingVertical:16}},"No servers match."):c.map(v=>V(v,"all"))),le))},nn=e=>{try{let t=ue();if(typeof(t==null?void 0:t.openAlert)!="function")return!1;let n=()=>{var r,i,o,l;try{(r=t.dismissAlert)==null||r.call(t,de)}catch(d){}try{(i=t.dismissAlert)==null||i.call(t)}catch(d){}try{(l=(o=te())==null?void 0:o.hideActionSheet)==null||l.call(o)}catch(d){}};return D=n,t.openAlert(de,y.default.createElement(pt,I(A({},e),{onRequestClose:n}))),!0}catch(t){return!1}},rn=e=>{try{let t=te();if(typeof(t==null?void 0:t.openLazy)!="function")return!1;let n=()=>{var i,o,l,d;try{(i=t.hideActionSheet)==null||i.call(t,Te)}catch(s){}try{(o=t.hideActionSheet)==null||o.call(t)}catch(s){}try{(d=(l=ue())==null?void 0:l.dismissAlert)==null||d.call(l,de)}catch(s){}};D=n;let r=i=>y.default.createElement(pt,I(A({},i),{onRequestClose:n}));return t.openLazy(Promise.resolve({default:r}),Te,e),!0}catch(t){return!1}},ut=(e,t,n)=>{try{let r=en(),i=r==null?void 0:r.showSimpleActionSheet;if(typeof i!="function"||t.length===0)return!1;let o=t.slice(0,Ce);return i({key:gt,header:{title:e,onClose:()=>ke()},options:o.map(l=>({label:l.name,onPress:()=>{ft(()=>n(l),120)}}))}),!0}catch(r){return!1}},on=e=>!!(nn(e)||rn(e)),ne=e=>{let t=!!e.preferSimple&&e.items.length>0&&e.items.length<=Ce;return t&&ut(e.title,e.items,e.onPick)?"simple":on(e)?"sheet":!t&&e.items.length>0&&e.items.length<=Ce&&ut(e.title,e.items,e.onPick)?"simple":null};var Ae=vendetta.metro,ge={textMuted:"#A3A6AA",textNormal:"#DBDEE1",textFaint:"#80848E",backgroundSecondary:"#2B2D31"},we,Ee,sn=()=>we!=null?we:we=(0,Ae.findByProps)("colors","unsafe_rawColors"),ln=()=>Ee!=null?Ee:Ee=(0,Ae.findByProps)("theme","darkTheme"),an=()=>{var t,n,r,i;let e=ln();return(i=(r=e==null?void 0:e.theme)!=null?r:(n=(t=e==null?void 0:e.getState)==null?void 0:t.call(e))==null?void 0:n.theme)!=null?i:"dark"},cn=(e,t)=>typeof e=="string"&&e.length>0?e:typeof e=="number"?`#${(e>>>0).toString(16).padStart(8,"0").slice(2)}`:t,me=(e,t)=>{var o,l,d;let n=sn(),r=(d=(o=n==null?void 0:n.meta)==null?void 0:o.resolveSemanticColor)!=null?d:(l=n==null?void 0:n.internal)==null?void 0:l.resolveSemanticColor;if(!r)return t;let i=an();for(let s of e)try{let u=r(i,s);if(u!=null&&u!=="")return cn(u,t)}catch(u){}return t},ht=()=>({textMuted:me(["HEADER_SECONDARY","TEXT_MUTED","INTERACTIVE_MUTED"],ge.textMuted),textNormal:me(["TEXT_NORMAL","HEADER_PRIMARY"],ge.textNormal),textFaint:me(["TEXT_MUTED","INTERACTIVE_MUTED"],ge.textFaint),backgroundSecondary:me(["BACKGROUND_SECONDARY","BG_BASE_SECONDARY","BACKGROUND_SECONDARY_ALT"],ge.backgroundSecondary)});var Ie,Le,Re,Me,Ne,ze,Ge,Pe,_e=()=>Ie!=null?Ie:Ie=(0,w.findByProps)("getGuild","getGuilds"),dn=()=>Le!=null?Le:Le=(0,w.findByProps)("getSortedGuilds"),Fe=()=>Re!=null?Re:Re=(0,w.findByProps)("setString","getString"),un=()=>Me!=null?Me:Me=(0,w.findByProps)("sendBotMessage"),gn=()=>Ne!=null?Ne:Ne=(0,w.findByProps)("getLastSelectedChannelId")||(0,w.findByProps)("getChannelId","getVoiceChannelId"),mn=()=>ze!=null?ze:ze=(0,w.findByProps)("getChannels","getDefaultChannel")||(0,w.findByProps)("getDefaultChannel"),fn=()=>Ge!=null?Ge:Ge=(0,w.findByProps)("getGuildId","getLastSelectedGuildId"),pn=()=>Pe!=null?Pe:Pe=(0,w.findByProps)("openUrl")||(0,w.findByProps)("openURL","openDeeplink")||(0,w.findByProps)("openURL"),yt=()=>{var e,t,n;try{return(n=(t=(e=fn())==null?void 0:e.getGuildId)==null?void 0:t.call(e))!=null?n:null}catch(r){return null}},fe=(e,t)=>{if(!e||!t)return;let n=un();if(n!=null&&n.sendBotMessage){n.sendBotMessage(e,t);return}if(n!=null&&n.sendMessage){n.sendMessage(e,{content:t},void 0,{nonce:Date.now().toString()});return}(0,h.showToast)("Could not post /servers reply in this channel","danger")},F="4.5.9",St=()=>{var e,t;try{g.storage.flatSidebar===void 0&&(g.storage.flatSidebar=!1),g.storage.aliases===void 0&&(g.storage.aliases=""),g.storage.debugLogging===void 0&&(g.storage.debugLogging=!1),g.storage.recentIds===void 0&&(g.storage.recentIds="[]"),g.storage.recentHistorySize===void 0&&(g.storage.recentHistorySize=X),g.storage.excludes===void 0&&(g.storage.excludes=""),g.storage.hideExcludedFromList===void 0&&(g.storage.hideExcludedFromList=!1)}catch(n){(t=(e=T.logger).error)==null||t.call(e,"Failed to initialize plugin storage",n)}},$e=ve(),bt=!1,M,re,xt=()=>{$e.clear(),$e=ve()},Et=80,C=[],vt=!1,hn=()=>{C.length=0;try{g.storage.debugLogText="",g.storage.debugLogPluginVersion=F}catch(e){}},oe=()=>{if(!vt){vt=!0;try{if(g.storage.debugLogPluginVersion!==F){hn();return}let e=g.storage.debugLogText;if(typeof e!="string"||!e.trim())return;let t=e.includes(` `)?e.split(` -`):e.split("");for(let n of t){let r=n.trim();!r||r.startsWith("Quick Server Switcher")||r.startsWith("lines=")||C.push(r)}for(;C.length>Et;)C.shift()}catch(e){}}},hn=()=>{try{u.storage.debugLogText=C.join(` -`),u.storage.debugLogPluginVersion=F}catch(e){}},yn=(e,...t)=>{try{re();let n=new Date().toISOString().slice(11,23),r=t.length===0?"":" "+t.map(i=>{try{return typeof i=="string"?i:JSON.stringify(i)}catch(o){return String(i)}}).join(" ");C.push(`[v${F} ${n}] ${e}${r}`),C.length>Et&&C.shift(),hn()}catch(n){}},Sn=()=>(re(),[`Quick Server Switcher debug log v${F}`,`lines=${C.length}`,...C].join(` -`)),bn=()=>{re();let e=`Quick Server Switcher debug log v${F} | lines=${C.length}`;return C.length===0?`${e} | (empty \u2014 open /servers or tap a server first)`:`${e} | ${C.join(" | ")}`},xn=()=>{var i,o;re();let e=He(),t=Sn(),n=bn(),r=!1;if(e!=null&&e.setString)try{e.setString(n),r=!0}catch(l){b("copyDebugLogs setString failed",String(l))}try{(o=(i=v.logger).info)==null||o.call(i,`[QuickSwitcher] debug dump -`+t)}catch(l){}if(r){let l=C.length>0?C[C.length-1]:"(empty)";(0,f.showToast)(`Copied ${C.length} line(s): ${l.slice(0,48)}`,"success");return}(0,f.showToast)("Clipboard unavailable \u2014 enable Debug Logging and check Revenge logs","danger")},b=(e,...t)=>{try{yn(e,...t);try{typeof v.logger.info=="function"?v.logger.info(`[QuickSwitcher] ${e}`,...t):u.storage.debugLogging&&v.logger.error(`[QuickSwitcher:debug] ${e}`,...t)}catch(n){}}catch(n){}},Tn=e=>{var r,i,o,l,g;let t=un(),n=((r=t==null?void 0:t.getLastSelectedChannelId)==null?void 0:r.call(t,e))||((i=t==null?void 0:t.getChannelId)==null?void 0:i.call(t,e))||null;if(n)return String(n);try{let s=gn(),d=(o=s==null?void 0:s.getDefaultChannel)==null?void 0:o.call(s,e);if(typeof d=="string"&&d)return d;if(d&&typeof d=="object"&&d.id)return String(d.id);let a=(l=s==null?void 0:s.getChannels)==null?void 0:l.call(s,e);if(Array.isArray(a)){let c=a.find(S=>S==null?void 0:S.id);if(c!=null&&c.id)return String(c.id)}else if(a&&typeof a=="object"){let c=a.SELECTABLE;if(Array.isArray(c))for(let S of c){let w=((g=S==null?void 0:S.channel)==null?void 0:g.id)||(S==null?void 0:S.id);if(w)return String(w)}}}catch(s){b("resolveChannelIdForGuild failed",String(s))}return null},ge=e=>{if(!e)return b("navigateToGuild missing id"),!1;let t=yt();if(t===e)return b("navigateToGuild already selected",{id:e}),!0;let n=Tn(e),r=pn(),i=typeof(r==null?void 0:r.openUrl)=="function"&&r.openUrl||typeof(r==null?void 0:r.openURL)=="function"&&r.openURL||null;if(b("navigateToGuild",{id:e,before:t,channelId:n,hasOpenUrl:!!i}),!n)return b("navigateToGuild no channel for guild",{id:e}),!1;if(!i)return b("navigateToGuild openUrl module missing"),!1;let o=`https://discord.com/channels/${e}/${n}`;try{i(o);let l=yt();return b("navigateToGuild openUrl ok",{href:o,after:l}),l===e?b("navigateToGuild verified",{label:"openUrl",after:l}):b("navigateToGuild openUrl accepted (async)",{after:l,expected:e}),!0}catch(l){return b("navigateToGuild openUrl failed",String(l)),!1}},ne=()=>et(u.storage.recentIds),me=e=>{var n;let t=tt(ne(),e,(n=u.storage.recentHistorySize)!=null?n:X);u.storage.recentIds=ye(t),b("recordRecent",{id:e,size:t.length})},vn=()=>{u.storage.recentIds="[]",(0,f.showToast)("Recent history cleared","success"),b("clearRecentHistory")},Cn=()=>{let e=He();if(!(e!=null&&e.setString)){(0,f.showToast)("Clipboard unavailable on this client","danger");return}let t=Ye(u.storage.aliases||"");if(!t){(0,f.showToast)("No aliases to copy","danger");return}e.setString(t),b("exported aliases",{count:fe(t)}),(0,f.showToast)(`Copied ${fe(t)} alias(es)`,"success")},kn=()=>De(null,null,function*(){let e=He();if(!(e!=null&&e.getString)){(0,f.showToast)("Clipboard unavailable on this client","danger");return}try{let t=yield e.getString();if(!(t!=null&&t.trim())){(0,f.showToast)("Clipboard is empty","danger");return}let n=Xe(u.storage.aliases||"",t);if(n.imported===0){(0,f.showToast)(n.skipped>0?"No valid alias lines on clipboard":"Clipboard is empty","danger");return}u.storage.aliases=n.text,b("imported aliases",n);let r=n.skipped>0?` (${n.skipped} skipped)`:"";(0,f.showToast)(`Imported ${n.imported}; ${n.total} total${r}`,"success")}catch(t){v.logger.error(t),(0,f.showToast)("Could not read clipboard","danger")}}),wn=(e,t)=>{var n,r,i,o,l,g;try{try{(r=(n=v.logger).info)==null||r.call(n,"[QuickSwitcher] command invoke",Array.isArray(e)?e.map(c=>c&&typeof c=="object"?{name:c.name,value:c.value,keys:Object.keys(c)}:c):e)}catch(c){}b("command invoke",e);let s={ok:!1},d=c=>{b("jumpToItem",{id:c.id,name:c.name}),s.ok=ge(c.id),s.ok?(me(c.id),(0,f.showToast)(`Jumped to ${c.name}`,"success")):(0,f.showToast)("Could not navigate to server","danger")},a=Se(e,{getGuilds:()=>{var c;return Object.values(((c=Ge())==null?void 0:c.getGuilds())||{}).map(S=>{var w;return H(G({},S),{name:(w=S.name)!=null?w:""})})},aliases:u.storage.aliases||"",navigateToGuild:c=>{s.ok=ge(c),s.ok||(0,f.showToast)("Could not navigate to server","danger")},showToast:f.showToast,debugLog:b,getRecentIds:ne,recordRecent:me,excludes:u.storage.excludes||"",hideExcludedFromList:!!u.storage.hideExcludedFromList});if(!a||typeof a!="object"){(0,f.showToast)("No /servers output \u2014 use the query or page options from the slash menu","danger");return}if(a.kind==="switcher"&&Array.isArray(a.items)&&a.items.length>0){let c=ee({title:"Quick Server Switcher",subtitle:`${a.items.length} servers \xB7 tap to jump`,items:a.items,recentItems:Array.isArray(a.recentItems)?a.recentItems:[],onPick:d});if(c){b("opened switcher UI",c);return}typeof a.content=="string"&&ue((i=t==null?void 0:t.channel)==null?void 0:i.id,a.content);return}if(a.kind==="pick-list"&&Array.isArray(a.items)&&a.items.length>0){let c="query"in a&&typeof a.query=="string"?a.query:"your query",S=ee({title:`Matches for \u201C${c}\u201D`,subtitle:"Tap a server to jump",items:a.items,preferSimple:!0,onPick:d});if(S){b("opened pick UI",S);return}typeof a.content=="string"&&ue((o=t==null?void 0:t.channel)==null?void 0:o.id,a.content);return}if(a.kind==="recent-list"&&Array.isArray(a.items)&&a.items.length>0){let c=ee({title:"Recent servers",subtitle:"Tap to jump \xB7 history from this plugin only",items:a.items,preferSimple:a.items.length<=12,onPick:d});if(c){b("opened recent UI",c);return}}if("content"in a&&typeof a.content=="string"){let c=a.content;"kind"in a&&a.kind==="jump"&&!s.ok&&(c=`${c} -_(navigation API unavailable \u2014 enable Debug Logging and check logs)_`),ue((l=t==null?void 0:t.channel)==null?void 0:l.id,c);return}(0,f.showToast)("No /servers output \u2014 use the query or page options from the slash menu","danger")}catch(s){v.logger.error(s),(0,f.showToast)("Something went wrong running /servers","danger");try{ue((g=t==null?void 0:t.channel)==null?void 0:g.id,`Quick Switcher error: ${String(s)}`)}catch(d){}}},En=()=>{var e,t;try{let n=Se({},{getGuilds:()=>{var r;return Object.values(((r=Ge())==null?void 0:r.getGuilds())||{}).map(i=>{var o;return H(G({},i),{name:(o=i.name)!=null?o:""})})},aliases:u.storage.aliases||"",navigateToGuild:r=>{ge(r)||(0,f.showToast)("Could not navigate to server","danger")},showToast:f.showToast,debugLog:b,getRecentIds:ne,recordRecent:me,excludes:u.storage.excludes||"",hideExcludedFromList:!!u.storage.hideExcludedFromList});if(n&&n.kind==="switcher"&&Array.isArray(n.items)&&ee({title:"Quick Server Switcher",subtitle:`${n.items.length} servers \xB7 tap to jump`,items:n.items,recentItems:Array.isArray(n.recentItems)?n.recentItems:[],onPick:i=>{ge(i.id)?(me(i.id),(0,f.showToast)(`Jumped to ${i.name}`,"success")):(0,f.showToast)("Could not navigate to server","danger")}}))return;(0,f.showToast)("Switcher sheet unavailable on this client","danger")}catch(n){(t=(e=v.logger).error)==null||t.call(e,n),(0,f.showToast)("Could not open switcher","danger")}},An=()=>{var e,t,n;try{let r=(e=wt.Forms)==null?void 0:e.FormSwitchRow;if(r)return r}catch(r){(n=(t=v.logger).error)==null||n.call(t,"FormSwitchRow unavailable",r)}return({label:r,value:i,onValueChange:o})=>p.default.createElement(m.Pressable,{onPress:()=>o(!i),style:{marginHorizontal:16,marginVertical:8,paddingVertical:10},accessibilityRole:"button",accessibilityLabel:r},p.default.createElement(m.Text,{style:{color:"#DBDEE1",fontWeight:"600"}},r,": ",i?"On":"Off"," (tap to toggle)"))},In={settings:()=>{var o,l,g;St(),(0,kt.useProxy)(u.storage);let e=ht(),t=An(),n=Y(u.storage.recentHistorySize),r=ne().length,i={flex:1,marginHorizontal:4,paddingVertical:10,borderRadius:8,backgroundColor:e.backgroundSecondary,alignItems:"center"};return p.default.createElement(m.ScrollView,null,p.default.createElement(m.View,{style:{flexDirection:"row",marginHorizontal:12,marginTop:8,marginBottom:8}},p.default.createElement(m.Pressable,{style:i,onPress:En,accessibilityRole:"button",accessibilityLabel:"Open server switcher"},p.default.createElement(m.Text,{style:{color:e.textNormal,fontWeight:"600"}},"Open switcher")),p.default.createElement(m.Pressable,{style:i,onPress:xn,accessibilityRole:"button",accessibilityLabel:"Copy debug logs"},p.default.createElement(m.Text,{style:{color:e.textNormal,fontWeight:"600"}},"Copy debug logs"))),p.default.createElement(t,{label:"Flat Sidebar",value:(o=u.storage.flatSidebar)!=null?o:!1,onValueChange:s=>{u.storage.flatSidebar=s,xt(),b("flatSidebar toggled",s),(0,f.showToast)(`Sidebar set to ${s?"Flat":"Standard"}`)}}),p.default.createElement(t,{label:"Debug Logging",value:(l=u.storage.debugLogging)!=null?l:!1,onValueChange:s=>{u.storage.debugLogging=s,(0,f.showToast)(`Debug logging ${s?"on":"off"}`),s&&b("debug logging enabled")}}),p.default.createElement(t,{label:"Hide excluded from /servers list",value:(g=u.storage.hideExcludedFromList)!=null?g:!1,onValueChange:s=>{u.storage.hideExcludedFromList=s,(0,f.showToast)(s?"Excluded servers hidden from list":"Excluded servers shown in list")}}),p.default.createElement(m.Text,{style:{marginHorizontal:16,marginTop:16,color:e.textMuted,fontWeight:"bold",textTransform:"uppercase",fontSize:12}},"Excluded servers"),p.default.createElement(m.Text,{style:{marginHorizontal:16,marginTop:4,color:e.textFaint,fontSize:12}},Ke()),p.default.createElement(m.TextInput,{style:{margin:16,marginBottom:8,padding:12,backgroundColor:e.backgroundSecondary,color:e.textNormal,borderRadius:8,textAlignVertical:"top"},multiline:!0,numberOfLines:3,placeholder:`Wayland Parents +`):e.split("");for(let n of t){let r=n.trim();!r||r.startsWith("Quick Server Switcher")||r.startsWith("lines=")||C.push(r)}for(;C.length>Et;)C.shift()}catch(e){}}},yn=()=>{try{g.storage.debugLogText=C.join(` +`),g.storage.debugLogPluginVersion=F}catch(e){}},Sn=(e,...t)=>{try{oe();let n=new Date().toISOString().slice(11,23),r=t.length===0?"":" "+t.map(i=>{try{return typeof i=="string"?i:JSON.stringify(i)}catch(o){return String(i)}}).join(" ");C.push(`[v${F} ${n}] ${e}${r}`),C.length>Et&&C.shift(),yn()}catch(n){}},bn=()=>(oe(),[`Quick Server Switcher debug log v${F}`,`lines=${C.length}`,...C].join(` +`)),xn=()=>{oe();let e=`Quick Server Switcher debug log v${F} | lines=${C.length}`;return C.length===0?`${e} | (empty \u2014 open /servers or tap a server first)`:`${e} | ${C.join(" | ")}`},vn=()=>{var i,o;oe();let e=Fe(),t=bn(),n=xn(),r=!1;if(e!=null&&e.setString)try{e.setString(n),r=!0}catch(l){x("copyDebugLogs setString failed",String(l))}try{(o=(i=T.logger).info)==null||o.call(i,`[QuickSwitcher] debug dump +`+t)}catch(l){}if(r){let l=C.length>0?C[C.length-1]:"(empty)";(0,h.showToast)(`Copied ${C.length} line(s): ${l.slice(0,48)}`,"success");return}(0,h.showToast)("Clipboard unavailable \u2014 enable Debug Logging and check Revenge logs","danger")},x=(e,...t)=>{try{Sn(e,...t);try{typeof T.logger.info=="function"?T.logger.info(`[QuickSwitcher] ${e}`,...t):g.storage.debugLogging&&T.logger.error(`[QuickSwitcher:debug] ${e}`,...t)}catch(n){}}catch(n){}},Tn=e=>{var r,i,o,l,d;let t=gn(),n=((r=t==null?void 0:t.getLastSelectedChannelId)==null?void 0:r.call(t,e))||((i=t==null?void 0:t.getChannelId)==null?void 0:i.call(t,e))||null;if(n)return String(n);try{let s=mn(),u=(o=s==null?void 0:s.getDefaultChannel)==null?void 0:o.call(s,e);if(typeof u=="string"&&u)return u;if(u&&typeof u=="object"&&u.id)return String(u.id);let a=(l=s==null?void 0:s.getChannels)==null?void 0:l.call(s,e);if(Array.isArray(a)){let c=a.find(m=>m==null?void 0:m.id);if(c!=null&&c.id)return String(c.id)}else if(a&&typeof a=="object"){let c=a.SELECTABLE;if(Array.isArray(c))for(let m of c){let k=((d=m==null?void 0:m.channel)==null?void 0:d.id)||(m==null?void 0:m.id);if(k)return String(k)}}}catch(s){x("resolveChannelIdForGuild failed",String(s))}return null},pe=e=>{if(!e)return x("navigateToGuild missing id"),!1;let t=yt();if(t===e)return x("navigateToGuild already selected",{id:e}),!0;let n=Tn(e),r=pn(),i=typeof(r==null?void 0:r.openUrl)=="function"&&r.openUrl||typeof(r==null?void 0:r.openURL)=="function"&&r.openURL||null;if(x("navigateToGuild",{id:e,before:t,channelId:n,hasOpenUrl:!!i}),!n)return x("navigateToGuild no channel for guild",{id:e}),!1;if(!i)return x("navigateToGuild openUrl module missing"),!1;let o=`https://discord.com/channels/${e}/${n}`;try{i(o);let l=yt();return x("navigateToGuild openUrl ok",{href:o,after:l}),l===e?x("navigateToGuild verified",{label:"openUrl",after:l}):x("navigateToGuild openUrl accepted (async)",{after:l,expected:e}),!0}catch(l){return x("navigateToGuild openUrl failed",String(l)),!1}},ie=()=>it(g.storage.recentIds),he=e=>{var n;let t=ot(ie(),e,(n=g.storage.recentHistorySize)!=null?n:X);g.storage.recentIds=be(t),x("recordRecent",{id:e,size:t.length})},Cn=()=>{g.storage.recentIds="[]",(0,h.showToast)("Recent history cleared","success"),x("clearRecentHistory")},kn=()=>{let e=Fe();if(!(e!=null&&e.setString)){(0,h.showToast)("Clipboard unavailable on this client","danger");return}let t=Ze(g.storage.aliases||"");if(!t){(0,h.showToast)("No aliases to copy","danger");return}e.setString(t),x("exported aliases",{count:ye(t)}),(0,h.showToast)(`Copied ${ye(t)} alias(es)`,"success")},wn=()=>We(null,null,function*(){let e=Fe();if(!(e!=null&&e.getString)){(0,h.showToast)("Clipboard unavailable on this client","danger");return}try{let t=yield e.getString();if(!(t!=null&&t.trim())){(0,h.showToast)("Clipboard is empty","danger");return}let n=et(g.storage.aliases||"",t);if(n.imported===0){(0,h.showToast)(n.skipped>0?"No valid alias lines on clipboard":"Clipboard is empty","danger");return}g.storage.aliases=n.text,x("imported aliases",n);let r=n.skipped>0?` (${n.skipped} skipped)`:"";(0,h.showToast)(`Imported ${n.imported}; ${n.total} total${r}`,"success")}catch(t){T.logger.error(t),(0,h.showToast)("Could not read clipboard","danger")}}),En=(e,t)=>{var n,r,i,o,l,d;try{try{(r=(n=T.logger).info)==null||r.call(n,"[QuickSwitcher] command invoke",Array.isArray(e)?e.map(c=>c&&typeof c=="object"?{name:c.name,value:c.value,keys:Object.keys(c)}:c):e)}catch(c){}x("command invoke",e);let s={ok:!1},u=c=>{x("jumpToItem",{id:c.id,name:c.name}),s.ok=pe(c.id),s.ok?(he(c.id),(0,h.showToast)(`Jumped to ${c.name}`,"success")):(0,h.showToast)("Could not navigate to server","danger")},a=xe(e,{getGuilds:()=>{var c;return Object.values(((c=_e())==null?void 0:c.getGuilds())||{}).map(m=>{var k;return I(A({},m),{name:(k=m.name)!=null?k:""})})},aliases:g.storage.aliases||"",navigateToGuild:c=>{s.ok=pe(c),s.ok||(0,h.showToast)("Could not navigate to server","danger")},showToast:h.showToast,debugLog:x,getRecentIds:ie,recordRecent:he,excludes:g.storage.excludes||"",hideExcludedFromList:!!g.storage.hideExcludedFromList});if(!a||typeof a!="object"){(0,h.showToast)("No /servers output \u2014 use the query or page options from the slash menu","danger");return}if(a.kind==="switcher"&&Array.isArray(a.items)&&a.items.length>0){let c=ne({title:"Quick Server Switcher",subtitle:`${a.items.length} servers \xB7 tap to jump`,items:a.items,recentItems:Array.isArray(a.recentItems)?a.recentItems:[],onPick:u});if(c){x("opened switcher UI",c);return}typeof a.content=="string"&&fe((i=t==null?void 0:t.channel)==null?void 0:i.id,a.content);return}if(a.kind==="pick-list"&&Array.isArray(a.items)&&a.items.length>0){let c="query"in a&&typeof a.query=="string"?a.query:"your query",m=ne({title:`Matches for \u201C${c}\u201D`,subtitle:"Tap a server to jump",items:a.items,preferSimple:!0,onPick:u});if(m){x("opened pick UI",m);return}typeof a.content=="string"&&fe((o=t==null?void 0:t.channel)==null?void 0:o.id,a.content);return}if(a.kind==="recent-list"&&Array.isArray(a.items)&&a.items.length>0){let c=ne({title:"Recent servers",subtitle:"Tap to jump \xB7 history from this plugin only",items:a.items,preferSimple:a.items.length<=12,onPick:u});if(c){x("opened recent UI",c);return}}if("content"in a&&typeof a.content=="string"){let c=a.content;"kind"in a&&a.kind==="jump"&&!s.ok&&(c=`${c} +_(navigation API unavailable \u2014 enable Debug Logging and check logs)_`),fe((l=t==null?void 0:t.channel)==null?void 0:l.id,c);return}(0,h.showToast)("No /servers output \u2014 use the query or page options from the slash menu","danger")}catch(s){T.logger.error(s),(0,h.showToast)("Something went wrong running /servers","danger");try{fe((d=t==null?void 0:t.channel)==null?void 0:d.id,`Quick Switcher error: ${String(s)}`)}catch(u){}}},An=()=>{var e,t;try{let n=xe({},{getGuilds:()=>{var r;return Object.values(((r=_e())==null?void 0:r.getGuilds())||{}).map(i=>{var o;return I(A({},i),{name:(o=i.name)!=null?o:""})})},aliases:g.storage.aliases||"",navigateToGuild:r=>{pe(r)||(0,h.showToast)("Could not navigate to server","danger")},showToast:h.showToast,debugLog:x,getRecentIds:ie,recordRecent:he,excludes:g.storage.excludes||"",hideExcludedFromList:!!g.storage.hideExcludedFromList});if(n&&n.kind==="switcher"&&Array.isArray(n.items)&&ne({title:"Quick Server Switcher",subtitle:`${n.items.length} servers \xB7 tap to jump`,items:n.items,recentItems:Array.isArray(n.recentItems)?n.recentItems:[],onPick:i=>{pe(i.id)?(he(i.id),(0,h.showToast)(`Jumped to ${i.name}`,"success")):(0,h.showToast)("Could not navigate to server","danger")}}))return;(0,h.showToast)("Switcher sheet unavailable on this client","danger")}catch(n){(t=(e=T.logger).error)==null||t.call(e,n),(0,h.showToast)("Could not open switcher","danger")}},In=()=>{var e,t,n;try{let r=(e=wt.Forms)==null?void 0:e.FormSwitchRow;if(r)return r}catch(r){(n=(t=T.logger).error)==null||n.call(t,"FormSwitchRow unavailable",r)}return({label:r,value:i,onValueChange:o})=>p.default.createElement(f.Pressable,{onPress:()=>o(!i),style:{marginHorizontal:16,marginVertical:8,paddingVertical:10},accessibilityRole:"button",accessibilityLabel:r},p.default.createElement(f.Text,{style:{color:"#DBDEE1",fontWeight:"600"}},r,": ",i?"On":"Off"," (tap to toggle)"))},Ln={settings:()=>{var o,l,d;St(),(0,kt.useProxy)(g.storage);let e=ht(),t=In(),n=Y(g.storage.recentHistorySize),r=ie().length,i={flex:1,marginHorizontal:4,paddingVertical:10,borderRadius:8,backgroundColor:e.backgroundSecondary,alignItems:"center"};return p.default.createElement(f.ScrollView,null,p.default.createElement(f.View,{style:{flexDirection:"row",marginHorizontal:12,marginTop:8,marginBottom:8}},p.default.createElement(f.Pressable,{style:i,onPress:An,accessibilityRole:"button",accessibilityLabel:"Open server switcher"},p.default.createElement(f.Text,{style:{color:e.textNormal,fontWeight:"600"}},"Open switcher")),p.default.createElement(f.Pressable,{style:i,onPress:vn,accessibilityRole:"button",accessibilityLabel:"Copy debug logs"},p.default.createElement(f.Text,{style:{color:e.textNormal,fontWeight:"600"}},"Copy debug logs"))),p.default.createElement(t,{label:"Flat Sidebar",value:(o=g.storage.flatSidebar)!=null?o:!1,onValueChange:s=>{g.storage.flatSidebar=s,xt(),x("flatSidebar toggled",s),(0,h.showToast)(`Sidebar set to ${s?"Flat":"Standard"}`)}}),p.default.createElement(t,{label:"Debug Logging",value:(l=g.storage.debugLogging)!=null?l:!1,onValueChange:s=>{g.storage.debugLogging=s,(0,h.showToast)(`Debug logging ${s?"on":"off"}`),s&&x("debug logging enabled")}}),p.default.createElement(t,{label:"Hide excluded from /servers list",value:(d=g.storage.hideExcludedFromList)!=null?d:!1,onValueChange:s=>{g.storage.hideExcludedFromList=s,(0,h.showToast)(s?"Excluded servers hidden from list":"Excluded servers shown in list")}}),p.default.createElement(f.Text,{style:{marginHorizontal:16,marginTop:16,color:e.textMuted,fontWeight:"bold",textTransform:"uppercase",fontSize:12}},"Excluded servers"),p.default.createElement(f.Text,{style:{marginHorizontal:16,marginTop:4,color:e.textFaint,fontSize:12}},rt()),p.default.createElement(f.TextInput,{style:{margin:16,marginBottom:8,padding:12,backgroundColor:e.backgroundSecondary,color:e.textNormal,borderRadius:8,textAlignVertical:"top"},multiline:!0,numberOfLines:3,placeholder:`Wayland Parents ~spam -123456789012345678`,placeholderTextColor:e.textFaint,value:u.storage.excludes||"",onChangeText:s=>{u.storage.excludes=s}}),p.default.createElement(m.Text,{style:{marginHorizontal:16,marginBottom:8,color:e.textFaint,fontSize:12}},Ze(u.storage.excludes||"")," active rule(s) \xB7 always skipped by search"),p.default.createElement(m.Text,{style:{marginHorizontal:16,marginTop:16,color:e.textMuted,fontWeight:"bold",textTransform:"uppercase",fontSize:12}},"Recent servers"),p.default.createElement(m.Text,{style:{marginHorizontal:16,marginTop:4,color:e.textFaint,fontSize:12}},"Recorded only when this plugin jumps you. Use /servers recent or /servers r1."),p.default.createElement(m.Text,{style:{marginHorizontal:16,marginTop:12,color:e.textFaint,fontSize:12}},"History size (1\u201315)"),p.default.createElement(m.TextInput,{style:{marginHorizontal:16,marginTop:4,marginBottom:8,padding:12,backgroundColor:e.backgroundSecondary,color:e.textNormal,borderRadius:8},keyboardType:"number-pad",value:String(n),onChangeText:s=>{let d=s.replace(/[^\d]/g,"");if(!d){u.storage.recentHistorySize=X;return}let a=Y(parseInt(d,10));u.storage.recentHistorySize=a,u.storage.recentIds=ye(ne().slice(0,a))}}),p.default.createElement(m.Text,{style:{marginHorizontal:16,marginBottom:8,color:e.textFaint,fontSize:12}},r," stored \xB7 shrinking the size trims oldest entries"),p.default.createElement(m.View,{style:{flexDirection:"row",marginHorizontal:12,marginBottom:8}},p.default.createElement(m.Pressable,{style:i,onPress:vn,accessibilityRole:"button",accessibilityLabel:"Clear recent server history"},p.default.createElement(m.Text,{style:{color:e.textNormal,fontWeight:"600"}},"Clear recent"))),p.default.createElement(m.Text,{style:{marginHorizontal:16,marginTop:16,color:e.textMuted,fontWeight:"bold",textTransform:"uppercase",fontSize:12}},"Custom Aliases (alias=server)"),p.default.createElement(m.Text,{style:{marginHorizontal:16,marginTop:4,color:e.textFaint,fontSize:12}},"One per line. Only the first = separates alias from target."),p.default.createElement(m.TextInput,{style:{margin:16,marginBottom:8,padding:12,backgroundColor:e.backgroundSecondary,color:e.textNormal,borderRadius:8,textAlignVertical:"top"},multiline:!0,numberOfLines:4,placeholder:`chess=Maynard -wow=World of Warcraft`,placeholderTextColor:e.textFaint,value:u.storage.aliases||"",onChangeText:s=>{u.storage.aliases=s}}),p.default.createElement(m.View,{style:{flexDirection:"row",marginHorizontal:12,marginBottom:16}},p.default.createElement(m.Pressable,{style:i,onPress:Cn,accessibilityRole:"button",accessibilityLabel:"Copy aliases to clipboard"},p.default.createElement(m.Text,{style:{color:e.textNormal,fontWeight:"600"}},"Copy")),p.default.createElement(m.Pressable,{style:i,onPress:()=>{kn()},accessibilityRole:"button",accessibilityLabel:"Import aliases from clipboard"},p.default.createElement(m.Text,{style:{color:e.textNormal,fontWeight:"600"}},"Import"))),p.default.createElement(m.Text,{style:{marginHorizontal:16,marginBottom:24,color:e.textFaint,fontSize:12}},"Copy exports normalized aliases. Import merges from the clipboard (imported names win on duplicates)."))},onLoad(){var e,t;try{St(),re(),b("onLoad",{version:F})}catch(n){try{(t=(e=v.logger).error)==null||t.call(e,"Quick Switcher onLoad init failed",n)}catch(r){}}try{try{R==null||R()}catch(n){}R=void 0,R=(0,Ct.registerCommand)({name:"servers",description:"List or jump to servers (fuzzy search, recent, pages)",applicationId:"-1",type:1,inputType:0,displayName:"servers",displayDescription:"List or jump to servers (fuzzy search, recent, pages)",options:[{name:"query",type:3,description:"Search, page number, recent, or r1",displayName:"query",displayDescription:"Search, page number, recent, or r1",required:!1},{name:"page",type:4,description:"Go to a specific page",displayName:"page",displayDescription:"Go to a specific page",required:!1}],execute:wn})}catch(n){try{v.logger.error("Failed to register /servers command",n),(0,f.showToast)("Quick Switcher loaded, but /servers failed to register","danger")}catch(r){}}try{let n=cn();n?(b("patching getSortedGuilds"),te=(0,vt.after)("getSortedGuilds",n,(r,i)=>{let o=Ge();return st(i,!!u.storage.flatSidebar,l=>{var s;let g=o==null?void 0:o.getGuild(l);return(s=g==null?void 0:g.name)!=null?s:null},ze)})):u.storage.flatSidebar&&!bt?(bt=!0,v.logger.error("Flat sidebar enabled but SortedGuildStore was not found"),(0,f.showToast)("Flat sidebar unavailable on this client","danger")):b("SortedGuildStore not found; flat sidebar patch skipped")}catch(n){try{v.logger.error("Failed to patch flat sidebar",n)}catch(r){}}try{(0,f.showToast)("Quick Server Switcher loaded")}catch(n){}},onUnload(){try{b("onUnload")}catch(e){}try{R==null||R()}catch(e){try{v.logger.error("Failed to unregister /servers",e)}catch(t){}}R=void 0;try{te==null||te()}catch(e){try{v.logger.error("Failed to unpatch sidebar",e)}catch(t){}}te=void 0;try{xt()}catch(e){}}},Ln=In; +123456789012345678`,placeholderTextColor:e.textFaint,value:g.storage.excludes||"",onChangeText:s=>{g.storage.excludes=s}}),p.default.createElement(f.Text,{style:{marginHorizontal:16,marginBottom:8,color:e.textFaint,fontSize:12}},nt(g.storage.excludes||"")," active rule(s) \xB7 always skipped by search"),p.default.createElement(f.Text,{style:{marginHorizontal:16,marginTop:16,color:e.textMuted,fontWeight:"bold",textTransform:"uppercase",fontSize:12}},"Recent servers"),p.default.createElement(f.Text,{style:{marginHorizontal:16,marginTop:4,color:e.textFaint,fontSize:12}},"Recorded only when this plugin jumps you. Use /servers recent or /servers r1."),p.default.createElement(f.Text,{style:{marginHorizontal:16,marginTop:12,color:e.textFaint,fontSize:12}},"History size (1\u201315)"),p.default.createElement(f.TextInput,{style:{marginHorizontal:16,marginTop:4,marginBottom:8,padding:12,backgroundColor:e.backgroundSecondary,color:e.textNormal,borderRadius:8},keyboardType:"number-pad",value:String(n),onChangeText:s=>{let u=s.replace(/[^\d]/g,"");if(!u){g.storage.recentHistorySize=X;return}let a=Y(parseInt(u,10));g.storage.recentHistorySize=a,g.storage.recentIds=be(ie().slice(0,a))}}),p.default.createElement(f.Text,{style:{marginHorizontal:16,marginBottom:8,color:e.textFaint,fontSize:12}},r," stored \xB7 shrinking the size trims oldest entries"),p.default.createElement(f.View,{style:{flexDirection:"row",marginHorizontal:12,marginBottom:8}},p.default.createElement(f.Pressable,{style:i,onPress:Cn,accessibilityRole:"button",accessibilityLabel:"Clear recent server history"},p.default.createElement(f.Text,{style:{color:e.textNormal,fontWeight:"600"}},"Clear recent"))),p.default.createElement(f.Text,{style:{marginHorizontal:16,marginTop:16,color:e.textMuted,fontWeight:"bold",textTransform:"uppercase",fontSize:12}},"Custom Aliases (alias=server)"),p.default.createElement(f.Text,{style:{marginHorizontal:16,marginTop:4,color:e.textFaint,fontSize:12}},"One per line. Only the first = separates alias from target."),p.default.createElement(f.TextInput,{style:{margin:16,marginBottom:8,padding:12,backgroundColor:e.backgroundSecondary,color:e.textNormal,borderRadius:8,textAlignVertical:"top"},multiline:!0,numberOfLines:4,placeholder:`chess=Maynard +wow=World of Warcraft`,placeholderTextColor:e.textFaint,value:g.storage.aliases||"",onChangeText:s=>{g.storage.aliases=s}}),p.default.createElement(f.View,{style:{flexDirection:"row",marginHorizontal:12,marginBottom:16}},p.default.createElement(f.Pressable,{style:i,onPress:kn,accessibilityRole:"button",accessibilityLabel:"Copy aliases to clipboard"},p.default.createElement(f.Text,{style:{color:e.textNormal,fontWeight:"600"}},"Copy")),p.default.createElement(f.Pressable,{style:i,onPress:()=>{wn()},accessibilityRole:"button",accessibilityLabel:"Import aliases from clipboard"},p.default.createElement(f.Text,{style:{color:e.textNormal,fontWeight:"600"}},"Import"))),p.default.createElement(f.Text,{style:{marginHorizontal:16,marginBottom:24,color:e.textFaint,fontSize:12}},"Copy exports normalized aliases. Import merges from the clipboard (imported names win on duplicates)."))},onLoad(){var e,t;try{St(),oe(),x("onLoad",{version:F})}catch(n){try{(t=(e=T.logger).error)==null||t.call(e,"Quick Switcher onLoad init failed",n)}catch(r){}}try{try{M==null||M()}catch(n){}M=void 0,M=(0,Ct.registerCommand)({name:"servers",description:"List or jump to servers (fuzzy search, recent, pages)",applicationId:"-1",type:1,inputType:0,displayName:"servers",displayDescription:"List or jump to servers (fuzzy search, recent, pages)",options:[{name:"query",type:3,description:"Search, page number, recent, or r1",displayName:"query",displayDescription:"Search, page number, recent, or r1",required:!1},{name:"page",type:4,description:"Go to a specific page",displayName:"page",displayDescription:"Go to a specific page",required:!1}],execute:En})}catch(n){try{T.logger.error("Failed to register /servers command",n),(0,h.showToast)("Quick Switcher loaded, but /servers failed to register","danger")}catch(r){}}try{let n=dn();n?(x("patching getSortedGuilds"),re=(0,Tt.after)("getSortedGuilds",n,(r,i)=>{let o=_e();return dt(i,!!g.storage.flatSidebar,l=>{var s;let d=o==null?void 0:o.getGuild(l);return(s=d==null?void 0:d.name)!=null?s:null},$e)})):g.storage.flatSidebar&&!bt?(bt=!0,T.logger.error("Flat sidebar enabled but SortedGuildStore was not found"),(0,h.showToast)("Flat sidebar unavailable on this client","danger")):x("SortedGuildStore not found; flat sidebar patch skipped")}catch(n){try{T.logger.error("Failed to patch flat sidebar",n)}catch(r){}}try{(0,h.showToast)("Quick Server Switcher loaded")}catch(n){}},onUnload(){try{x("onUnload")}catch(e){}try{M==null||M()}catch(e){try{T.logger.error("Failed to unregister /servers",e)}catch(t){}}M=void 0;try{re==null||re()}catch(e){try{T.logger.error("Failed to unpatch sidebar",e)}catch(t){}}re=void 0;try{xt()}catch(e){}}},Rn=Ln; var _exp=module.exports; var _plugin=(_exp&&_exp.__esModule&&_exp.default!=null)?_exp.default:(_exp&&_exp.default!=null?_exp.default:_exp); diff --git a/manifest.json b/manifest.json index c9bdf6b..8488fc9 100644 --- a/manifest.json +++ b/manifest.json @@ -8,6 +8,6 @@ } ], "main": "dist/index.js", - "version": "4.5.8", - "hash": "376e77875fb7284228e74cf9d2e480dcd79ac59af9efb4c1498b3e6894da189a" + "version": "4.5.9", + "hash": "70a041b5fea42d25ea48892b65aee133601253e6996ae1951c27db1e926adbf0" } diff --git a/package.json b/package.json index 666aacf..97440ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "revenge-quick-switcher", - "version": "4.5.8", + "version": "4.5.9", "main": "dist/index.js", "scripts": { "build": "node scripts/build.mjs", diff --git a/src/index.tsx b/src/index.tsx index 213d863..093d8d6 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -137,7 +137,7 @@ const postCommandReply = (channelId: string | undefined, content: string) => { /** Injected at build time from package.json; keep fallback in sync when bumping. */ const PLUGIN_VERSION = - typeof __QSS_VERSION__ !== "undefined" && __QSS_VERSION__ ? __QSS_VERSION__ : "4.5.8"; + typeof __QSS_VERSION__ !== "undefined" && __QSS_VERSION__ ? __QSS_VERSION__ : "4.5.9"; const ensureStorageDefaults = () => { try { diff --git a/src/sheets.tsx b/src/sheets.tsx index 4d8a19f..f502909 100644 --- a/src/sheets.tsx +++ b/src/sheets.tsx @@ -1,6 +1,7 @@ import React from "react"; import { findByProps } from "@revenge-mod/metro"; import { + Platform, Pressable, ScrollView, TextInput, @@ -28,6 +29,11 @@ type LazyActionSheetHost = { hideActionSheet?: (key?: string) => void; }; +type AlertHost = { + openAlert?: (key: string, element: React.ReactElement) => void; + dismissAlert?: (key?: string) => void; +}; + type SimpleActionSheetApi = { showSimpleActionSheet?: (opts: { key: string; @@ -36,32 +42,12 @@ type SimpleActionSheetApi = { }) => void; }; -type ActionSheetModule = { - ActionSheet?: React.ComponentType<{ children?: React.ReactNode; scrollable?: boolean }>; -}; - -type TitleHeaderModule = { - ActionSheetTitleHeader?: React.ComponentType<{ - title: string; - subtitle?: string; - trailing?: React.ReactNode; - }>; - BottomSheetTitleHeader?: React.ComponentType<{ - title: string; - trailing?: React.ReactNode; - }>; -}; - -type CloseButtonModule = { - ActionSheetCloseButton?: React.ComponentType<{ onPress?: () => void }>; -}; - const SHEET_KEY = "quick-switcher-sheet"; +const ALERT_KEY = "quick-switcher-top"; const SIMPLE_KEY = "quick-switcher-simple"; -/** Keep simple sheets short — Discord’s native simple sheet auto-dismisses on press. */ const MAX_SIMPLE_OPTIONS = 12; -/** Rows per page in the native ActionSheet body. */ +/** Rows per page — keeps the top panel short enough to sit above the keyboard. */ export const SHEET_PAGE_SIZE = 8; export const sheetPageCount = (itemCount: number, pageSize = SHEET_PAGE_SIZE) => @@ -89,11 +75,9 @@ export const filterSwitcherItems = (items: SwitcherItem[], query: string) => { }; let _lazySheet: LazyActionSheetHost | undefined; +let _alertHost: AlertHost | undefined; let _simpleSheet: SimpleActionSheetApi | undefined; -let _ActionSheet: React.ComponentType<{ children?: React.ReactNode; scrollable?: boolean }> | undefined; -let _TitleHeader: React.ComponentType<{ title: string; subtitle?: string; trailing?: React.ReactNode }> | undefined; -let _CloseButton: React.ComponentType<{ onPress?: () => void }> | undefined; -let _lookedUpNative = false; +let _activeClose: (() => void) | undefined; const getLazyActionSheet = () => { if (_lazySheet) return _lazySheet; @@ -107,6 +91,16 @@ const getLazyActionSheet = () => { return _lazySheet; }; +const getAlertHost = () => { + if (_alertHost) return _alertHost; + try { + _alertHost = findByProps("openAlert", "dismissAlert") as AlertHost | undefined; + } catch { + _alertHost = undefined; + } + return _alertHost; +}; + const getSimpleActionSheet = () => { if (_simpleSheet) return _simpleSheet; try { @@ -120,43 +114,27 @@ const getSimpleActionSheet = () => { }; /** - * Resolve Discord’s native ActionSheet pieces the way Stealmoji / Bunny plugins do. - * Custom Views opened via openLazy WITHOUT this wrapper leave a touch-blocking shell - * after hideActionSheet + openUrl (device QA v4.5.6–4.5.7). + * Dismiss every known host. Stealmoji/JumpTo always hideActionSheet before follow-ups; + * top-docked UI also needs dismissAlert (v4.5.6–4.5.7 dead-tap QA). */ -const ensureNativeSheetParts = () => { - if (_lookedUpNative) return; - _lookedUpNative = true; +export const hideSwitcherSheet = () => { try { - const sheetMod = findByProps("ActionSheet") as ActionSheetModule | undefined; - _ActionSheet = sheetMod?.ActionSheet; + _activeClose?.(); } catch { /* ignore */ } + _activeClose = undefined; + try { - const titleMod = findByProps("ActionSheetTitleHeader") as TitleHeaderModule | undefined; - _TitleHeader = titleMod?.ActionSheetTitleHeader; + getAlertHost()?.dismissAlert?.(ALERT_KEY); } catch { /* ignore */ } - if (!_TitleHeader) { - try { - const bottom = findByProps("BottomSheetTitleHeader") as TitleHeaderModule | undefined; - _TitleHeader = bottom?.BottomSheetTitleHeader; - } catch { - /* ignore */ - } - } try { - const closeMod = findByProps("ActionSheetCloseButton") as CloseButtonModule | undefined; - _CloseButton = closeMod?.ActionSheetCloseButton; + getAlertHost()?.dismissAlert?.(); } catch { /* ignore */ } -}; - -/** Hide Discord’s LazyActionSheet host (JumpTo / Stealmoji / Bunny). */ -export const hideSwitcherSheet = () => { try { getLazyActionSheet()?.hideActionSheet?.(SHEET_KEY); } catch { @@ -175,10 +153,10 @@ export const hideSwitcherSheet = () => { }; /** - * Stealmoji / JumpTo pattern: hideActionSheet first, then run the action. - * Never navigate while a custom overlay is still mounted. + * Stealmoji / JumpTo pattern: dismiss host first, then run the action. + * Never call openUrl while an overlay is still mounted. */ -export const dismissThenRun = (action: () => void, delayMs = 160) => { +export const dismissThenRun = (action: () => void, delayMs = 200) => { try { hideSwitcherSheet(); } catch { @@ -193,7 +171,7 @@ export const dismissThenRun = (action: () => void, delayMs = 160) => { }, delayMs); }; -/** @deprecated use dismissThenRun — kept for callers that imported the old name */ +/** @deprecated use dismissThenRun */ export const runAfterSwitcherDismissed = dismissThenRun; const COLORS = { @@ -206,12 +184,24 @@ const COLORS = { }; /** - * Body rendered INSIDE Discord’s native ActionSheet (Stealmoji AddToServer pattern). - * Do not use a full-screen flex:1 overlay or openAlert — those leave dead taps after jump. + * Top-docked searchable panel (v4.5.1 keyboard fix). + * + * Hosted by openAlert so it sits at the top of the screen — bottom ActionSheets + * are covered by the Android keyboard (v4.5.8 screenshot). + * + * Critical vs broken v4.5.6 overlay: + * - No full-screen Pressable scrim + * - Outer container pointerEvents="box-none" (no leftover touch sink) + * - Pick path: hide/dismiss first, then onPick → openUrl (Stealmoji) + * - TextInput never autoFocus (keyboard only when user taps Filter) */ -const SwitcherSheetBody: React.ComponentType = (sheetProps) => { +export const SwitcherTopPanel: React.ComponentType< + SwitcherSheetProps & { onRequestClose: () => void } +> = (sheetProps) => { + const [visible, setVisible] = React.useState(true); const [query, setQuery] = React.useState(sheetProps.initialQuery || ""); const [page, setPage] = React.useState(1); + const closedRef = React.useRef(false); const colors = COLORS; const recent = sheetProps.recentItems || []; @@ -222,55 +212,46 @@ const SwitcherSheetBody: React.ComponentType = (sheetProps) setPage(1); }, [query]); - const pick = (item: SwitcherItem) => { - // Match Stealmoji: hideActionSheet before the follow-up action. - dismissThenRun(() => { + const finishClose = React.useCallback( + (after?: () => void) => { + if (closedRef.current) return; + closedRef.current = true; + setVisible(false); + try { + sheetProps.onRequestClose(); + } catch { + /* ignore */ + } + try { + hideSwitcherSheet(); + } catch { + /* ignore */ + } try { sheetProps.onClose?.(); } catch { /* ignore */ } - sheetProps.onPick(item); - }); - }; + if (after) { + dismissThenRun(after, 200); + } + }, + [sheetProps.onRequestClose, sheetProps.onClose] + ); - const closeOnly = () => { - hideSwitcherSheet(); - try { - sheetProps.onClose?.(); - } catch { - /* ignore */ - } + const pick = (item: SwitcherItem) => { + finishClose(() => sheetProps.onPick(item)); }; - ensureNativeSheetParts(); - const ActionSheet = _ActionSheet; - const TitleHeader = _TitleHeader; - const CloseButton = _CloseButton; - - const header = - TitleHeader && CloseButton ? ( - } - /> - ) : ( - - {sheetProps.title} - - Close - - - ); + if (!visible) return null; const row = (item: SwitcherItem, keyPrefix: string) => ( pick(item)} style={{ - paddingVertical: 14, - paddingHorizontal: 16, + paddingVertical: 12, + paddingHorizontal: 4, borderBottomWidth: 1, borderBottomColor: colors.border, }} @@ -281,131 +262,231 @@ const SwitcherSheetBody: React.ComponentType = (sheetProps) ); - const body = ( - <> - {header} - {sheetProps.subtitle && !TitleHeader ? ( - - {sheetProps.subtitle} - - ) : null} - 1 ? ( + - - {!query.trim() && recent.length > 0 && safePage === 1 ? ( - - - Recent - - {recent.slice(0, 5).map((item) => row(item, "recent"))} - - ) : null} - + setPage((p) => Math.max(1, p - 1))} + disabled={safePage <= 1} style={{ - color: colors.muted, - fontSize: 11, - fontWeight: "700", - textTransform: "uppercase", - paddingHorizontal: 16, - marginBottom: 4, + flex: 1, + marginRight: 6, + paddingVertical: 10, + borderRadius: 8, + backgroundColor: safePage <= 1 ? "#3A3C41" : colors.accent, + alignItems: "center", + opacity: safePage <= 1 ? 0.5 : 1, }} + accessibilityRole="button" + accessibilityLabel="Previous page" > - {query.trim() - ? `Matches (${filtered.length})` - : `Servers (${filtered.length}) · page ${safePage}/${totalPages}`} + Previous + + + {safePage} / {totalPages} - {pageItems.length === 0 ? ( - No servers match. - ) : ( - pageItems.map((item) => row(item, "all")) - )} - - {totalPages > 1 ? ( - setPage((p) => Math.min(totalPages, p + 1))} + disabled={safePage >= totalPages} style={{ - flexDirection: "row", + flex: 1, + marginLeft: 6, + paddingVertical: 10, + borderRadius: 8, + backgroundColor: safePage >= totalPages ? "#3A3C41" : colors.accent, alignItems: "center", - justifyContent: "space-between", - paddingHorizontal: 16, - paddingVertical: 12, - paddingBottom: 20, + opacity: safePage >= totalPages ? 0.5 : 1, }} + accessibilityRole="button" + accessibilityLabel="Next page" > + Next + + + ) : null; + + // Top-aligned panel only — no full-bleed flex:1 touch sink under the keyboard. + return ( + + + + + {sheetProps.title} + setPage((p) => Math.max(1, p - 1))} - disabled={safePage <= 1} + onPress={() => finishClose()} + accessibilityRole="button" + accessibilityLabel="Close switcher" + hitSlop={12} style={{ - flex: 1, - marginRight: 6, - paddingVertical: 10, + paddingHorizontal: 12, + paddingVertical: 8, borderRadius: 8, - backgroundColor: safePage <= 1 ? "#3A3C41" : colors.accent, - alignItems: "center", - opacity: safePage <= 1 ? 0.5 : 1, + backgroundColor: "#3A3C41", }} - accessibilityRole="button" - accessibilityLabel="Previous page" > - Previous + Close - - {safePage} / {totalPages} - - setPage((p) => Math.min(totalPages, p + 1))} - disabled={safePage >= totalPages} + + {sheetProps.subtitle ? ( + {sheetProps.subtitle} + ) : null} + + + {!query.trim() && recent.length > 0 && safePage === 1 ? ( + + + Recent + + {recent.slice(0, 5).map((item) => row(item, "recent"))} + + ) : null} + = totalPages ? "#3A3C41" : colors.accent, - alignItems: "center", - opacity: safePage >= totalPages ? 0.5 : 1, + color: colors.muted, + fontSize: 11, + fontWeight: "700", + textTransform: "uppercase", + marginBottom: 4, }} - accessibilityRole="button" - accessibilityLabel="Next page" > - Next - - - ) : ( - - )} - + {query.trim() + ? `Matches (${filtered.length})` + : `Servers (${filtered.length}) · page ${safePage}/${totalPages}`} + + {pageItems.length === 0 ? ( + No servers match. + ) : ( + pageItems.map((item) => row(item, "all")) + )} + + {pager} + + ); +}; + +/** Top-docked via openAlert — stays above the Android keyboard. */ +const openViaAlert = (props: SwitcherSheetProps): boolean => { + try { + const host = getAlertHost(); + if (typeof host?.openAlert !== "function") return false; + + const close = () => { + try { + host.dismissAlert?.(ALERT_KEY); + } catch { + /* ignore */ + } + try { + host.dismissAlert?.(); + } catch { + /* ignore */ + } + try { + getLazyActionSheet()?.hideActionSheet?.(); + } catch { + /* ignore */ + } + }; + _activeClose = close; + + host.openAlert!( + ALERT_KEY, + React.createElement(SwitcherTopPanel, { + ...props, + onRequestClose: close, + }) + ); + return true; + } catch { + return false; + } +}; + +/** Fallback: LazyActionSheet with the same top panel body (no ActionSheet chrome). */ +const openViaLazy = (props: SwitcherSheetProps): boolean => { + try { + const host = getLazyActionSheet(); + if (typeof host?.openLazy !== "function") return false; + + const close = () => { + try { + host.hideActionSheet?.(SHEET_KEY); + } catch { + /* ignore */ + } + try { + host.hideActionSheet?.(); + } catch { + /* ignore */ + } + try { + getAlertHost()?.dismissAlert?.(ALERT_KEY); + } catch { + /* ignore */ + } + }; + _activeClose = close; - if (ActionSheet) { - return {body}; + const Sheet: React.ComponentType = (sheetProps) => ( + + ); + + host.openLazy!(Promise.resolve({ default: Sheet }), SHEET_KEY, props); + return true; + } catch { + return false; } - // Last resort: still open via LazyActionSheet but without ActionSheet chrome. - return {body}; }; -/** Native Discord simple sheet — auto-dismisses on option press (JumpTo-adjacent). */ export const openSimplePickSheet = ( title: string, items: SwitcherItem[], @@ -426,7 +507,6 @@ export const openSimplePickSheet = ( options: limited.map((item) => ({ label: item.name, onPress: () => { - // Native simple sheet usually dismisses itself; still hide + delay like Stealmoji. dismissThenRun(() => onPick(item), 120); }, })), @@ -437,24 +517,13 @@ export const openSimplePickSheet = ( } }; -/** Full searchable switcher inside Discord’s LazyActionSheet + ActionSheet. */ +/** Prefer top-docked alert (keyboard-safe); fall back to LazyActionSheet. */ export const openSwitcherSheet = (props: SwitcherSheetProps): boolean => { - try { - ensureNativeSheetParts(); - const host = getLazyActionSheet(); - if (typeof host?.openLazy !== "function") return false; - - host.openLazy!(Promise.resolve({ default: SwitcherSheetBody }), SHEET_KEY, props); - return true; - } catch { - return false; - } + if (openViaAlert(props)) return true; + if (openViaLazy(props)) return true; + return false; }; -/** - * Prefer native ActionSheet host; use simple sheet for short lists. - * Never use openAlert — device QA showed leftover touch-blocking shells. - */ export const openSwitcherUi = ( props: SwitcherSheetProps & { preferSimple?: boolean } ): "sheet" | "simple" | null => {