Skip to content

Commit

Permalink
Now remembers previously opened windows and restores on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Marak committed Apr 17, 2022
1 parent 811e815 commit c50673a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 26 deletions.
37 changes: 22 additions & 15 deletions desktop/apps/desktop.login/desktop.login.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ desktop.app.login.load = function loadDesktopLogin (params, next) {
// token is valid, show client login success
buddypond.qtokenid = localToken;
buddypond.me = me;
desktop.app.login.success();
desktop.app.login.success({ source: 'localToken' });
}
if (location.hash) {
desktop.routeFromHash();
Expand Down Expand Up @@ -137,7 +137,7 @@ desktop.app.login.auth = function authDesktop (buddyname, password) {
localStorage.setItem('qtokenid', data.qtokenid);
localStorage.setItem('me', buddypond.me);
buddypond.qtokenid = data.qtokenid;
desktop.app.login.success();
desktop.app.login.success({ source: 'serverToken' });
} else {
if (data.banned) {
alert(data.message);
Expand All @@ -158,14 +158,14 @@ desktop.app.login.auth = function authDesktop (buddyname, password) {
});
};

desktop.app.login.success = function desktopLoginSuccess () {
desktop.app.login.success = function desktopLoginSuccess (params) {
$('#me_title').html('Welcome - ' + buddypond.me);
$('.me').html(buddypond.me);
desktop.play('WELCOME.wav', Infinity);
$('.logoutLink').show();
$('.loginLink').hide();
// $('.qtokenid').val(data);
$('#window_login').hide();
desktop.ui.closeWindow('login');
$('.buddy_pond_not_connected').hide();
$('#login_desktop_icon').hide();
$('#profile_desktop_icon').show();
Expand Down Expand Up @@ -209,22 +209,29 @@ desktop.app.login.success = function desktopLoginSuccess () {
}, 1000);

// TODO: route default view based on query string
let params = desktop.utils.parseQueryString(document.location.search);
if (params.pond) {
let queryParams = desktop.utils.parseQueryString(document.location.search);
if (queryParams.pond) {
desktop.ui.openWindow('pond', {
context: params.pond
context: queryParams.pond
});
} else {
$('#window_buddylist').show();
desktop.ui.openWindow('buddylist');
desktop.ui.openWindow('pond');
desktop.ui.openWindow('pond', {
context: 'Lily'
});
// anounce all new buddies when they join
// is the source of the login is a serverToken, this indicates a fresh login
// for fresh logins, show the buddy list and join the default Lily Pond
// if params.source === 'localToken', this indicates that localStorage remembered the session
// and that the desktop should rely on localStorage desktop.settings.windows_open
if (params.source === 'serverToken') {
$('#window_buddylist').show();
desktop.ui.openWindow('buddylist');
desktop.ui.openWindow('pond');
desktop.ui.openWindow('pond', {
context: 'Lily'
});
}
// anounce all new anonymous buddies when they join
if (buddypond.me === 'anonymous') {
buddypond.pondSendMessage('Lily', 'Hello, I am anonymous.', function (err, data) {
});
// TODO: show Merlin welcome message
}
}

Expand All @@ -241,7 +248,7 @@ desktop.app.login.success = function desktopLoginSuccess () {
desktop.app.login.openWindow = function desktopLoginOpenWindow () {
$('.desktopConnected').hide();
$('.logoutLink').hide();
$('#window_login').addClass('window_stack').show();
// $('#window_login').addClass('window_stack').show();
$('#window_login').css('width', '74vw');
$('#window_login').css('height', '75vh');
$('#window_login').css('left', '22vw');
Expand Down
5 changes: 4 additions & 1 deletion desktop/apps/desktop.mtv/data/mtv.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ desktop.app.ytPlaylist = [
'itRWssMSuvw',
'mV-qGna_4Eo',
'RISWXReh-QI',
'EtC8WxPt7d8'
'EtC8WxPt7d8',
'ALZHF5UqnU4',
'K5KAc5CoCuk',
'VHoT4N43jK8'
];

36 changes: 27 additions & 9 deletions desktop/assets/js/jquery.desktop.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,20 @@ JQDX.window_resize = function window_resize (el) {
// Bring window to front.
JQDX.window_flat();
win.addClass('window_stack');

desktop.ui.openWindows[win.attr('id')] = {
/* TODO: windows_open should remember if window min or max
let openWindows = desktop.settings.windows_open || {};
openWindows[win.attr('id')] = {
open: true,
app: appName,
app: win.data('app'),
context: win.data('context'),
width: win.css('width'),
height: win.css('height'),
top: win.css('top'),
left: win.css('left')
}

desktop.ui.openWindows = openWindows;
desktop.set('windows_open', desktop.ui.openWindows);
*/

};

Expand Down Expand Up @@ -495,6 +498,15 @@ JQDX.bindDocumentEventHandlers = function bindDocumentEventHandlers () {
return false;
});

/* TODO: remove help with single click
d.on('click', '.help', function (ev) {
// Remark It's not code yet, it's "coode"
let holder = $(this).parent();
holder.hide();
return false;
});
*/

d.on('click', 'tr.openApp', function (ev) {
let appName = $(this).data('app');
desktop.ui.openWindow(appName);
Expand Down Expand Up @@ -726,10 +738,12 @@ JQDX.bindDocumentEventHandlers = function bindDocumentEventHandlers () {
// desktop.ui.getDesktopIconPositions();
let win = $(this);
let windowId = '#' + win.attr('id');
let appName = windowId.replace('#window_', '');
let appName = win.data('app');
let context = win.data('context');
desktop.ui.openWindows[windowId] = {
open: true,
app: appName,
context: context,
width: win.css('width'),
height: win.css('height'),
top: win.css('top'),
Expand Down Expand Up @@ -848,6 +862,7 @@ JQDX.loadWindow = function loadWindow (appName, params, callback) {
});
*/
if (desktop.app[appName] && desktop.app[appName].depends_on && desktop.app[appName].depends_on.length > 0) {
// TODO: can we remove this and just use call load.remoteJS() from inside the app.load ( like other deps )
let depName = desktop.app[appName].depends_on[0];
desktop.log('Loading: App.' + depName);
desktop.load.remoteJS([ `desktop/apps/desktop.${depName}/desktop.${desktop.app[appName].depends_on[0]}.js` ], function () {
Expand Down Expand Up @@ -906,6 +921,9 @@ JQDX.showWindow = function showWindow (appName, params) {
JQDX.window_flat();
$(appWindow).addClass('window_stack').show();

$(appWindow).data('app', appName);
$(appWindow).data('context', params.context);

if (desktop.ui.view === 'Mobile') {
JQDX.window_maximize($(appWindow));
}
Expand All @@ -925,7 +943,8 @@ JQDX.showWindow = function showWindow (appName, params) {
let win = $(appWindow);
desktop.ui.openWindows[appWindow] = {
open: true,
app: appName,
app: win.data('app'),
context: win.data('context'),
width: win.css('width'),
height: win.css('height'),
top: win.css('top'),
Expand Down Expand Up @@ -1383,12 +1402,11 @@ desktop.ui.toggleDisplayMode = function toggleDisplayMode () {
}
}

desktop.ui.openSavedWindows = function openSavedWindows () {
return;
desktop.ui.openWindowsFromSavedSettings = function openWindowsFromSavedSettings () {
let previouslyOpenWindows = desktop.get('windows_open');
for (let key in previouslyOpenWindows) {
let win = previouslyOpenWindows[key];
desktop.ui.openWindow(win.app, {}, function(){
desktop.ui.openWindow(win.app, { context: win.context }, function(){
$(key).css('top', win.top);
$(key).css('left', win.left);
$(key).css('width', win.width);
Expand Down
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@
// never gonna work due to:
// Refused to display 'https://www.google.com/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.
// desktop.ui.openWindow('console');
// desktop.ui.openSavedWindows();

// re-opens previously opened windows
desktop.ui.openWindowsFromSavedSettings();

});
});
Expand Down

0 comments on commit c50673a

Please sign in to comment.