globals.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /**
  2. * Copyright (C) 2024 Puter Technologies Inc.
  3. *
  4. * This file is part of Puter.
  5. *
  6. * Puter is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. window.clipboard_op = '';
  20. window.clipboard = [];
  21. window.actions_history = [];
  22. window.window_nav_history = {};
  23. window.window_nav_history_current_position = {};
  24. window.progress_tracker = [];
  25. window.upload_item_global_id = 0;
  26. window.download_progress = [];
  27. window.download_item_global_id = 0;
  28. window.TRUNCATE_LENGTH = 20;
  29. // This is the minimum width of the window for the sidebar to be shown
  30. window.window_width_threshold_for_sidebar = 500;
  31. // the window over which mouse is hovering
  32. window.mouseover_window = null;
  33. // an active itewm container is the one where keyboard events should work (arrow keys, ...)
  34. window.active_item_container = null;
  35. window.mouseX = 0;
  36. window.mouseY = 0;
  37. // get all logged-in users
  38. try{
  39. window.logged_in_users = JSON.parse(localStorage.getItem("logged_in_users"));
  40. }catch(e){
  41. window.logged_in_users = [];
  42. }
  43. if(window.logged_in_users === null)
  44. window.logged_in_users = [];
  45. // this sessions's user
  46. window.auth_token = localStorage.getItem("auth_token");
  47. try{
  48. window.user = JSON.parse(localStorage.getItem("user"));
  49. }catch(e){
  50. window.user = null;
  51. }
  52. // in case this is the first time user is visiting multi-user feature
  53. if(window.logged_in_users.length === 0 && window.user !== null){
  54. let tuser = window.user;
  55. tuser.auth_token = window.auth_token
  56. window.logged_in_users.push(tuser);
  57. localStorage.setItem("logged_in_users", window.logged_in_users);
  58. }
  59. window.last_window_zindex = 1;
  60. // first visit tracker
  61. window.first_visit_ever = localStorage.getItem("has_visited_before") === null ? true : false;
  62. localStorage.setItem("has_visited_before", true);
  63. // system paths
  64. if(window.user !== undefined && window.user !== null){
  65. window.desktop_path = '/' + window.user.username + '/Desktop';
  66. window.trash_path = '/' + window.user.username + '/Trash';
  67. window.appdata_path = '/' + window.user.username + '/AppData';
  68. window.documents_path = '/' + window.user.username + '/Documents';
  69. window.pictures_path = '/' + window.user.username + '/Photos';
  70. window.videos_path = '/' + window.user.username + '/Videos';
  71. window.audio_path = '/' + window.user.username + '/Audio';
  72. window.home_path = '/' + window.user.username;
  73. }
  74. window.root_dirname = 'Puter';
  75. // user preferences, persisted across sessions, cached in localStorage
  76. try {
  77. window.user_preferences = JSON.parse(localStorage.getItem('user_preferences'))
  78. }catch(e){
  79. window.user_preferences = null;
  80. }
  81. // default values
  82. if (window.user_preferences === null) {
  83. window.user_preferences = {
  84. show_hidden_files: false,
  85. language: navigator.language.split("-")[0] || navigator.userLanguage || 'en',
  86. clock_visible: 'auto',
  87. }
  88. }
  89. window.window_stack = []
  90. window.toolbar_height = 30;
  91. window.default_taskbar_height = 50;
  92. window.taskbar_height = window.default_taskbar_height;
  93. window.upload_progress_hide_delay = 500;
  94. window.active_uploads = {};
  95. window.copy_progress_hide_delay = 1000;
  96. window.busy_indicator_hide_delay = 600;
  97. window.global_element_id = 0;
  98. window.operation_id = 0;
  99. window.operation_cancelled = [];
  100. window.last_enter_pressed_to_rename_ts = 0;
  101. window.window_counter = 0;
  102. window.keypress_item_seach_term = '';
  103. window.keypress_item_seach_buffer_timeout = undefined;
  104. window.first_visit_animation = false;
  105. window.show_twitter_link = true;
  106. window.animate_window_opening = true;
  107. window.animate_window_closing = true;
  108. window.desktop_loading_fade_delay = (window.first_visit_ever && first_visit_animation ? 6000 : 1000);
  109. window.watchItems = [];
  110. window.appdata_signatures = {};
  111. window.appCallbackFunctions = [];
  112. // 'Launch' apps
  113. window.launch_apps = [];
  114. window.launch_apps.recent = []
  115. window.launch_apps.recommended = []
  116. // Is puter being loaded inside an iframe?
  117. if (window.location !== window.parent.location) {
  118. window.is_embedded = true;
  119. // taskbar is not needed in embedded mode
  120. window.taskbar_height = 0;
  121. } else {
  122. window.is_embedded = false;
  123. }
  124. // calculate desktop height and width
  125. window.desktop_height = window.innerHeight - window.toolbar_height - window.taskbar_height;
  126. window.desktop_width = window.innerWidth;
  127. // {id: {left: 0, top: 0}}
  128. window.original_window_position = {};
  129. // recalculate desktop height and width on window resize
  130. $( window ).on( "resize", function() {
  131. const new_desktop_height = window.innerHeight - window.toolbar_height - window.taskbar_height;
  132. const new_desktop_width = window.innerWidth;
  133. $('.window').each((_, el) => {
  134. const pos = $(el).position();
  135. const id = $(el).attr('id');
  136. if(!window.original_window_position[id]){
  137. window.original_window_position[id] = {
  138. left: pos.left,
  139. top: pos.top
  140. }
  141. }
  142. const leftRadio = pos.left / window.desktop_width;
  143. const topRadio = pos.top / window.desktop_height;
  144. let left = new_desktop_width * leftRadio;
  145. let top = new_desktop_height * topRadio;
  146. const maxLeft = new_desktop_width - $(el).width();
  147. const maxTop = new_desktop_height - $(el).height();
  148. // first move the window to the original position
  149. const originalLeft = window.original_window_position[id].left;
  150. const originalTop = window.original_window_position[id].top;
  151. if(left < 0) left = 0;
  152. else if(left > maxLeft || originalLeft > maxLeft) left = maxLeft;
  153. if(top < window.toolbar_height) top = window.toolbar_height;
  154. else if(top > maxTop || originalTop > maxTop) top = maxTop + window.toolbar_height;
  155. $(el).css({
  156. left,
  157. top
  158. })
  159. })
  160. window.desktop_height = new_desktop_height;
  161. window.desktop_width = new_desktop_width;
  162. });
  163. // for now `active_element` is basically the last element that was clicked,
  164. // later on though (todo) `active_element` will also be set by keyboard movements
  165. // such as arrow keys, tab key, ... and when creating new windows...
  166. window.active_element = null;
  167. // The number of recent apps to show in the launch menu
  168. window.launch_recent_apps_count = 10;
  169. // indicated if the mouse is in one of the window snap zones or not
  170. // if yes, which one?
  171. window.current_active_snap_zone = undefined;
  172. //
  173. window.is_fullpage_mode = false;
  174. window.window_border_radius = 4;
  175. window.sites = [];
  176. window.feature_flags = {
  177. // if true, the user will be able to create shortcuts to files and directories
  178. create_shortcut: true,
  179. // if true, the user will be asked to confirm before navigating away from Puter only if there is at least one window open
  180. prompt_user_when_navigation_away_from_puter: false,
  181. // if true, the user will be able to zip and download directories
  182. download_directory: true,
  183. }
  184. window.is_auto_arrange_enabled = true;
  185. window.desktop_item_positions = {};
  186. window.reset_item_positions = true; // The variable decides if the item positions should be reset when the user enabled auto arrange
  187. // default language
  188. window.locale = 'en';