-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathv5.js
276 lines (218 loc) · 7.66 KB
/
v5.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
window.bp_v_5 = async function bp_v_5() {
await bp.load('error-tracker', {
apiEndpoint: 'https://errors.buddypond.com/error',
// apiEndpoint: 'http://localhost:8787/error',
});
setConfig();
bindUIEvents();
await bp.load('localstorage');
await bp.load('buddyscript');
await loadCoreApps();
arrangeDesktop();
// desktop is loaded at this stage, continue with other apps
// load what is required for buddylist and login
let allCommands = bp.apps.buddyscript.commands;
await bp.load('play');
await bp.open('client');
// if not mobile, open buddylist
if (!bp.isMobile()) {
await bp.open({
name: 'buddylist',
autocomplete: allCommands
});
}
// if mobile and also session, open buddylist
// TODO: if (bp.isMobile() && bp.me) {
// buddy list is operational at this stage
// load apps related to chat / social
await bp.load("card");
// 'toastr', 'powerlevel',
// load any other apps that are non-essential but still useful
bp.load('console');
bp.load('clock');
bp.load('appstore');
bp.load('themes');
bp.load('wallpaper');
bp.load('motd');
bp.load('say');
bp.load('droparea');
bp.load('file-viewer');
//bp.open('file-explorer');
// bp.open('piano')
// bp.open('hacker-typer');
// bp.open('globe');
// bp.open('maps');
//bp.open('minesweeper');
//bp.open('solitaire');
//bp.open('mantra');
// await bp.load('youtube');
// await bp.load('soundrecorder');
// await bp.open('camera');
// bp.apps.buddylist.openChatWindow({ context: 'Buddy', type: 'pond', x: 500 });
};
function setConfig() {
bp.setConfig({
host: _host,
wsHost: _wsHost,
api: _api,
cdn: _cdn
});
}
function bindUIEvents() {
// Legacy BP logout / login
bp.on('auth::logout', 'old-bp-logout', function () {
$('.loggedIn').flexHide();
$('.loggedOut').flexShow();
//$('.loggedOut').addClass('show');
bp.apps.client.api.logout(function (err, data) {
console.log('logout', err, data);
});
});
bp.on('auth::qtoken', 'old-bp-login', function (qtoken) {
buddypond.qtokenid = qtoken.qtokenid;
bp.me = qtoken.me;
//console.log("Showing logged in", qtoken);
$('.loggedIn').flexShow();
//$('.loggedIn').addClass('show');
$('.loggedOut').flexHide();
$('#me_title').html('Welcome ' + bp.me);
bp.apps.desktop.load();
});
bp.on('buddy::message::gotfiltered', 'show-toast-info', function (message) {
// console.log('buddy-message-gotfiltered', message);
// make toastr that stays for 5 seconds
toastr.options.timeOut = 5000;
toastr.info('Your message was filtered due to being at Power Level 1.');
// desktop.ui.openWindow('buddy_message', { context: message });
});
let d = $(document);
// Delegate click event for .volumeToggle
d.on('click', '.volumeToggle', function () {
let audio_enabled = localStorage.getItem('audio_enabled');
if (audio_enabled === 'true') {
localStorage.setItem('audio_enabled', 'false');
$('.volumeFull').hide();
$('.volumeMuted').show();
} else {
localStorage.setItem('audio_enabled', 'true');
$('.volumeFull').show();
$('.volumeMuted').hide();
bp.play('desktop/assets/audio/IM.wav', { tryHard: Infinity });
}
});
// Delegate click event for .loginLink
d.on('click', '.loginLink', function () {
bp.open('buddylist');
});
// Delegate change event for .selectPlaylist
d.on('change', '.selectPlaylist', function () {
$('#soundcloudiframe').remove();
$('#soundcloudplayer').html('');
/*
if (desktop.app.soundcloud) {
desktop.app.soundcloud.embeded = false;
}
desktop.ui.openWindow('soundcloud', { playlistID: $(this).val() });
*/
if (bp.apps.soundcloud) {
bp.apps.soundcloud.soundCloudEmbeded = false; // reload
}
bp.open('soundcloud', { playlistID: $(this).val() });
});
// Delegate change event for .selectTheme
d.on('change', '.selectTheme', function () {
let theme = $(this).val();
if (theme === 'Customize') {
bp.open('profile', { context: 'themes' });
} else {
/*
desktop.app.themes.applyTheme(desktop.app.themes.themes[theme]);
*/
bp.apps.themes.applyTheme(theme);
bp.set('active_theme', theme);
}
});
d.on('mousedown', 'img.remixPaint, img.remixMeme', function () {
let form = $(this).parent();
let url = $('.image', form).attr('src');
let output = $(this).data('output');
let context = $(this).data('context');
let cardContainer = $(this).parent().parent();
console.log('cardContainer', cardContainer);
url = $('.bp-image', cardContainer).attr('src');
// url = buddypond.host + url;
console.log('remixPaint', url, output, context);
bp.open('paint', {
src: url,
output: output,
context: context
});
});
// Checking and setting the initial state of audio settings
$(function () {
if (!desktop.settings.audio_enabled) {
$('.volumeFull').hide();
$('.volumeMuted').show();
} else {
$('.volumeFull').show();
$('.volumeMuted').hide();
}
});
}
async function loadCoreApps() {
console.log("start ui import")
await bp.importModule({
name: 'ui',
parent: $('#desktop').get(0),
window: {
onFocus(window) {
// console.log('custom onFocus window focused');
// legacy window check ( we can remove this after all windows are converted to new window )
// get all the legacy windows and check z-index to ensure
// our window is +1 of the highest z-index
let legacyWindows = $('.window');
let highestZ = 0;
let anyVisible = false;
legacyWindows.each((i, el) => {
let z = parseInt($(el).css('z-index'));
if (z > highestZ) {
highestZ = z;
}
if ($(el).is(':visible')) {
anyVisible = true;
}
});
// set the z-index of the current window to highestZ + 1
if (legacyWindows.length > 0 && anyVisible) {
console.log('legacyWindows', legacyWindows);
console.log('highestZ', highestZ);
console.log('setting window depth to', highestZ + 1);
window.setDepth(highestZ + 1);
}
},
}
});
console.log("ui imported")
await bp.importModule({
name: 'desktop',
parent: $('#desktop').get(0),
});
await bp.load('menubar');
bp.apps.menubar.load();
// await bp.start(['ui', 'fetch-in-webworker', 'audio-track']);
//bp.open('audio-player')
}
function arrangeDesktop() {
if (bp.isMobile()) {
bp.apps.desktop.arrangeShortcuts(4, {
rowWidth: 256,
rowHeight: 256
});
} else {
bp.apps.desktop.arrangeShortcuts(3); // Arrange the icons in a grid of 4 columns
}
setTimeout(() => {
bp.apps.desktop.showDesktopIcons();
}, 300);
}
window.arrangeDesktop = arrangeDesktop;