summaryrefslogtreecommitdiff
path: root/Library/Launcher.js
blob: 5040580577bc646c154be26b143437621d0d6f8d (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
// noinspection JSUnresolvedVariable

let Selected = 0;
let Applications = [];

let self = {
    GetAppsList: () => {
        let Applications1 = require('fs').readdirSync(global._STRAWBERRY_APPLICATIONS_ROOT).filter((i) => {
            return i.endsWith(".app") && require('fs').lstatSync(global._STRAWBERRY_APPLICATIONS_ROOT + "/" + i).isDirectory();
        });
        let Applications2 = require('fs').readdirSync(global._STRAWBERRY_SYSTEMAPPS_ROOT).filter((i) => {
            return i.endsWith(".app") && require('fs').lstatSync(global._STRAWBERRY_SYSTEMAPPS_ROOT + "/" + i).isDirectory();
        });
        Applications = [...Applications1, ...Applications2].sort((a, b) => a.localeCompare(b));
    },

    Init: () => {
        Selected = 0;
        self.GetAppsList();
    },

    Spawn: () => {
        load("Strawberry.DisplayRaw");
        Strawberry.DisplayRaw.Write(color.bgWhite.black("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓"), 1, 1)

        let line = 1;
        let appIndex = 0;

        for (let application of Applications) {
            line++;
            let appName = application.substring(0, 48);
            appName = appName.substring(0, appName.length - 4);

            if (appIndex === Selected) {
                Strawberry.DisplayRaw.Write(color.bgWhite.black("┃ " + color.bgBlue.white(" " + appName + " ".repeat(48 - appName.length) + " ") + " ┃"), 1, line);
            } else {
                Strawberry.DisplayRaw.Write(color.bgWhite.black("┃  " + appName + " ".repeat(48 - appName.length) + "  ┃"), 1, line);
            }

            appIndex++;
        }

        Strawberry.DisplayRaw.Write(color.bgWhite.black("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫"), 1, line + 1)
        Strawberry.DisplayRaw.Write(color.bgWhite.black("┃  Strawberry OS " + Strawberry.SystemInfo.Version() + " ".repeat(34 - Strawberry.SystemInfo.Version().length) + "  ┃"), 1, line + 2)
        Strawberry.DisplayRaw.Write(color.bgWhite.black("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛"), 1, line + 3)
    },

    GoUp: () => {
        Strawberry.Audio.SystemSound("Strawberry.Menu.Select")

        if (Selected > 0) {
            Selected--;
        } else {
            Selected = Applications.length - 1;
        }

        self.Spawn();
    },

    GoDown: () => {
        Strawberry.Audio.SystemSound("Strawberry.Menu.Select")

        if (Selected < Applications.length - 1) {
            Selected++;
        } else {
            Selected = 0;
        }

        self.Spawn();
    },

    Open: () => {
        Strawberry.Audio.SystemSound("Strawberry.Menu.Click")

        let line = 2 + Selected;
        let appName = Applications[Selected].substring(0, 48);
        appName = appName.substring(0, appName.length - 4);

        setTimeout(() => {
            self._OpenActive(appName, line);
            setTimeout(() => {
                self._OpenInactive(appName, line);
                setTimeout(() => {
                    self._OpenActive(appName, line);
                    setTimeout(() => {
                        self._OpenInactive(appName, line);
                        setTimeout(() => {
                            self._OpenActive(appName, line);
                            setTimeout(() => {
                                self._OpenInactive(appName, line);
                                setTimeout(() => {
                                    global._STRAWBERRY_APPMENU_OPEN = false;
                                    console.clear();
                                    Strawberry.WhenLoaded();
                                    Strawberry.MenuBar.Reset();
                                    if (fs.existsSync(global._STRAWBERRY_APPLICATIONS_ROOT + "/" + appName + ".app")) {
                                        Strawberry.AppManager.Start(global._STRAWBERRY_APPLICATIONS_ROOT + "/" + appName + ".app");
                                    } else {
                                        Strawberry.AppManager.Start(global._STRAWBERRY_SYSTEMAPPS_ROOT + "/" + appName + ".app");
                                    }
                                }, 30);
                            }, 30);
                        }, 30);
                    }, 30);
                }, 30);
            }, 30);
        }, 30);
    },

    _OpenActive: (appName, line) => {
        Strawberry.DisplayRaw.Write(color.bgWhite.black("┃ " + color.bgCyan.white(" " + appName + " ".repeat(48 - appName.length) + " ") + " ┃"), 1, line);
    },

    _OpenInactive: (appName, line) => {
        Strawberry.DisplayRaw.Write(color.bgWhite.black("┃  " + appName + " ".repeat(48 - appName.length) + "  ┃"), 1, line);
    }
}

module.exports = self;