-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathoctos.js
159 lines (132 loc) · 4.88 KB
/
octos.js
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
const octos = (() => {
class MediaController {
async pausePlay() {
window.media.send.pausePlay();
}
async prevTrack() {
window.media.send.prevTrack();
}
async nextTrack() {
window.media.send.nextTrack();
}
async getTrack() {
return {
title: await window.media.getTitle(),
artist: await window.media.getArtist(),
secondsElapsed: await window.media.getSecondsElapsed(),
secondsTotal: await window.media.getSecondsTotal(),
playing: await window.media.isPlaying()
}
}
async getTrackTitle() {
return window.media.getTitle();
}
async getTrackArtist() {
return window.media.getArtist();
}
async getTrackSecondsElapsed() {
return window.media.getSecondsElapsed();
}
async getTrackSecondsTotal() {
return window.media.getSecondsTotal();
}
async getTrackPercentElapsed() {
return window.media.getPercentElapsed();
}
async isPlaying() {
return window.media.isPlaying();
}
async send(type = "pause-play") {
if (type == "prev-track") return window.media.send.prevTrack();
else if (type == "pause-play") return window.media.send.pausePlay();
else if (type == "next-track") return window.media.send.nextTrack();
else return null;
}
async request(type = "title") {
if (type == "title") return window.media.getTitle();
else if (type == "artist") return window.media.getArtist();
else if (type == "seconds-elapsed") return window.media.getSecondsElapsed();
else if (type == "seconds-total") return window.media.getSecondsTotal();
else if (type == "amount-elapsed") return window.media.getPercentElapsed();
else if (type == "state") return window.media.isPlaying();
}
on(event, listener) {
if (["track", "playbackstatus", "playbacktime"].includes(event)) document.addEventListener(event, (e) => listener(e.detail));
}
}
class Storage {
async read(id = "") {
return window.storage.getStorage(id);
}
async write(id = "", content = "") {
return window.storage.setStorage(id, content);
}
}
class FileDialog {
constructor(options) {
if (options.type == "directory") this.type = "directory";
else this.type = "file";
if (options.extensions) this.extensions = options.extensions;
else this.extensions = [];
this.events = [];
}
request() {
window.storage.requestFile(this.extensions).then((filepath) => {
for (var e of this.events) {
if (e.event == "finish") e.listener({ filepath });
}
}).catch((err) => {
for (var e of this.events) {
if (e.event == "error") e.listener(err);
}
});
return this;
}
on(event, listener) {
this.events.push({ event, listener });
return this;
}
}
class UserPreferences {
async read(id = "") {
return window.prefs.get(id);
}
async write(id = "", value = "") {
return window.prefs.set(id, value)
}
on(event, listener) {
if (event == "change") document.addEventListener("prefschange", (e) => listener(e.detail));
}
}
class FileSystem {
async readdir(path = "") {
return window.files.readdir(path);
}
async open(path = "") {
return window.files.open(path);
}
async extractIcon(path = "") {
return window.files.icon(path);
}
async pathExists(path = "") {
return window.files.exists(path);
}
async isDirectory(path = "") {
return window.files.isDir(path);
}
}
const system = {
// cpus, arch, machine, os, mem, freemem, uptime
getTheme: async () => window.system.getTheme(),
toggleDevTools: async () => window.dev.toggleDevTools(),
getCpus: async () => window.system.request("cpus"),
getArch: async () => window.system.request("arch"),
getMachine: async () => window.system.request("machine"),
getOS: async () => window.system.request("os"),
getTotalMem: async () => window.system.request("mem"),
getFreeMem: async () => window.system.request("freemem"),
getUptime: async () => window.system.request("uptime"),
}
exports = { MediaController, Storage, FileDialog, UserPreferences, system, FileSystem }
return exports;
})();