levix-bot 4.6.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/views/qr.ejs CHANGED
@@ -1,25 +1,26 @@
1
1
  <!DOCTYPE html>
2
- <html lang="en" data-theme="dark">
2
+ <html data-brand="<%= brand.name %>">
3
3
  <head>
4
+ <script src="/ui-boot.js"></script>
4
5
  <meta charset="UTF-8" />
5
6
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
- <title><%= brand.name %> · Link WhatsApp</title>
7
+ <title data-i18n="titleQr"><%= brand.name %> · Link WhatsApp</title>
7
8
  <link rel="icon" type="image/png" sizes="32x32" href="/brand/icon-32.png" />
8
9
  <link rel="apple-touch-icon" href="/brand/apple-touch-icon.png" />
9
10
  <link rel="stylesheet" href="/dashboard.css" />
10
11
  </head>
11
12
  <body class="gateway-page">
12
13
  <main class="gateway-shell">
13
- <section class="gateway-story" aria-label="About <%= brand.name %>">
14
+ <section class="gateway-story" aria-label="About <%= brand.name %>" data-i18n-aria-label="storyAbout">
14
15
  <div class="brand-lockup" aria-label="<%= brand.name %>">
15
16
  <img src="/brand/mark.svg" alt="" />
16
- <span><strong><%= brand.name %></strong><small><%= brand.tagline %></small></span>
17
+ <span><strong><%= brand.name %></strong><small data-i18n="tagline"><%= brand.tagline %></small></span>
17
18
  </div>
18
19
 
19
20
  <div class="gateway-copy">
20
- <span class="eyebrow">A direct line</span>
21
- <h2>Bring your assistant online.</h2>
22
- <p>One scan securely links Levix to the WhatsApp account you choose.</p>
21
+ <span class="eyebrow" data-i18n="directLine">A direct line</span>
22
+ <h2 data-i18n="qrHeadline">Bring your assistant online.</h2>
23
+ <p data-i18n="qrLede">One scan securely links Levix to the WhatsApp account you choose.</p>
23
24
  </div>
24
25
 
25
26
  <div class="gateway-mark" aria-hidden="true">
@@ -27,7 +28,7 @@
27
28
  <img src="/brand/mark.svg" alt="" />
28
29
  </div>
29
30
 
30
- <p class="gateway-trust"><span></span> Live pairing status</p>
31
+ <p class="gateway-trust" data-i18n-html="qrTrust"><span></span> Live pairing status</p>
31
32
  </section>
32
33
 
33
34
  <section class="gateway-panel">
@@ -35,46 +36,53 @@
35
36
  <div class="card auth-card qr-card">
36
37
  <div class="card-head qr-card-head">
37
38
  <div>
38
- <span class="eyebrow">Link device</span>
39
- <h1>Scan with WhatsApp</h1>
39
+ <span class="eyebrow" data-i18n="linkDevice">Link device</span>
40
+ <h1 data-i18n="qrScanTitle">Scan with WhatsApp</h1>
40
41
  </div>
41
- <span class="pill" id="state"><span class="dot"></span>Waiting…</span>
42
+ <span class="pill" id="state"><span class="dot"></span><span data-i18n="qrWaiting">Waiting…</span></span>
42
43
  </div>
43
44
 
44
45
  <div class="qr-box">
45
46
  <div class="qr-frame" id="frame"></div>
46
47
  <ol class="steps">
47
- <li><span>Open</span> WhatsApp on the phone the bot should use.</li>
48
- <li><span>Choose</span> Settings → Linked devices → Link a device.</li>
49
- <li><span>Scan</span> the code shown above.</li>
48
+ <li data-i18n-html="qrStep1"><span>Open</span> WhatsApp on the phone the bot should use.</li>
49
+ <li data-i18n-html="qrStep2"><span>Choose</span> Settings → Linked devices → Link a device.</li>
50
+ <li data-i18n-html="qrStep3"><span>Scan</span> the code shown above.</li>
50
51
  </ol>
51
52
  <div class="callout compact-callout">
52
53
  <span class="callout-icon" aria-hidden="true">i</span>
53
- <p>No code yet? Press <strong>Start session</strong> on the dashboard's Connection screen.</p>
54
+ <p data-i18n-html="qrCallout">No code yet? Press <strong>Start session</strong> on the dashboard's Connection screen.</p>
54
55
  </div>
55
56
  </div>
56
57
 
57
58
  <a class="btn qr-back" href="/">
