-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme.js
314 lines (266 loc) · 9.36 KB
/
theme.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
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
// Set vars
w96.ui.Theme.uiVars.maxWindowSizeFormulaW = "calc(100vw - -2px)";
w96.ui.Theme.uiVars.maxWindowSizeFormulaH = "calc(100vh - 44px)";
// Add start menubar
let username = 'User';
let sam = await w96.sys.sam.readSAM();
if(sam && sam.name) username = sam.name;
const startMenuItems = [
{
name: username,
action: ()=>void w96.sys.execCmd("explorer", ["c:/user"])
},
{
name: "Documents",
action: ()=>void w96.sys.execCmd("explorer", ["c:/user/documents"])
},
{
name: "App Data",
action: ()=>void w96.sys.execCmd("explorer", ["c:/user/appdata"])
},
{
name: "Trash",
action: ()=>void w96.sys.execCmd("explorer", ["c:/trash"])
},
{
type: "separator"
},
{
name: "Computer",
action: ()=>void w96.sys.execCmd("explorer", [])
},
{
name: "Root",
action: ()=>void w96.sys.execCmd("explorer", ["w:/"])
},
{
type: "separator"
},
{
name: "Run",
action: ()=>void w96.sys.execCmd("run", [])
},
{
name: "Control Panel",
action: ()=>void w96.sys.execCmd("ctrl", [])
},
{
name: "Help",
action: ()=>void w96.sys.execCmd("wiki96", [])
},
{
name: "Reboot",
action: ()=>void w96.sys.execCmd("reboot", [])
}
];
const quickProgramsMenuItems = [
{
name: "Explorer",
icon: await w96.ui.Theme.getIconUrl("apps/explorer"),
action: ()=>void w96.sys.execCmd("explorer", [])
},
{
name: "Package Manager",
icon: await w96.ui.Theme.getIconUrl("apps/pkmgr"),
action: ()=>void w96.sys.execCmd("pkmgr", [])
},
{
name: "Textpad",
icon: await w96.ui.Theme.getIconUrl("apps/textpad"),
action: ()=>void w96.sys.execCmd("textpad", [])
}
];
let currentView = "quick";
function createListItem(label, icon, action) {
const btn = document.createElement('div');
btn.classList.add('item');
btn.addEventListener('click', async (e)=>{
let evtObj = {
evt: e,
cancel: false
};
await action(evtObj);
if(!evtObj.cancel) {
console.log("aero debug: close start");
w96.evt.shell.emit('start-close');
}
});
const iconEl = document.createElement('div');
iconEl.className = "icon";
iconEl.style.backgroundImage = `url(${icon})`;
btn.appendChild(iconEl);
const textEl = document.createElement('div');
textEl.className = "text";
textEl.innerText = label;
btn.appendChild(textEl);
return btn;
}
async function populateP1View(start, type, args) {
currentView = type;
const p1items = start.querySelector(".p1>.items");
while(p1items.firstChild)
p1items.removeChild(p1items.firstChild);
//p1items.querySelectorAll("*").forEach((v)=>v.remove());
if(type == "quick") {
for(let i of quickProgramsMenuItems) {
if(i.type == "separator") {
const s = document.createElement('div');
s.classList.add('separator');
p1items.appendChild(s);
} else {
p1items.appendChild(createListItem(i.name, i.icon, i.action));
}
}
} else if(type == "programs") {
const diskContents = await w96.FS.readdir((args == null) ? "c:/system/programs" : args);
const cleanNames = diskContents.map((v)=>w96.FSUtil.fname(v));
if(args && (args != "c:/system/programs") && (args !== "C:/system/programs")) {
let upEl = createListItem("..", await w96.ui.Theme.getIconUrl("places/folder", "16x16"), async (e)=>{
e.cancel = true;
populateP1View(start, "programs", w96.FSUtil.getParentPath(args));
e.evt.stopPropagation();
});
upEl.classList.add('small');
p1items.appendChild(upEl);
}
cleanNames.aForEach(async(n, i)=>{
let el = createListItem(n, await w96.ui.Theme.getFileIconUrl(diskContents[i], "16x16"), async (e)=>{
if(await w96.FS.isFile(diskContents[i])) {
w96.sys.execFile(diskContents[i]);
} else {
e.evt.stopPropagation();
e.cancel = true;
// Open and close directory.
populateP1View(start, "programs", diskContents[i]);
}
});
el.classList.add('small');
p1items.appendChild(el);
});
}
}
let fnStartOpen = async (e)=>{
e.remove();
// Replace start menu
const start = document.createElement('div');
start.className = "start-menu oc-event-exempt";
start.innerHTML = `
<div class="account">
<div class="account-pfp"></div>
<span>User</span>
</div>
<div class="huge-ahh-line"></div>
<div class="container">
<div class="p1">
<div class="items"></div>
<div class="all-programs">
<hr>
<div class="button">
All Programs <div class="start_arrow_button"></div>
</div>
</div>
<div class="search-box">
<input class="w96-textbox search" placeholder="Search programs and files">
</div>
</div>
<div class="p2">
<div class="items"></div>
</div>
</div>
`;
const p2account = start.querySelector('.account');
if(sam && sam.picture && await w96.FS.exists(sam.picture.path)) {
let url = URL.createObjectURL(new Blob([await w96.FS.readbin(sam.picture.path)], { type: sam.picture.mime }));
p2account.style.backgroundImage = 'url(' + url + ')';
p2account.style.backgroundSize = 'cover';
//URL.revokeObjectURL(url);
}
// Setup search box
const searchBox = start.querySelector('.search');
const p1items = start.querySelector(".p1>.items");
const allProgramsBtn = start.querySelector(".all-programs>.button");
const prgmBackHandler = async () => {
await populateP1View(start, "quick");
searchBox.value = "";
allProgramsBtn.onclick = prgmAllHandler;
};
const prgmAllHandler = async () => {
await populateP1View(start, "programs");
allProgramsBtn.onclick = prgmBackHandler;
searchBox.value = "";
};
allProgramsBtn.onclick = prgmAllHandler;
searchBox.addEventListener('keydown', async(v)=>{
try {
if((searchBox.value.trim() == "") && (currentView !== "quick")) {
// Revert to quick view
await populateP1View(start, "quick");
allProgramsBtn.textContent = "▶ All Programs";
// All programs event handler.
allProgramsBtn.onclick = prgmAllHandler;
} else {
if(searchBox.value.length < 2)
return;
allProgramsBtn.textContent = "◀ Back";
allProgramsBtn.onclick = prgmBackHandler;
// TODO Add events to programs button to go back.
// Show search results
await populateP1View(start, "search");
const diskContents = await w96.FS.walk("c:/");
const cleanNames = diskContents.map((v)=>w96.FSUtil.fname(v));
const lq = searchBox.value.trim().toLowerCase();
let firstIndex = 0;
await cleanNames.aForEach(async(n, i)=>{
const nLq = n.trim().toLowerCase();
if(nLq.includes(lq)) {
let el = createListItem(n, await w96.ui.Theme.getFileIconUrl(diskContents[i], "small"), ()=>{
w96.sys.execFile(diskContents[i]);
});
if (!firstIndex)firstIndex = i;
el.classList.add('small');
p1items.appendChild(el);
}
});
if(v.keyCode == 13){
fnStartClose();
w96.sys.execFile(diskContents[firstIndex]);
}
}
} catch(e) {
console.error(e);
}
});
await populateP1View(start, "quick");
const p2items = start.querySelector(".p2>.items");
for(let i of startMenuItems) {
if(i.type == "separator") {
const s = document.createElement('div');
s.classList.add('separator');
p2items.appendChild(s);
} else {
const btn = document.createElement('button');
btn.addEventListener('click', ()=>{
w96.evt.shell.emit('start-close');
i.action();
});
btn.innerText = i.name;
p2items.appendChild(btn);
}
}
document.querySelector('#maingfx').appendChild(start);
searchBox.focus();
};
w96.evt.shell.on('start-opened', fnStartOpen);
let fnStartClose = ()=>{
const s = document.querySelector('.start-menu');
if(s) {
while(s.firstChild)
s.removeChild(s.firstChild);
s.remove();
}
};
w96.evt.shell.on('start-closed', fnStartClose);
w96.evt.ui.once('theme-unload', ()=>{
w96.evt.shell.remove('start-opened', fnStartOpen);
w96.evt.shell.remove('start-closed', fnStartClose);
});