-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathApp.svelte
More file actions
632 lines (606 loc) · 19.2 KB
/
App.svelte
File metadata and controls
632 lines (606 loc) · 19.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
<script lang="ts">
import { onMount } from "svelte";
import { emit, listen } from "@tauri-apps/api/event";
import { getVersion } from "@tauri-apps/api/app";
import Link from "./Link.svelte";
import Preview from "./Preview.svelte";
let deviceMode = "none";
let outputMode = "none";
let ledMode = "none";
let disableAirStrings = false;
let divaSerialPort = "COM1";
let divaBrightness = 63;
let brokenithmPort = 1606;
let keyboardSensitivity = 20;
let keyboardDirectInput = false;
let outputPolling = "100";
let outputWebsocketUrl = "http://localhost:3000";
let ledFaster = false;
let ledColorActive = "#ff00ff";
let ledColorInactive = "#ffff00";
let ledColorAirActive = "#0086ed";
let ledColorAirInactive = "#000000";
let ledSensitivity = 20;
let ledWebsocketUrl = "http://localhost:3001";
let ledUmgrWebsocketPort = 7124;
let ledSerialPort = "COM5";
let dirty = false;
function markDirty() {
dirty = true;
}
// let debugstr = "";
let versionString = "";
let ips: Array<string> = [];
let polling = null;
let tick = 0;
let previewData = Array(131).fill(0);
let timerData = "";
function updatePolling(enabled) {
if (!!polling) {
clearInterval(polling);
polling = null;
}
if (enabled) {
polling = setInterval(async () => {
tick += 1;
await emit("queryState", "");
}, 50);
}
// console.log(enabled, polling, tick);
}
// Receive events
onMount(async () => {
document.addEventListener("contextmenu", (event) => event.preventDefault());
// console.log(emit, listen);
await listen("showConfig", (event) => {
const payload: any = JSON.parse(event.payload as any);
deviceMode = payload.deviceMode || "none";
outputMode = payload.outputMode || "none";
ledMode = payload.ledMode || "none";
disableAirStrings = payload.disableAirStrings || false;
divaSerialPort = payload.divaSerialPort || "COM1";
divaBrightness = payload.divaBrightness || 63;
brokenithmPort = payload.brokenithmPort || 1606;
keyboardSensitivity = payload.keyboardSensitivity || 20;
keyboardDirectInput = payload.keyboardDirectInput || false;
outputPolling = payload.outputPolling || "100";
outputWebsocketUrl =
payload.outputWebsocketUrl || "http://localhost:3000/";
ledFaster = payload.ledFaster || false;
ledColorActive = payload.ledColorActive || "#ff00ff";
ledColorInactive = payload.ledColorInactive || "#ffff00";
ledColorAirActive = payload.ledColorAirActive || "#0086ed";
ledColorAirInactive = payload.ledColorAirInactive || "#000000";
ledSensitivity = payload.ledSensitivity || 20;
ledWebsocketUrl = payload.ledWebsocketUrl || "http://localhost:3001";
ledUmgrWebsocketPort = payload.ledUmgrWebsocketPort || 7124;
ledSerialPort = payload.ledSerialPort || "COM5";
});
await listen("showState", (event) => {
previewData = event.payload as any;
});
await listen("showTimerState", (event) => {
timerData = event.payload as string;
});
await listen("listIps", (event) => {
ips = (event.payload as Array<string>).filter(
(x) => x.split(".").length == 4
);
});
await emit("ready", "");
updatePolling(true);
await listen("ackShow", (event) => {
console.log("ackShow");
updatePolling(true);
});
await listen("ackHide", (event) => {
console.log("ackHide");
updatePolling(false);
});
versionString = ` ${await getVersion()}`;
});
// Emit events
async function setConfig() {
console.log("Updating config");
console.log(disableAirStrings);
await emit(
"setConfig",
JSON.stringify({
deviceMode,
outputMode,
ledMode,
disableAirStrings,
divaSerialPort,
divaBrightness,
brokenithmPort,
keyboardSensitivity,
keyboardDirectInput,
outputPolling,
outputWebsocketUrl,
ledFaster,
ledColorActive,
ledColorInactive,
ledColorAirActive,
ledColorAirInactive,
ledSensitivity,
ledWebsocketUrl,
ledUmgrWebsocketPort,
ledSerialPort,
})
);
dirty = false;
console.log("Done");
}
async function hide() {
await emit("hide", "");
}
async function quit() {
await emit("quit", "");
}
async function logs() {
await emit("openLogfile", "");
}
async function brokenithmQr() {
await emit("openBrokenithmQr");
}
async function repo() {
await emit("openRepo");
}
</script>
<div class="titlebar">
<div class="header-icon">
<img src="/icon.png" alt="logo" />
</div>
<div class="header">
slidershim{versionString}
</div>
<div class="header-space" />
<div class="header-timer">
{timerData}
</div>
</div>
<div data-tauri-drag-region class="titlebar titlebar-front" />
<main class="main">
<div class="preview-row">
<Preview data={previewData} />
</div>
<div class="options">
<div class="row">
<div class="label">Input Device</div>
<div class="input">
<select bind:value={deviceMode} on:change={markDirty}>
<option value="none">None</option>
<option value="tasoller-one">GAMO2 Tasoller, 1.0 HID Firmware</option>
<option value="tasoller-two">GAMO2 Tasoller, 2.0 HID Firmware</option>
<option value="yuancon">Yuancon Laverita, HID Firmware</option>
<option value="yuancon-three">Yuancon Laverita v3, HID Firmware</option>
<option value="yubideck">大四 / Yubideck, HID Firmware 1.0</option>
<option value="yubideck-three">大四 / Yubideck, HID Firmware 3.0</option>
<option value="diva">Slider over Serial</option>
<option value="brokenithm">Brokenithm</option>
<option value="brokenithm-led">Brokenithm + Led</option>
<option value="brokenithm-nostalgia">Brokestalgia (28k)</option>
</select>
</div>
</div>
{#if deviceMode.slice(0, 8) === "tasoller" || deviceMode.slice(0, 7) === "yuancon" || deviceMode.slice(0, 8) === "yubideck" || (deviceMode.slice(0, 10) === "brokenithm" && deviceMode !== "brokenithm-nostalgia")}
<div class="row">
<div class="label" />
<div class="input">
<span>
<input
type="checkbox"
id="disable-air"
style="width: unset;"
bind:checked={disableAirStrings}
on:change={markDirty}
/>
<label for="disable-air">Disable Air Strings</label>
</span>
</div>
</div>
{/if}
{#if deviceMode.slice(0, 10) === "brokenithm"}
<div class="row">
<div class="label">Brokenithm Port</div>
<div class="input">
<input
type="number"
min="1024"
max="65535"
step="1"
bind:value={brokenithmPort}
on:change={markDirty}
/>
</div>
</div>
<div class="row">
<div class="label" />
<div class="input">
<div class="serverlist">
Brokenithm will be running at one of:
<div class="iplist">
{ips
.map((x) => `http://${x}:${brokenithmPort || 1606}/`)
.join("\n")
.trim()}
</div>
</div>
</div>
</div>
{/if}
{#if deviceMode === "diva"}
<div class="row">
<div class="label">Slider Serial Port</div>
<div class="input">
<select bind:value={divaSerialPort} on:change={markDirty}>
<option value="COM1">COM1</option>
<option value="COM2">COM2</option>
<option value="COM3">COM3</option>
<option value="COM4">COM4</option>
<option value="COM5">COM5</option>
<option value="COM6">COM6</option>
<option value="COM7">COM7</option>
<option value="COM8">COM8</option>
<option value="COM9">COM9</option>
</select>
</div>
</div>
<div class="row">
<div class="label">Brightness</div>
<div class="input">
<input
type="number"
min="1"
max="255"
step="1"
bind:value={divaBrightness}
on:change={markDirty}
/>
</div>
</div>
<div class="row">
<div class="label" />
<div class="input">
<input
type="range"
min="1"
max="255"
step="1"
bind:value={divaBrightness}
on:change={markDirty}
/>
</div>
</div>
{/if}
<div class="row">
<div class="label">Output Mode</div>
<div class="input">
<select bind:value={outputMode} on:change={markDirty}>
<option value="none">None</option>
<option value="kb-32-tasoller"
>Keyboard 32-zone, Tasoller Layout</option
>
<option value="kb-32-yuancon">Keyboard 32-zone, Yuancon Layout</option
>
<option value="kb-32-umiguri">Keyboard 32-zone, UMIGURI Layout</option
>
<option value="kb-16">Keyboard 16-zone, Linear</option>
<option value="kb-8">Keyboard 8-zone, Linear</option>
<option value="kb-6">Keyboard 6-zone, Linear</option>
<option value="kb-4">Keyboard 4-zone, Linear</option>
<option value="kb-voltex">Keyboard 10-zone, Voltex Layout</option>
<option value="kb-neardayo">Keyboard 10-zone, Neardayo Layout</option>
<option value="gamepad-voltex">XBOX 360 Gamepad, Voltex Layout</option
>
<option value="gamepad-neardayo"
>XBOX 360 Gamepad, Neardayo Layout</option
>
<option value="gamepad-hori">DS4, HORI DIVA FT ASC Layout</option>
<option value="gamepad-hori-wide"
>DS4, HORI DIVA FT ASC Slider Only Layout</option
>
<!-- <option value="websocket">Websocket</option> -->
</select>
</div>
</div>
{#if deviceMode === "brokenithm-nostalgia" && outputMode !== "none" && outputMode.slice(0, 5) !== "kb-32"}
<div class="row">
<div class="label" />
<div class="input comment">
32 key layout is recommended for Brokestalgia controllers
</div>
</div>
{:else if deviceMode.slice(0, 10) === "brokenithm" && ["kb-voltex", "kb-neardayo", "gamepad-voltex", "gamepad-neardayo", "gamepad-hori"].includes(outputMode)}
<div class="row">
<div class="label" />
<div class="input comment">
Gamepad layouts are not recommended for Brokenithm controllers
</div>
</div>
{/if}
{#if outputMode.slice(0, 7) === "gamepad"}
<div class="row">
<div class="label" />
<div class="input comment">
Gamepad emulation requires <Link
href="https://github.com/ViGEm/ViGEmBus/releases">ViGEMBus</Link
>
</div>
</div>
{/if}
{#if outputMode !== "none"}
<div class="row">
<div class="label">Output Polling</div>
<div class="input">
<select bind:value={outputPolling} on:change={markDirty}>
<option value="60">60 Hz</option>
<option value="100">100 Hz</option>
<option value="250">250 Hz</option>
<option value="500">500 Hz</option>
<option value="1000">1000 Hz</option>
</select>
</div>
</div>
{/if}
{#if (outputMode.slice(0, 2) === "kb" || outputMode.slice(0, 7) === "gamepad") && deviceMode.slice(0, 10) !== "brokenithm"}
<div class="row">
<div class="label" title="Larger means harder to trigger">
Sensitivity
</div>
<div class="input">
<input
type="number"
min="1"
max="255"
step="1"
bind:value={keyboardSensitivity}
on:change={markDirty}
/>
</div>
</div>
<div class="row">
<div class="label" />
<div class="input">
<input
type="range"
min="1"
max="255"
step="1"
bind:value={keyboardSensitivity}
on:change={markDirty}
/>
</div>
</div>
{/if}
{#if outputMode.slice(0, 2) === "kb"}
<div class="row">
<div class="label" />
<div class="input">
<span>
<input
type="checkbox"
id="direct-input"
style="width: unset;"
bind:checked={keyboardDirectInput}
on:change={markDirty}
/>
<label for="direct-input">Use DirectInput</label>
</span>
</div>
</div>
{#if keyboardDirectInput}
<div class="row">
<div class="label" />
<div class="input comment">
DirectInput emulation requires <Link
href="https://github.com/oblitum/Interception/releases/tag/v1.0.1"
>Interception</Link
>
</div>
</div>
{/if}
{/if}
{#if outputMode === "websocket"}
<div class="row">
<div class="label">Output URL</div>
<div class="input">
<input
placeholder="URL"
bind:value={outputWebsocketUrl}
on:change={markDirty}
/>
</div>
</div>
{/if}
<div class="row">
<div class="label">LED Mode</div>
<div class="input">
<select bind:value={ledMode} on:change={markDirty}>
<option value="none">None</option>
<option value="reactive-16">Reactive, 16-Zone</option>
<option value="reactive-8">Reactive, 8-Zone</option>
<option value="reactive-6">Reactive, 6-Zone</option>
<option value="reactive-4">Reactive, 4-Zone</option>
<option value="reactive-rainbow">Reactive, 16-Zone Rainbow</option>
<option value="reactive-voltex">Reactive, Voltex Layout</option>
<option value="reactive-hori"
>Reactive, DIVA Future Tone Layout</option
>
<option value="attract">Rainbow Attract Mode</option>
<!-- <option value="websocket">Websocket</option> -->
<option value="umgr-websocket">UMIGURI Websocket</option>
<option value="serial">Serial</option>
</select>
</div>
</div>
{#if ledMode !== "none"}
<div class="row">
<div class="label" />
<div class="input">
<span>
<input
type="checkbox"
id="led-faster"
style="width: unset;"
bind:checked={ledFaster}
on:change={markDirty}
/>
<label for="led-faster">Update LED data faster</label>
</span>
</div>
</div>
{/if}
{#if ledMode.slice(0, 8) === "reactive" && ["16", "8", "6", "4"].includes(ledMode.slice(9))}
<div class="row">
<div class="label">Slider Color</div>
<div class="input">
<span>
<input
type="color"
id="color-active"
style="width: 3rem;"
bind:value={ledColorActive}
on:change={markDirty}
/>
<label for="color-active">Active</label>
</span>
<span>
<input
type="color"
id="color-base"
style="width: 3rem;"
bind:value={ledColorInactive}
on:change={markDirty}
/>
<label for="color-base">Inactive</label>
</span>
</div>
</div>
<div class="row">
<div class="label">Air Color</div>
<div class="input">
<span>
<input
type="color"
id="color-active"
style="width: 3rem;"
bind:value={ledColorAirActive}
on:change={markDirty}
/>
<label for="color-active">Active</label>
</span>
<span>
<input
type="color"
id="color-base"
style="width: 3rem;"
bind:value={ledColorAirInactive}
on:change={markDirty}
/>
<label for="color-base">Inactive</label>
</span>
</div>
</div>
{/if}
{#if ledMode.slice(0, 8) === "reactive" && deviceMode.slice(0, 10) !== "brokenithm"}
<div class="row">
<div class="label" title="Larger means harder to trigger">
Sensitivity
</div>
<div class="input">
<input
type="number"
min="1"
max="255"
step="1"
bind:value={ledSensitivity}
on:change={markDirty}
/>
</div>
</div>
<div class="row">
<div class="label" />
<div class="input">
<input
type="range"
min="1"
max="255"
step="1"
bind:value={ledSensitivity}
on:change={markDirty}
/>
</div>
</div>
{/if}
{#if ledMode === "websocket"}
<div class="row">
<div class="label">LED URL</div>
<div class="input">
<input
placeholder="URL"
bind:value={ledWebsocketUrl}
on:change={markDirty}
/>
</div>
</div>
{/if}
{#if ledMode === "umgr-websocket"}
<div class="row">
<div class="label">UMIGURI Port</div>
<div class="input">
<input
type="number"
min="1024"
max="65535"
step="1"
bind:value={ledUmgrWebsocketPort}
on:change={markDirty}
/>
</div>
</div>
{/if}
{#if ledMode === "serial"}
<div class="row">
<div class="label" />
<div class="input comment">
Serial LED may require <Link
href="https://sourceforge.net/projects/com0com/files/com0com/2.2.2.0/com0com-2.2.2.0-x64-fre-signed.zip/download"
>com0com</Link
>
</div>
</div>
<div class="row">
<div class="label">LED Serial Port</div>
<div class="input">
<select bind:value={ledSerialPort} on:change={markDirty}>
<option value="COM1">COM1</option>
<option value="COM2">COM2</option>
<option value="COM3">COM3</option>
<option value="COM4">COM4</option>
<option value="COM5">COM5</option>
<option value="COM6">COM6</option>
<option value="COM7">COM7</option>
<option value="COM8">COM8</option>
<option value="COM9">COM9</option>
</select>
</div>
</div>
{/if}
</div>
<div class="buttons-row">
<button
on:click={async () => await setConfig()}
class={`${dirty && "primary"}`}>Apply</button
>
<button on:click={async () => await hide()}>Hide</button>
<button on:click={async () => await quit()}>Quit</button>
<button on:click={async () => await logs()}>Logs</button>
{#if deviceMode.slice(0, 10) === "brokenithm"}
<button on:click={async () => await brokenithmQr()}>Brokenithm QR</button>
{/if}
<button on:click={async () => await repo()}>About</button>
</div>
</main>
<style>
</style>