summaryrefslogtreecommitdiff
path: root/Library/SDK/Entrypoint.js
blob: d55d823df8356d36b972c78e4f1eabcf67e23450 (plain)
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
// noinspection JSUnresolvedVariable

process.title = "-strawberry";
global.fs = require('fs');
global.color = require('chalk');

console.clear();
process.stdin.setRawMode(true);

const readline = require('readline');
readline.emitKeypressEvents(process.stdin);

Launcher = require("../Launcher");

process.stdin.on('keypress', (str, key) => {
    for (let func of Strawberry.KeyboardEvents) {
        func(key.sequence);
    }

    if (key.sequence === '\u0003') {
        require('show-terminal-cursor')();
        process.exit();
    }

    if (!Strawberry.ProcessKeyboard) return;

    if (!global._STRAWBERRY_APPMENU_OPEN) {
        try {
            Strawberry.MenuBar.Reset();
        } catch (e) {}
    } else {
        if (key.sequence === "\x1B[A") {
            Launcher.GoUp();
        }
        if (key.sequence === "\x1B[B") {
            Launcher.GoDown();
        }
        if (key.sequence === "\r") {
            Launcher.Open();
        }
    }

    process.stdout.cursorTo(0, process.stdout.rows - 1);
    process.stdout.clearLine();
    process.stdout.write("0x" + Buffer.from(key.sequence).toString("hex").toUpperCase());

    if (key.sequence === "\x1B[P") {
        throw new Error("User pressed interrupt button");
    }
    if ((key.sequence === '\x1BOP' || key.sequence === "\x1B[[A") && !global._STRAWBERRY_APPMENU_OPEN) {
        process.stdout.cursorTo(1, 0);
        process.stdout.write(color.bgYellow.blue(" O "));
        Strawberry.Audio.SystemSound("Strawberry.Menu.Open");

        if (Strawberry.System) {
            global._STRAWBERRY_APPMENU_OPEN = true;
            Launcher.Init();
            Launcher.Spawn();
            return;
        } else {
            load("Strawberry.AppManager");
            Strawberry.MenuBar.BlinkAndQuit();
        }
    }
    if ((key.sequence === '\x1B' && global._STRAWBERRY_APPMENU_OPEN) || ((key.sequence === '\x1BOP' || key.sequence === "\x1B[[A") && global._STRAWBERRY_APPMENU_OPEN)) {
        Strawberry.Audio.SystemSound("Strawberry.Menu.Close");
        global._STRAWBERRY_APPMENU_OPEN = false;
        console.clear();
        Strawberry.WhenLoaded();
        Strawberry.MenuBar.Reset();
    }
    if (key.sequence === '\x1BOQ' || key.sequence === "\x1B[[B") {
        if (Strawberry.Menus.length > 0) {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Open");
            Strawberry.MenuBar.Active(0);
            setTimeout(() => {
                if (Strawberry.MenuAction[0]) {
                    Strawberry.MenuBar.Blink(0);
                    Strawberry.MenuAction[0]();
                } else {
                    Strawberry.MenuBar.Blink(0);
                }
            }, 75)
        } else {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid");
            return;
        }
    }
    if (key.sequence === '\x1BOR' || key.sequence === "\x1B[[C") {
        if (Strawberry.Menus.length > 1) {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Open");
            Strawberry.MenuBar.Active(1);
            setTimeout(() => {
                if (Strawberry.MenuAction[1]) {
                    Strawberry.MenuBar.Blink(1);
                    Strawberry.MenuAction[1]();
                } else {
                    Strawberry.MenuBar.Blink(1);
                }
            }, 75)
        } else {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid");
            return;
        }
    }
    if (key.sequence === '\x1BOS' || key.sequence === "\x1B[[D") {
        if (Strawberry.Menus.length > 2) {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Open");
            Strawberry.MenuBar.Active(2);
            setTimeout(() => {
                if (Strawberry.MenuAction[2]) {
                    Strawberry.MenuBar.Blink(2);
                    Strawberry.MenuAction[2]();
                } else {
                    Strawberry.MenuBar.Blink(2);
                }
            }, 75)
        } else {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid");
            return;
        }
    }
    if (key.sequence === '\x1B[15~' || key.sequence === "\x1B[[E") {
        if (Strawberry.Menus.length > 3) {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Open");
            Strawberry.MenuBar.Active(3);
            setTimeout(() => {
                if (Strawberry.MenuAction[3]) {
                    Strawberry.MenuBar.Blink(3);
                    Strawberry.MenuAction[3]();
                } else {
                    Strawberry.MenuBar.Blink(3);
                }
            }, 75)
        } else {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid");
            return;
        }
    }
    if (key.sequence === '\x1B[16~') {
        if (Strawberry.Menus.length > 4) {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Open");
            Strawberry.MenuBar.Active(4);
            setTimeout(() => {
                if (Strawberry.MenuAction[4]) {
                    Strawberry.MenuBar.Blink(4);
                    Strawberry.MenuAction[4]();
                } else {
                    Strawberry.MenuBar.Blink(4);
                }
            }, 75)
        } else {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid");
            return;
        }
    }
    if (key.sequence === '\x1B[17~') {
        if (Strawberry.Menus.length > 5) {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Open");
            Strawberry.MenuBar.Active(5);
            setTimeout(() => {
                if (Strawberry.MenuAction[5]) {
                    Strawberry.MenuBar.Blink(5);
                    Strawberry.MenuAction[5]();
                } else {
                    Strawberry.MenuBar.Blink(5);
                }
            }, 75)
        } else {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid");
            return;
        }
    }
    if (key.sequence === '\x1B[18~') {
        if (Strawberry.Menus.length > 6) {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Open");
            Strawberry.MenuBar.Active(6);
            setTimeout(() => {
                if (Strawberry.MenuAction[6]) {
                    Strawberry.MenuBar.Blink(6);
                    Strawberry.MenuAction[6]();
                } else {
                    Strawberry.MenuBar.Blink(6);
                }
            }, 75)
        } else {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid");
            return;
        }
    }
    if (key.sequence === '\x1B[19~') {
        if (Strawberry.Menus.length > 7) {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Open");
            Strawberry.MenuBar.Active(7);
            setTimeout(() => {
                if (Strawberry.MenuAction[7]) {
                    Strawberry.MenuBar.Blink(7);
                    Strawberry.MenuAction[7]();
                } else {
                    Strawberry.MenuBar.Blink(7);
                }
            }, 75)
        } else {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid");
            return;
        }
    }
    if (key.sequence === '\x1B[20~') {
        if (Strawberry.Menus.length > 8) {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Open");
            Strawberry.MenuBar.Active(8);
            setTimeout(() => {
                if (Strawberry.MenuAction[8]) {
                    Strawberry.MenuBar.Blink(8);
                    Strawberry.MenuAction[8]();
                } else {
                    Strawberry.MenuBar.Blink(8);
                }
            }, 75)
        } else {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid");
            return;
        }
    }
    if (key.sequence === '\x1B[21~') {
        if (Strawberry.Menus.length > 9) {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Open");
            Strawberry.MenuBar.Active(9);
            setTimeout(() => {
                if (Strawberry.MenuAction[9]) {
                    Strawberry.MenuBar.Blink(9);
                    Strawberry.MenuAction[9]();
                } else {
                    Strawberry.MenuBar.Blink(9);
                }
            }, 75)
        } else {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid");
            return;
        }
    }
    if (key.sequence === '\x1B[23~') {
        if (Strawberry.Menus.length > 10) {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Open");
            Strawberry.MenuBar.Active(10);
            setTimeout(() => {
                if (Strawberry.MenuAction[10]) {
                    Strawberry.MenuBar.Blink(10);
                    Strawberry.MenuAction[10]();
                } else {
                    Strawberry.MenuBar.Blink(10);
                }
            }, 75)
        } else {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid");
            return;
        }
    }
    if (key.sequence === '\x1B[24~') {
        if (Strawberry.Menus.length > 10) {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Open");
            Strawberry.MenuBar.Active(11);
            setTimeout(() => {
                if (Strawberry.MenuAction[11]) {
                    Strawberry.MenuBar.Blink(11);
                    Strawberry.MenuAction[11]();
                } else {
                    Strawberry.MenuBar.Blink(11);
                }
            }, 75)
        } else {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid");
            return;
        }
    }
    if (key.sequence === '\x1B[24~') {
        if (Strawberry.Menus.length > 10) {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Open");
            Strawberry.MenuBar.Active(12);
            setTimeout(() => {
                if (Strawberry.MenuAction[12]) {
                    Strawberry.MenuBar.Blink(12);
                    Strawberry.MenuAction[12]();
                } else {
                    Strawberry.MenuBar.Blink(12);
                }
            }, 75)
        } else {
            Strawberry.Audio.SystemSound("Strawberry.Menu.Invalid");
        }
    }
    if (key.sequence === "\x1B\x1B[B") {
        if (Strawberry.CurrentPane + 1 < Strawberry.Panes.length) {
            Strawberry.CurrentPane++;
        } else {
            Strawberry.CurrentPane = 0;
        }
        Strawberry.UpdatePanes();
    }
    if (key.sequence === "\x1B\x1B[A") {
        if (Strawberry.CurrentPane > 0) {
            Strawberry.CurrentPane--;
        } else {
            Strawberry.CurrentPane = Strawberry.Panes.length - 1;
        }
        Strawberry.UpdatePanes();
    }
})

