From 06b075b1a44b75f2060ae75abc1b403605caade5 Mon Sep 17 00:00:00 2001 From: meetqy Date: Sat, 16 Mar 2024 13:48:11 +0800 Subject: [PATCH 1/4] fix: #90 --- src/globals.js | 132 +++++++++++++++++++++++++++---------------------- 1 file changed, 74 insertions(+), 58 deletions(-) diff --git a/src/globals.js b/src/globals.js index f5ff998a..222e779c 100644 --- a/src/globals.js +++ b/src/globals.js @@ -7,17 +7,17 @@ * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -window.clipboard_op = ''; +window.clipboard_op = ""; window.clipboard = []; window.actions_history = []; window.window_nav_history = {}; @@ -43,63 +43,65 @@ window.mouseX = 0; window.mouseY = 0; // get all logged-in users -try{ - window.logged_in_users = JSON.parse(localStorage.getItem("logged_in_users")); -}catch(e){ - window.logged_in_users = []; +try { + window.logged_in_users = JSON.parse(localStorage.getItem("logged_in_users")); +} catch (e) { + window.logged_in_users = []; } -if(window.logged_in_users === null) - window.logged_in_users = []; +if (window.logged_in_users === null) window.logged_in_users = []; // this sessions's user window.auth_token = localStorage.getItem("auth_token"); -try{ - window.user = JSON.parse(localStorage.getItem("user")); -}catch(e){ - window.user = null; +try { + window.user = JSON.parse(localStorage.getItem("user")); +} catch (e) { + window.user = null; } // in case this is the first time user is visiting multi-user feature -if(window.logged_in_users.length === 0 && window.user !== null){ - let tuser = window.user; - tuser.auth_token = window.auth_token - window.logged_in_users.push(tuser); - localStorage.setItem("logged_in_users", window.logged_in_users); +if (window.logged_in_users.length === 0 && window.user !== null) { + let tuser = window.user; + tuser.auth_token = window.auth_token; + window.logged_in_users.push(tuser); + localStorage.setItem("logged_in_users", window.logged_in_users); } window.last_window_zindex = 1; // first visit tracker -window.first_visit_ever = localStorage.getItem("has_visited_before") === null ? true : false; +window.first_visit_ever = + localStorage.getItem("has_visited_before") === null ? true : false; localStorage.setItem("has_visited_before", true); // system paths -if(window.user !== undefined && window.user !== null){ - window.desktop_path = '/' + window.user.username + '/Desktop'; - window.trash_path = '/' + window.user.username + '/Trash'; - window.appdata_path = '/' + window.user.username + '/AppData'; - window.documents_path = '/' + window.user.username + '/Documents'; - window.pictures_path = '/' + window.user.username + '/Photos'; - window.videos_path = '/' + window.user.username + '/Videos'; - window.audio_path = '/' + window.user.username + '/Audio'; - window.home_path = '/' + window.user.username; +if (window.user !== undefined && window.user !== null) { + window.desktop_path = "/" + window.user.username + "/Desktop"; + window.trash_path = "/" + window.user.username + "/Trash"; + window.appdata_path = "/" + window.user.username + "/AppData"; + window.documents_path = "/" + window.user.username + "/Documents"; + window.pictures_path = "/" + window.user.username + "/Photos"; + window.videos_path = "/" + window.user.username + "/Videos"; + window.audio_path = "/" + window.user.username + "/Audio"; + window.home_path = "/" + window.user.username; } -window.root_dirname = 'Puter'; +window.root_dirname = "Puter"; // user preferences, persisted across sessions, cached in localStorage try { - window.user_preferences = JSON.parse(localStorage.getItem('user_preferences')) -}catch(e){ - window.user_preferences = null; + window.user_preferences = JSON.parse( + localStorage.getItem("user_preferences") + ); +} catch (e) { + window.user_preferences = null; } // default values if (window.user_preferences === null) { - window.user_preferences = { - show_hidden_files: false, - } + window.user_preferences = { + show_hidden_files: false, + }; } -window.window_stack = [] +window.window_stack = []; window.toolbar_height = 30; window.default_taskbar_height = 50; window.taskbar_height = window.default_taskbar_height; @@ -112,43 +114,57 @@ window.operation_id = 0; window.operation_cancelled = []; window.last_enter_pressed_to_rename_ts = 0; window.window_counter = 0; -window.keypress_item_seach_term = ''; +window.keypress_item_seach_term = ""; window.keypress_item_seach_buffer_timeout = undefined; window.first_visit_animation = false; window.show_twitter_link = true; window.animate_window_opening = true; window.animate_window_closing = true; -window.desktop_loading_fade_delay = (window.first_visit_ever && first_visit_animation ? 6000 : 1000); +window.desktop_loading_fade_delay = + window.first_visit_ever && first_visit_animation ? 6000 : 1000; window.watchItems = []; window.appdata_signatures = {}; window.appCallbackFunctions = []; // 'Launch' apps window.launch_apps = []; -window.launch_apps.recent = [] -window.launch_apps.recommended = [] +window.launch_apps.recent = []; +window.launch_apps.recommended = []; // Is puter being loaded inside an iframe? if (window.location !== window.parent.location) { - window.is_embedded = true; - // taskbar is not needed in embedded mode - window.taskbar_height = 0; + window.is_embedded = true; + // taskbar is not needed in embedded mode + window.taskbar_height = 0; } else { - window.is_embedded = false; + window.is_embedded = false; } // calculate desktop height and width -window.desktop_height = window.innerHeight - window.toolbar_height - window.taskbar_height; +window.desktop_height = + window.innerHeight - window.toolbar_height - window.taskbar_height; window.desktop_width = window.innerWidth; // recalculate desktop height and width on window resize -$( window ).on( "resize", function() { - window.desktop_height = window.innerHeight - window.toolbar_height - window.taskbar_height; - window.desktop_width = window.innerWidth; +$(window).on("resize", function () { + const radio = window.desktop_width / window.innerWidth; + + window.desktop_height = + window.innerHeight - window.toolbar_height - window.taskbar_height; + window.desktop_width = window.innerWidth; + + const { top } = $(".window-login").position(); + + const width = $(".window-login").width(); + + $(".window-login").css({ + left: (window.desktop_width - width) / 2, + top: top / radio, + }); }); - + // for now `active_element` is basically the last element that was clicked, -// later on though (todo) `active_element` will also be set by keyboard movements +// later on though (todo) `active_element` will also be set by keyboard movements // such as arrow keys, tab key, ... and when creating new windows... window.active_element = null; @@ -159,7 +175,7 @@ window.launch_recent_apps_count = 10; // if yes, which one? window.current_active_snap_zone = undefined; -// +// window.is_fullpage_mode = false; window.window_border_radius = 4; @@ -167,10 +183,10 @@ window.window_border_radius = 4; window.sites = []; window.feature_flags = { - // if true, the user will be able to create shortcuts to files and directories - create_shortcut: true, - // if true, the user will be asked to confirm before navigating away from Puter only if there is at least one window open - prompt_user_when_navigation_away_from_puter: false, - // if true, the user will be able to zip and download directories - download_directory: true, -} + // if true, the user will be able to create shortcuts to files and directories + create_shortcut: true, + // if true, the user will be asked to confirm before navigating away from Puter only if there is at least one window open + prompt_user_when_navigation_away_from_puter: false, + // if true, the user will be able to zip and download directories + download_directory: true, +}; From 404a6a5aa56060d31f02a6ca3e9bc3c73abf06cd Mon Sep 17 00:00:00 2001 From: meetqy Date: Sat, 16 Mar 2024 13:53:25 +0800 Subject: [PATCH 2/4] format --- src/globals.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/globals.js b/src/globals.js index 222e779c..11f2cb31 100644 --- a/src/globals.js +++ b/src/globals.js @@ -147,6 +147,7 @@ window.desktop_width = window.innerWidth; // recalculate desktop height and width on window resize $(window).on("resize", function () { + const radio = window.desktop_width / window.innerWidth; window.desktop_height = From 68cd3f420e70c0162f0197e6dd977367050e0e45 Mon Sep 17 00:00:00 2001 From: meetqy Date: Sat, 16 Mar 2024 13:56:36 +0800 Subject: [PATCH 3/4] code format --- src/globals.js | 142 +++++++++++++++++++++++-------------------------- 1 file changed, 67 insertions(+), 75 deletions(-) diff --git a/src/globals.js b/src/globals.js index 11f2cb31..5e31a7c3 100644 --- a/src/globals.js +++ b/src/globals.js @@ -7,17 +7,17 @@ * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. - * + * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -window.clipboard_op = ""; +window.clipboard_op = ''; window.clipboard = []; window.actions_history = []; window.window_nav_history = {}; @@ -43,65 +43,63 @@ window.mouseX = 0; window.mouseY = 0; // get all logged-in users -try { - window.logged_in_users = JSON.parse(localStorage.getItem("logged_in_users")); -} catch (e) { - window.logged_in_users = []; +try{ + window.logged_in_users = JSON.parse(localStorage.getItem("logged_in_users")); +}catch(e){ + window.logged_in_users = []; } -if (window.logged_in_users === null) window.logged_in_users = []; +if(window.logged_in_users === null) + window.logged_in_users = []; // this sessions's user window.auth_token = localStorage.getItem("auth_token"); -try { - window.user = JSON.parse(localStorage.getItem("user")); -} catch (e) { - window.user = null; +try{ + window.user = JSON.parse(localStorage.getItem("user")); +}catch(e){ + window.user = null; } // in case this is the first time user is visiting multi-user feature -if (window.logged_in_users.length === 0 && window.user !== null) { - let tuser = window.user; - tuser.auth_token = window.auth_token; - window.logged_in_users.push(tuser); - localStorage.setItem("logged_in_users", window.logged_in_users); +if(window.logged_in_users.length === 0 && window.user !== null){ + let tuser = window.user; + tuser.auth_token = window.auth_token + window.logged_in_users.push(tuser); + localStorage.setItem("logged_in_users", window.logged_in_users); } window.last_window_zindex = 1; // first visit tracker -window.first_visit_ever = - localStorage.getItem("has_visited_before") === null ? true : false; +window.first_visit_ever = localStorage.getItem("has_visited_before") === null ? true : false; localStorage.setItem("has_visited_before", true); // system paths -if (window.user !== undefined && window.user !== null) { - window.desktop_path = "/" + window.user.username + "/Desktop"; - window.trash_path = "/" + window.user.username + "/Trash"; - window.appdata_path = "/" + window.user.username + "/AppData"; - window.documents_path = "/" + window.user.username + "/Documents"; - window.pictures_path = "/" + window.user.username + "/Photos"; - window.videos_path = "/" + window.user.username + "/Videos"; - window.audio_path = "/" + window.user.username + "/Audio"; - window.home_path = "/" + window.user.username; +if(window.user !== undefined && window.user !== null){ + window.desktop_path = '/' + window.user.username + '/Desktop'; + window.trash_path = '/' + window.user.username + '/Trash'; + window.appdata_path = '/' + window.user.username + '/AppData'; + window.documents_path = '/' + window.user.username + '/Documents'; + window.pictures_path = '/' + window.user.username + '/Photos'; + window.videos_path = '/' + window.user.username + '/Videos'; + window.audio_path = '/' + window.user.username + '/Audio'; + window.home_path = '/' + window.user.username; } -window.root_dirname = "Puter"; +window.root_dirname = 'Puter'; // user preferences, persisted across sessions, cached in localStorage try { - window.user_preferences = JSON.parse( - localStorage.getItem("user_preferences") - ); -} catch (e) { - window.user_preferences = null; + window.user_preferences = JSON.parse(localStorage.getItem('user_preferences')) +}catch(e){ + window.user_preferences = null; } // default values if (window.user_preferences === null) { - window.user_preferences = { - show_hidden_files: false, - }; + window.user_preferences = { + show_hidden_files: false, + } } -window.window_stack = []; +window.window_stack = [] window.toolbar_height = 30; window.default_taskbar_height = 50; window.taskbar_height = window.default_taskbar_height; @@ -114,58 +112,52 @@ window.operation_id = 0; window.operation_cancelled = []; window.last_enter_pressed_to_rename_ts = 0; window.window_counter = 0; -window.keypress_item_seach_term = ""; +window.keypress_item_seach_term = ''; window.keypress_item_seach_buffer_timeout = undefined; window.first_visit_animation = false; window.show_twitter_link = true; window.animate_window_opening = true; window.animate_window_closing = true; -window.desktop_loading_fade_delay = - window.first_visit_ever && first_visit_animation ? 6000 : 1000; +window.desktop_loading_fade_delay = (window.first_visit_ever && first_visit_animation ? 6000 : 1000); window.watchItems = []; window.appdata_signatures = {}; window.appCallbackFunctions = []; // 'Launch' apps window.launch_apps = []; -window.launch_apps.recent = []; -window.launch_apps.recommended = []; +window.launch_apps.recent = [] +window.launch_apps.recommended = [] // Is puter being loaded inside an iframe? if (window.location !== window.parent.location) { - window.is_embedded = true; - // taskbar is not needed in embedded mode - window.taskbar_height = 0; + window.is_embedded = true; + // taskbar is not needed in embedded mode + window.taskbar_height = 0; } else { - window.is_embedded = false; + window.is_embedded = false; } // calculate desktop height and width -window.desktop_height = - window.innerHeight - window.toolbar_height - window.taskbar_height; +window.desktop_height = window.innerHeight - window.toolbar_height - window.taskbar_height; window.desktop_width = window.innerWidth; // recalculate desktop height and width on window resize -$(window).on("resize", function () { - - const radio = window.desktop_width / window.innerWidth; - - window.desktop_height = - window.innerHeight - window.toolbar_height - window.taskbar_height; - window.desktop_width = window.innerWidth; - - const { top } = $(".window-login").position(); - - const width = $(".window-login").width(); - - $(".window-login").css({ - left: (window.desktop_width - width) / 2, - top: top / radio, - }); +$( window ).on( "resize", function() { + const radio = window.desktop_width / window.innerWidth; + + window.desktop_height = window.innerHeight - window.toolbar_height - window.taskbar_height; + window.desktop_width = window.innerWidth; + + const { top } = $(".window-login").position(); + const width = $(".window-login").width(); + $(".window-login").css({ + left: (window.desktop_width - width) / 2, + top: top / radio, + }); }); - + // for now `active_element` is basically the last element that was clicked, -// later on though (todo) `active_element` will also be set by keyboard movements +// later on though (todo) `active_element` will also be set by keyboard movements // such as arrow keys, tab key, ... and when creating new windows... window.active_element = null; @@ -176,7 +168,7 @@ window.launch_recent_apps_count = 10; // if yes, which one? window.current_active_snap_zone = undefined; -// +// window.is_fullpage_mode = false; window.window_border_radius = 4; @@ -184,10 +176,10 @@ window.window_border_radius = 4; window.sites = []; window.feature_flags = { - // if true, the user will be able to create shortcuts to files and directories - create_shortcut: true, - // if true, the user will be asked to confirm before navigating away from Puter only if there is at least one window open - prompt_user_when_navigation_away_from_puter: false, - // if true, the user will be able to zip and download directories - download_directory: true, -}; + // if true, the user will be able to create shortcuts to files and directories + create_shortcut: true, + // if true, the user will be asked to confirm before navigating away from Puter only if there is at least one window open + prompt_user_when_navigation_away_from_puter: false, + // if true, the user will be able to zip and download directories + download_directory: true, +} From 509a6cbd314fa843287b1ac9ff6d0ab52060739d Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Sat, 16 Mar 2024 12:08:11 -0700 Subject: [PATCH 4/4] refactor to account for signup window and the location of the code --- src/globals.js | 15 --------------- src/initgui.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/globals.js b/src/globals.js index 5e31a7c3..3c443394 100644 --- a/src/globals.js +++ b/src/globals.js @@ -141,21 +141,6 @@ if (window.location !== window.parent.location) { window.desktop_height = window.innerHeight - window.toolbar_height - window.taskbar_height; window.desktop_width = window.innerWidth; -// recalculate desktop height and width on window resize -$( window ).on( "resize", function() { - const radio = window.desktop_width / window.innerWidth; - - window.desktop_height = window.innerHeight - window.toolbar_height - window.taskbar_height; - window.desktop_width = window.innerWidth; - - const { top } = $(".window-login").position(); - const width = $(".window-login").width(); - $(".window-login").css({ - left: (window.desktop_width - width) / 2, - top: top / radio, - }); -}); - // for now `active_element` is basically the last element that was clicked, // later on though (todo) `active_element` will also be set by keyboard movements // such as arrow keys, tab key, ... and when creating new windows... diff --git a/src/initgui.js b/src/initgui.js index 097dd037..121594f4 100644 --- a/src/initgui.js +++ b/src/initgui.js @@ -1976,4 +1976,32 @@ function requestOpenerOrigin() { $(document).on('click', '.generic-close-window-button', function(e){ $(this).closest('.window').close(); +}); + +// Re-calculate desktop height and width on window resize and re-position the login and signup windows +$(window).on("resize", function () { + // If host env is popup, don't continue because the popup window has its own resize requirements. + if (window.embedded_in_popup) + return; + + const ratio = window.desktop_width / window.innerWidth; + + window.desktop_height = window.innerHeight - window.toolbar_height - window.taskbar_height; + window.desktop_width = window.innerWidth; + + // Re-center the login window + const top = $(".window-login").position()?.top; + const width = $(".window-login").width(); + $(".window-login").css({ + left: (window.desktop_width - width) / 2, + top: top / ratio, + }); + + // Re-center the create account window + const top2 = $(".window-signup").position()?.top; + const width2 = $(".window-signup").width(); + $(".window-signup").css({ + left: (window.desktop_width - width2) / 2, + top: top2 / ratio, + }); }); \ No newline at end of file