58
59
  <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M19 12H5M11 6l-6 6 6 6"/></svg>
59
- Back to dashboard
60
+ <span data-i18n="backToDashboard">Back to dashboard</span>
60
61
  </a>
61
62
  </div>
62
63
 
63
- <div class="foot"><%= brand.name %> by <%= brand.developer %> · <%= brand.studio %></div>
64
+ <div class="foot"><%= brand.name %> <span data-i18n="by">by</span> <%= brand.developer %> · <%= brand.studio %></div>
64
65
  </div>
65
66
  </section>
66
67
  </main>
67
68
 
69
+ <script src="/gateway-i18n.js"></script>
68
70
  <script src="/socket.io.min.js"></script>
69
71
  <script src="/qrcode.min.js"></script>
70
72
  <script>
71
73
  (() => {
74
+ const getT = () => (window.LevixGatewayI18n ? window.LevixGatewayI18n.t : (k) => k);
72
75
  const frame = document.getElementById("frame");
73
76
  const state = document.getElementById("state");
74
77
  let painted = null;
78
+ let currentStatusKey = "qrWaiting";
79
+ let currentStatusKind = "";
80
+ let isLinked = false;
75
81
 
76
- function setState(text, kind) {
77
- state.className = `pill ${kind || ""}`;
82
+ function setState(text, kind, key) {
83
+ if (key) currentStatusKey = key;
84
+ currentStatusKind = kind || "";
85
+ state.className = `pill ${currentStatusKind}`;
78
86
  state.innerHTML = `<span class="dot"></span>${text}`;
79
87
  }
80
88
 
@@ -88,37 +96,58 @@
88
96
  height: 250,
89
97
  correctLevel: QRCode.CorrectLevel.H,
90
98
  });
91
- setState("Scan me", "");
99
+ setState(getT()("qrScanMe"), "", "qrScanMe");
92
100
  }
93
101
 
94
102
  // The QR the server already had when this page was rendered.
95
103
  const initial = <%- JSON.stringify(qr || "") %>;
96
104
  if (initial) render(initial);
97
- else setState("Waiting for a code…", "");
105
+ else setState(getT()("qrWaitingCode"), "", "qrWaitingCode");
98
106
 
