summaryrefslogtreecommitdiff
path: root/Library/SystemSoftware.js
blob: 6737410f37ca7438487962df89d7e72a4ea4b5df (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
// noinspection JSUnresolvedVariable

require('./SDK/Entrypoint'); // This part is supposed to be require-d by the system
// ----------------------

let initialized = false;

global._STRAWBERRY_SYSTEMSOFTWARE_INIT = () => {
    Strawberry.App = "System Software";
    Strawberry.System = true;
    Strawberry.Menus = [
        "Power Off",
        "Restart",
        "System Info",
        "Debugger"
    ]

    Strawberry.StartLoad(initialized);
    Strawberry.WhenLoaded = () => {
        load("Strawberry.Audio");
        load("Strawberry.MenuBar");
        load("Strawberry.DisplayRaw");
        load("Strawberry.SystemInfo");
        load("Strawberry.Dialog");
        load("Strawberry.AppManager");

        Strawberry.MenuAction[0] = () => {
            Strawberry.Tick.Events = [];
            Strawberry.ProcessKeyboard = 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(() => {
                console.clear();
                process.stdout.cursorTo(0, 0);

                setTimeout(() => {
                    Strawberry.Dialog.Basic("It is now safe to turn off your computer.", "red");
                }, 3000)
            }, 1000)
        }

        Strawberry.MenuAction[1] = () => {
            Strawberry.Tick.Events = [];
            Strawberry.ProcessKeyboard = 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(() => {
                console.clear();
                process.stdout.cursorTo(0, 0);
                setTimeout(() => {
                    require('child_process').spawnSync(process.argv[0], process.argv.filter((_, i) => { return i > 0 }), { stdio: "inherit" });
                }, 3000)
            }, 1000)
        }

        Strawberry.DisplayRaw.Write(color.bold.underline("Strawberry OS " + Strawberry.SystemInfo.Version()), 5, 3)
        Strawberry.DisplayRaw.Write(Math.round(Strawberry.SystemInfo.GetHardwareMemory().Total / 1024) + "K memory", 5, 4)
        Strawberry.DisplayRaw.Write(Strawberry.SystemInfo.GetProcessors().Count + " processors", 5, 5)

        Strawberry.DisplayRaw.Write(color.bold.underline("Processes:"), 5, 7)
        let proc = Strawberry.SystemInfo.Processes().filter((i) => {
            return !i.includes("/node_modules/");
        }).filter((_, i) => {
            let line = 8 + i;
            return line < process.stdout.rows - 2
        });

        let index = 0;
        for (let p of proc) {
            Strawberry.DisplayRaw.Write(p, 5, 8 + index);
            index++;
        }
    }

    initialized = true;
}

global._STRAWBERRY_SYSTEMSOFTWARE_INIT();