global._STRAWBERRY_INIT_APP = () => {
    global.Strawberry = {
        App: "Strawberry",
        MultiPanes: false,
        System: false,
        Window: true,
        Menus: [],
        Panes: [],
        CurrentPane: 0,
        MenuAction: [],
        KeyboardEvents: [],
        Tick: {
            Events: [],
            Timer: setInterval(() => {
                for (let i in Strawberry.Tick.Events) {
                    Strawberry.Tick.Events[i]();
                }
            })
        },
        UpdatePanes: () => {
            let line = 8;
            let index = 0;
            for (let pane of Strawberry.Panes) {
                let name = pane.name;

                process.stdout.cursorTo(3, line);
                if (index === Strawberry.CurrentPane) {
                    process.stdout.write(chalk.bgBlue.white(" " + name + " ".repeat(44 - name.length)));
                } else {
                    if (index === Strawberry.CurrentPane + 1) {
                        process.stdout.write(chalk.bgWhite.black(" " + name + " ".repeat(44 - name.length - 9) + chalk.blue("Opt+Down") + " "));
                    } else if (index === Strawberry.CurrentPane - 1) {
                        process.stdout.write(chalk.bgWhite.black(" " + name + " ".repeat(44 - name.length - 7) + chalk.blue("Opt+Up") + " "));
                    } else if (Strawberry.CurrentPane === 0 && index === Strawberry.Panes.length - 1) {
                        process.stdout.write(chalk.bgWhite.black(" " + name + " ".repeat(44 - name.length - 7) + chalk.blue("Opt+Up") + " "));
                    } else if (Strawberry.CurrentPane === Strawberry.Panes.length - 1 && index === 0) {
                        process.stdout.write(chalk.bgWhite.black(" " + name + " ".repeat(44 - name.length - 9) + chalk.blue("Opt+Down") + " "));
                    } else {
                        process.stdout.write(chalk.bgWhite.black(" " + name + " ".repeat(44 - name.length)));
                    }
                }

                line++;
                index++;
            }

            for (let i = 3; i < process.stdout.rows - 1; i++) {
                process.stdout.cursorTo(52, i);
                process.stdout.write(chalk.bgWhite.black(" ".repeat(process.stdout.columns - 53)));
                Strawberry.Panes[Strawberry.CurrentPane].load();
            }
        },
        ProcessKeyboard: true,
        WhenLoaded: () => {},
        StartLoad: (skipCoolLoading) => {
            load("Strawberry.Audio");
            if (!skipCoolLoading) skipCoolLoading = false;

            console.clear();
            if (Strawberry.System) {
                let horizontal = Math.round(process.stdout.columns / 2 - (1 + (Strawberry.App.length / 2)));
                process.stdout.write(color.bgBlue.white(" ".repeat(horizontal + Strawberry.App.length) + " ".repeat(process.stdout.columns - horizontal - Strawberry.App.length)));
            } else {
                let horizontal = Math.round(process.stdout.columns / 2 - (1 + (Strawberry.App.length / 2)));
                process.stdout.write(color.bgBlue.white(" ".repeat(horizontal) + Strawberry.App + " ".repeat(process.stdout.columns - horizontal - Strawberry.App.length)));
            }

            setTimeout(() => {
                if (Strawberry.System && !skipCoolLoading) {
                    Strawberry.Audio.SystemSound("Strawberry.System.Login");
                }

                Strawberry.ProcessKeyboard = true;

                if (!Strawberry.System && Strawberry.Window) {
                    process.stdout.cursorTo(0, 2);
                    process.stdout.write(chalk.bgWhite.blue("┏" + "━".repeat(process.stdout.columns - 2) + "┓"))

                    for (let i = 3; i < process.stdout.rows - 1; i++) {
                        process.stdout.cursorTo(0, i);
                        process.stdout.write(chalk.bgWhite.blue("┃" + " ".repeat(process.stdout.columns - 2) + "┃"))
                    }

                    process.stdout.cursorTo(0, process.stdout.rows);
                    process.stdout.write(chalk.bgWhite.blue("┗" + "━".repeat(process.stdout.columns - 2) + "┛"))

                    Strawberry.Audio.SystemSound("Strawberry.System.Window");
                }

                if (Strawberry.MultiPanes) {
                    process.stdout.cursorTo(0, 2);
                    process.stdout.write(chalk.bgWhite.blue("┏" + "━".repeat(50) + "┳" + "━".repeat(process.stdout.columns - 53) + "┓"))

                    for (let i = 3; i < process.stdout.rows - 1; i++) {
                        process.stdout.cursorTo(0, i);
                        process.stdout.write(chalk.bgWhite.blue("┃" + " ".repeat(50) + "┃" + " ".repeat(process.stdout.columns - 53) + "┃"))
                    }

                    process.stdout.cursorTo(0, process.stdout.rows);
                    process.stdout.write(chalk.bgWhite.blue("┗" + "━".repeat(50) + "┻" + "━".repeat(process.stdout.columns - 53) + "┛"))

                    process.stdout.cursorTo(0, 6);
                    process.stdout.write(chalk.bgWhite.blue("┣" + "━".repeat(50) + "┫"))

                    process.stdout.cursorTo(0, 4);
                    process.stdout.write(chalk.bgWhite.blue("┃") + chalk.bgWhite.black(" ".repeat((50 - Strawberry.App.length) / 2) + Strawberry.App))
                }

                Strawberry.WhenLoaded();

                if (Strawberry.MultiPanes) {
                    Strawberry.UpdatePanes();
                }

                try {
                    Strawberry.MenuBar.Initialize();
                    Strawberry.MenuBar.Reset();
                } catch (e) {}
            }, (skipCoolLoading ? 500 : 2000))
        }
    }
}

global._STRAWBERRY_INIT_APP();

global.load = (module) => {
    if (require('os').platform() === "linux" && module === "Strawberry.Menubar") {
        module = "Strawberry.MenuBar";
    }

    if (module.includes("/")) throw new Error("Invalid module: " + module);
    if (!fs.existsSync(__dirname + "/Modules/" + module + ".js")) throw new Error("Invalid module: " + module);

    let parts = module.split(".");
    if (parts.length > 2) {
        Strawberry[parts[1]] = {};
        Strawberry[parts[1]][parts[2]] = require("./Modules/" + module);
    } else if (parts.length > 3) {
        Strawberry[parts[1]][parts[2]] = {};
        Strawberry[parts[1]][parts[2]][parts[3]] = require("./Modules/" + module);
    } else {
        Strawberry[parts[1]] = require("./Modules/" + module);
    }

    if (module === "Strawberry.Menubar") {
        load("Strawberry.MenuBar");
    }

    if (require('os').platform() === "linux" && module === "Strawberry.MenuBar") {
        Strawberry.Menubar = Strawberry.MenuBar;
    }
}