99
- function clear(text, kind) {
107
+ function clear(text, kind, key) {
100
108
  painted = null;
101
109
  frame.innerHTML = "";
102
- setState(text, kind || "");
110
+ setState(text, kind || "", key);
103
111
  }
104
112
 
113
+ function repaint() {
114
+ if (currentStatusKey) {
115
+ setState(getT()(currentStatusKey), currentStatusKind, currentStatusKey);
116
+ }
117
+ if (isLinked) {
118
+ frame.innerHTML = `<div class="qr-success">${getT()("qrLinked")}</div>`;
119
+ }
120
+ }
121
+
122
+ window.addEventListener("levix-gateway-lang", repaint);
123
+ window.addEventListener("levix-ui-prefs", repaint);
124
+ window.addEventListener("storage", (e) => {
125
+ if (e.key === "levix_lang") repaint();
126
+ });
127
+
105
128
  const socket = io();
106
129
  socket.on("qr", render);
107
130
 
108
131
  // The backend drops a code the moment it stops being scannable. Without
109
132
  // this the page sat on an expired QR forever, and somebody would keep
110
133
  // pointing a phone at it.
111
- socket.on("qr_cleared", () => clear("Waiting for a code…", ""));
134
+ socket.on("qr_cleared", () => {
135
+ isLinked = false;
136
+ clear(getT()("qrWaitingCode"), "", "qrWaitingCode");
137
+ });
112
138
 
113
- socket.on("session", (state) => {
114
- if (state.state === "connected") {
115
- frame.innerHTML = '<div class="qr-success">Linked ✓</div>';
139
+ socket.on("session", (s) => {
140
+ if (s.state === "connected") {
141
+ isLinked = true;
142
+ frame.innerHTML = `<div class="qr-success">${getT()("qrLinked")}</div>`;
116
143
  painted = null;
117
- setState("Connected", "on");
144
+ setState(getT()("qrConnected"), "on", "qrConnected");
118
145
  return;
119
146
  }
120
- if (state.state === "waiting_for_qr") return; // the qr event paints it
121
- clear(state.canStart ? "Not started — start it from the dashboard" : "Connecting…", "");
147
+ isLinked = false;
148
+ if (s.state === "waiting_for_qr") return; // the qr event paints it
149
+ const key = s.canStart ? "qrNotStarted" : "qrConnecting";
150
+ clear(getT()(key), "", key);
122
151
  });
123
152
  })();
124
153
  </script>
package/views/setup.ejs CHANGED
@@ -1,25 +1,26 @@
1
1
  <!DOCTYPE html>
2
- <html lang="en" data-theme="dark">
2
+ <html data-brand="<%= brand.name %>">
3
3
  <head>
4
+ <script src="/ui-boot.js"></script>
4
5
  <meta charset="UTF-8" />
5
6
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
- <title><%= brand.name %> · First run</title>
7
+ <title data-i18n="titleSetup"><%= brand.name %> · First run</title>
7
8
  <link rel="icon" type="image/png" sizes="32x32" href="/brand/icon-32.png" />
8
9
  <link rel="apple-touch-icon" href="/brand/apple-touch-icon.png" />
9
10
  <link rel="stylesheet" href="/dashboard.css" />
10
11
  </head>
11
12
  <body class="gateway-page">
12
13
  <main class="gateway-shell">
13
- <section class="gateway-story" aria-label="About <%= brand.name %>">
14
+ <section class="gateway-story" aria-label="About <%= brand.name %>" data-i18n-aria-label="storyAbout">
14
15
  <div class="brand-lockup" aria-label="<%= brand.name %>">
15
16
  <img src="/brand/mark.svg" alt="" />
16
- <span><strong><%= brand.name %></strong><small><%= brand.tagline %></small></span>
17
+ <span><strong><%= brand.name %></strong><small data-i18n="tagline"><%= brand.tagline %></small></span>
17
18
  </div>
18
19
 
19
20
  <div class="gateway-copy">
20
- <span class="eyebrow">Your first minute</span>
21
- <h2>Make the workspace yours.</h2>
22
- <p>Choose one strong password, then manage the assistant from a single private control room.</p>
21
+ <span class="eyebrow" data-i18n="firstMinute">Your first minute</span>
22
+ <h2 data-i18n="setupHeadline">Make the workspace yours.</h2>
23
+ <p data-i18n="setupLede">Choose one strong password, then manage the assistant from a single private control room.</p>
23
24
  </div>
24
25
 
25
26
  <div class="gateway-mark" aria-hidden="true">
@@ -27,7 +28,7 @@
27
28
  <img src="/brand/mark.svg" alt="" />
28
29
  </div>
29
30
 
30
- <p class="gateway-trust"><span></span> One setup · no configuration files</p>
31
+ <p class="gateway-trust" data-i18n-html="setupTrust"><span></span> One setup · no configuration files</p>
31
32
  </section>
32
33
 
33
34
  <section class="gateway-panel">
@@ -35,30 +36,33 @@
35
36
  <form class="card auth-card setup-card" action="/setup" method="post">
36
37
  <button type="button" class="gateway-back-btn" id="setup-back-app" hidden>
37
38
  <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
38
- <span>Back to app</span>
39
+ <span data-i18n="backToApp">Back to app</span>
39
40
  </button>
40
41
  <div class="auth-head">
41
- <span class="eyebrow">Create your workspace</span>
42
- <h1>Welcome to <%= brand.name %></h1>
43
- <p class="sub">Protect the linked WhatsApp account with at least <%= minLength %> characters.</p>
42
+ <span class="eyebrow" data-i18n="createWorkspace">Create your workspace</span>
43
+ <h1 data-i18n="setupWelcome">Welcome to <%= brand.name %></h1>
44
+ <p class="sub" data-i18n="setupSub">Protect the linked WhatsApp account with at least <%= minLength %> characters.</p>
44
45
  </div>
45
46
 
46
47
  <% if (needsCode) { %>
47
48
  <label class="field">
48
- <span>Setup code</span>
49
+ <span data-i18n="setupCodeLabel">Setup code</span>
49
50
  <input type="text" name="code" autocomplete="off" autofocus required
50
- placeholder="Printed in the bot's terminal" />
51
- <small>Confirms you can access the server running Levix.</small>
51
+ placeholder="Printed in the bot's terminal"
52
+ data-i18n-placeholder="setupCodePlaceholder" />
53
+ <small data-i18n="setupCodeHint">Confirms you can access the server running Levix.</small>
52
54
  </label>
53
55
  <% } %>
54
56
 
55
57
  <label class="field">
56
- <span>Password</span>
58
+ <span data-i18n="setupPasswordLabel">Password</span>
57
59
  <div class="input-wrap">
58
- <input type="password" name="password" autocomplete="new-password"
60
+ <input type="password" dir="ltr" spellcheck="false" autocapitalize="off" autocorrect="off" name="password" autocomplete="new-password"
59
61
  placeholder="At least <%= minLength %> characters"
62
+ data-i18n-placeholder="minLengthPlaceholder"
63
+ data-i18n-n="<%= minLength %>"
60
64
  minlength="<%= minLength %>" <%= needsCode ? "" : "autofocus" %> required />
61
- <button type="button" class="eye-btn" aria-label="Show password">
65
+ <button type="button" class="eye-btn" aria-label="Show password" data-i18n-aria-label="showPassword" aria-pressed="false">
62
66
  <svg class="eye-on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
63
67
  <svg class="eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c6.5 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3.5 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
64
68
  </button>
@@ -66,11 +70,13 @@
66
70
  </label>
67
71
 
68
72
  <label class="field">
69
- <span>Repeat password</span>
73
+ <span data-i18n="repeatPassword">Repeat password</span>
70
74
  <div class="input-wrap">
71
- <input type="password" name="confirm" autocomplete="new-password"
72
- placeholder="Type it again" minlength="<%= minLength %>" required />
73
- <button type="button" class="eye-btn" aria-label="Show password">
75
+ <input type="password" dir="ltr" spellcheck="false" autocapitalize="off" autocorrect="off" name="confirm" autocomplete="new-password"
76
+ placeholder="Type it again"
77
+ data-i18n-placeholder="repeatPlaceholder"
78
+ minlength="<%= minLength %>" required />
79
+ <button type="button" class="eye-btn" aria-label="Show password" data-i18n-aria-label="showPassword" aria-pressed="false">
74
80
  <svg class="eye-on" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7Z"/><circle cx="12" cy="12" r="3"/></svg>
75
81
  <svg class="eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" style="display:none"><path d="M9.88 9.88a3 3 0 1 0 4.24 4.24"/><path d="M10.73 5.08A10.43 10.43 0 0 1 12 5c6.5 0 10 7 10 7a13.16 13.16 0 0 1-1.67 2.68"/><path d="M6.61 6.61A13.526 13.526 0 0 0 2 12s3.5 7 10 7a9.74 9.74 0 0 0 5.39-1.61"/><line x1="2" x2="22" y1="2" y2="22"/></svg>
76
82
  </button>
@@ -78,33 +84,31 @@
78
84
  </label>
79
85
 
80
86
  <button type="submit" class="btn btn-primary auth-submit">
81
- Create workspace
87
+ <span data-i18n="createWorkspaceBtn">Create workspace</span>
82
88
  <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12h14M13 6l6 6-6 6"/></svg>
83
89
  </button>
84
90
 
85
91
  <% if (error) { %>
86
- <div class="error" role="alert"><%= error %></div>
92
+ <div class="error" role="alert" data-i18n-error="<%= errorCode %>" data-i18n-n="<%= minLength %>"><%= error %></div>
87
93
  <% } %>
88
94
  </form>
89
95
 
90
- <div class="foot"><%= brand.name %> by <%= brand.developer %> · <%= brand.studio %></div>
96
+ <div class="foot"><%= brand.name %> <span data-i18n="by">by</span> <%= brand.developer %> · <%= brand.studio %></div>
91
97
  </div>
92
98
  </section>
93
99
  </main>
94
100
 
101
+ <script src="/gateway-i18n.js"></script>
95
102
  <script src="/gateway.js"></script>
96
103
  <script>
97
104
  (function () {
105
+ // Android app: show the back-to-app button. Its label is already in
106
+ // whichever language the page loaded in.
98
107
  var inApp = typeof window.LevixHost !== "undefined" && typeof window.LevixHost.closePanel === "function";
99
108
  if (inApp) {
100
- var isAr = false;
101
- try { isAr = localStorage.getItem("levix_lang") === "ar"; } catch(e) {}
102
- var backLabel = isAr ? "العودة للتطبيق" : "Back to app";
103
109
  var btn = document.getElementById("setup-back-app");
104
110
  if (btn) {
105
111
  btn.hidden = false;
106
- btn.querySelector("span").textContent = backLabel;
107
- if (isAr) { btn.dir = "rtl"; btn.style.direction = "rtl"; }
108
112
  btn.addEventListener("click", function() { window.LevixHost.closePanel(); });
109
113
  }
110
114
  }