diff --git a/src/helpers.js b/src/helpers.js index f895bac9..0c4521ea 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -36,7 +36,7 @@ import UIWindowDownloadDirProg from './UI/UIWindowDownloadDirProg.js'; import { PROCESS_RUNNING, PortalProcess, PseudoProcess } from "./definitions.js"; window.is_auth = ()=>{ - if(localStorage.getItem("auth_token") === null || auth_token === null) + if(localStorage.getItem("auth_token") === null || window.auth_token === null) return false; else return true; @@ -44,7 +44,7 @@ window.is_auth = ()=>{ window.suggest_apps_for_fsentry = async (options)=>{ let res = await $.ajax({ - url: api_origin + "/suggest_apps", + url: window.api_origin + "/suggest_apps", type: 'POST', contentType: "application/json", data: JSON.stringify({ @@ -52,11 +52,11 @@ window.suggest_apps_for_fsentry = async (options)=>{ path: options.path ?? undefined, }), headers: { - "Authorization": "Bearer "+auth_token + "Authorization": "Bearer "+window.auth_token }, statusCode: { 401: function () { - logout(); + window.logout(); }, }, success: function (res){ @@ -196,7 +196,7 @@ window.scrollParentToChild = (parent, child)=>{ window.getItem = async function(options){ return $.ajax({ - url: api_origin + "/getItem", + url: window.api_origin + "/getItem", type: 'POST', data: JSON.stringify({ key: options.key, @@ -205,11 +205,11 @@ window.getItem = async function(options){ async: true, contentType: "application/json", headers: { - "Authorization": "Bearer "+auth_token + "Authorization": "Bearer "+window.auth_token }, statusCode: { 401: function () { - logout(); + window.logout(); }, }, success: function (result){ @@ -221,7 +221,7 @@ window.getItem = async function(options){ window.setItem = async function(options){ return $.ajax({ - url: api_origin + "/setItem", + url: window.api_origin + "/setItem", type: 'POST', data: JSON.stringify({ app: options.app_uid, @@ -231,11 +231,11 @@ window.setItem = async function(options){ async: true, contentType: "application/json", headers: { - "Authorization": "Bearer "+auth_token + "Authorization": "Bearer "+window.auth_token }, statusCode: { 401: function () { - logout(); + window.logout(); }, }, success: function (fsentry){ @@ -312,6 +312,7 @@ window.globToRegExp = function (glob, opts) { reStr += "."; break; } + // fallthrough case "[": case "]": @@ -319,6 +320,7 @@ window.globToRegExp = function (glob, opts) { reStr += c; break; } + // fallthrough case "{": if (extended) { @@ -326,6 +328,7 @@ window.globToRegExp = function (glob, opts) { reStr += "("; break; } + // fallthrough case "}": if (extended) { @@ -333,6 +336,7 @@ window.globToRegExp = function (glob, opts) { reStr += ")"; break; } + // fallthrough case ",": if (inGroup) { @@ -364,7 +368,7 @@ window.globToRegExp = function (glob, opts) { if (isGlobstar) { // it's a globstar, so match zero or more path segments - reStr += "((?:[^/]*(?:\/|$))*)"; + reStr += "((?:[^/]*(?:/|$))*)"; i++; // move over the "/" } else { // it's not a globstar, so only match one path segment @@ -408,7 +412,7 @@ window.globToRegExp = function (glob, opts) { window.validate_fsentry_name = function(name){ if(!name) throw {message: i18n('name_cannot_be_empty')} - else if(!isString(name)) + else if(!window.isString(name)) throw {message: i18n('name_must_be_string')} else if(name.includes('/')) throw {message: i18n('name_cannot_contain_slash')} @@ -417,7 +421,7 @@ window.validate_fsentry_name = function(name){ else if(name === '..') throw {message: i18n('name_cannot_contain_double_period')}; else if(name.length > window.max_item_name_length) - throw {message: i18n('name_too_long', config.max_item_name_length)} + throw {message: i18n('name_too_long', window.max_item_name_length)} else return true } @@ -516,7 +520,7 @@ window.check_fsentry_against_allowed_file_types_string =function (fsentry, allow } // MIME types (e.g. text/plain) - else if(globToRegExp(allowed_file_type).test(fsentry.type?.toLowerCase())){ + else if(window.globToRegExp(allowed_file_type).test(fsentry.type?.toLowerCase())){ passes_allowed_file_type_filter = true; break; } @@ -649,11 +653,11 @@ window.refresh_user_data = async (auth_token)=>{ try{ whoami = await puter.os.user(); }catch(e){ - + // Ignored } // update local user data if(whoami){ - update_auth_data(auth_token, whoami) + window.update_auth_data(auth_token, whoami) } } @@ -675,7 +679,7 @@ window.update_auth_data = (auth_token, user)=>{ localStorage.setItem('user', JSON.stringify(window.user)); // re-initialize the Puter.js objects with the new auth token - puter.setAuthToken(auth_token, api_origin) + puter.setAuthToken(auth_token, window.api_origin) //update the logged_in_users array entry for this user if(window.user){ @@ -719,7 +723,7 @@ window.mutate_user_preferences = function(user_preferences_delta) { puter.kv.set(`user_preferences.${key}`, value); } // There may be syncing issues across multiple devices - update_user_preferences({ ...window.user_preferences, ...user_preferences_delta }); + window.update_user_preferences({ ...window.user_preferences, ...user_preferences_delta }); } window.update_user_preferences = function(user_preferences) { @@ -737,13 +741,13 @@ window.update_user_preferences = function(user_preferences) { window.sendWindowWillCloseMsg = function(iframe_element) { return new Promise(function(resolve){ - const msg_id = uuidv4(); + const msg_id = window.uuidv4(); iframe_element.contentWindow.postMessage({ msg: "windowWillClose", msg_id: msg_id }, '*'); //register callback - appCallbackFunctions[msg_id] = resolve; + window.appCallbackFunctions[msg_id] = resolve; }) } @@ -786,12 +790,12 @@ window.get_apps = async (app_names, callback)=>{ return []; let res = await $.ajax({ - url: api_origin + "/apps/"+app_names, + url: window.api_origin + "/apps/"+app_names, type: 'GET', async: true, contentType: "application/json", headers: { - "Authorization": "Bearer "+auth_token + "Authorization": "Bearer "+window.auth_token }, success: function (res){ } @@ -858,13 +862,14 @@ window.item_icon = async (fsentry)=>{ // -------------------------------------------------- // If this file is Trashed then set the name to the original name of the file before it was trashed // -------------------------------------------------- - if(fsentry.path?.startsWith(trash_path + '/')){ + if(fsentry.path?.startsWith(window.trash_path + '/')){ if(fsentry.metadata){ try{ let metadata = JSON.parse(fsentry.metadata); fsentry.name = (metadata && metadata.original_name) ? metadata.original_name : fsentry.name } catch(e){ + // Ignored } } } @@ -886,12 +891,12 @@ window.item_icon = async (fsentry)=>{ // -------------------------------------------------- // Trash // -------------------------------------------------- - else if(fsentry.shortcut_to_path && fsentry.shortcut_to_path === trash_path){ + else if(fsentry.shortcut_to_path && fsentry.shortcut_to_path === window.trash_path){ // get trash image, this is needed to get the correct empty vs full trash icon - let trash_img = $(`.item[data-path="${html_encode(trash_path)}" i] .item-icon-icon`).attr('src') + let trash_img = $(`.item[data-path="${html_encode(window.trash_path)}" i] .item-icon-icon`).attr('src') // if trash_img is undefined that's probably because trash wasn't added anywhere, do a direct lookup to see if trash is empty or no if(!trash_img){ - let trashstat = await puter.fs.stat(trash_path); + let trashstat = await puter.fs.stat(window.trash_path); if(trashstat.is_empty !== undefined && trashstat.is_empty === true) trash_img = window.icons['trash.svg']; else @@ -904,15 +909,15 @@ window.item_icon = async (fsentry)=>{ // -------------------------------------------------- else if(fsentry.is_dir){ // System Directories - if(fsentry.path === docs_path) + if(fsentry.path === window.docs_path) return {image: window.icons['folder-documents.svg'], type: 'icon'}; - else if (fsentry.path === pictures_path) + else if (fsentry.path === window.pictures_path) return { image: window.icons['folder-pictures.svg'], type: 'icon' }; - else if (fsentry.path === home_path) + else if (fsentry.path === window.home_path) return { image: window.icons['folder-home.svg'], type: 'icon' }; - else if (fsentry.path === videos_path) + else if (fsentry.path === window.videos_path) return { image: window.icons['folder-videos.svg'], type: 'icon' }; - else if (fsentry.path === desktop_path) + else if (fsentry.path === window.desktop_path) return { image: window.icons['folder-desktop.svg'], type: 'icon' }; // regular directories else @@ -1034,11 +1039,11 @@ window.item_icon = async (fsentry)=>{ */ window.show_save_account_notice_if_needed = function(message){ - getItem({ + window.getItem({ key: "save_account_notice_shown", success: async function(value){ if(!value && window.user?.is_temp){ - setItem({key: "save_account_notice_shown", value: true}); + window.setItem({key: "save_account_notice_shown", value: true}); // Show the notice setTimeout(async () => { @@ -1068,6 +1073,7 @@ window.show_save_account_notice_if_needed = function(message){ }) if(alert_resp === 'remind-later'){ + // TODO } if(alert_resp === 'save-session'){ let saved = await UIWindowSaveAccount({ @@ -1085,10 +1091,9 @@ window.show_save_account_notice_if_needed = function(message){ close_on_backdrop_click: false, } }); - if(!login_result) - $('.toolbar').prepend(ht); + // FIXME: Report login error. } - }, desktop_loading_fade_delay + 1000); + }, window.desktop_loading_fade_delay + 1000); } } }) @@ -1147,8 +1152,8 @@ window.create_folder = async(basedir, appendto_element)=>{ let dirname = basedir; let folder_name = 'New Folder'; - let newfolder_op_id = operation_id++; - operation_cancelled[newfolder_op_id] = false; + let newfolder_op_id = window.operation_id++; + window.operation_cancelled[newfolder_op_id] = false; let newfolder_progress_window_init_ts = Date.now(); let progwin; @@ -1166,10 +1171,10 @@ window.create_folder = async(basedir, appendto_element)=>{ success: function (data){ const el_created_dir = $(appendto_element).find('.item[data-path="'+html_encode(dirname)+'/'+html_encode(data.name)+'"]'); if(el_created_dir.length > 0){ - activate_item_name_editor(el_created_dir); + window.activate_item_name_editor(el_created_dir); // Add action to actions_history for undo ability - actions_history.push({ + window.actions_history.push({ operation: 'create_folder', data: el_created_dir }); @@ -1178,13 +1183,13 @@ window.create_folder = async(basedir, appendto_element)=>{ // done let newfolder_duration = (Date.now() - newfolder_progress_window_init_ts); - if( progwin && newfolder_duration >= copy_progress_hide_delay){ + if( progwin && newfolder_duration >= window.copy_progress_hide_delay){ $(progwin).close(); }else if(progwin){ setTimeout(() => { setTimeout(() => { $(progwin).close(); - }, Math.abs(copy_progress_hide_delay - newfolder_duration)); + }, Math.abs(window.copy_progress_hide_delay - newfolder_duration)); }) } } @@ -1208,10 +1213,10 @@ window.create_file = async(options)=>{ success: async function (data){ const created_file = $(appendto_element).find('.item[data-path="'+html_encode(dirname)+'/'+html_encode(data.name)+'"]'); if(created_file.length > 0){ - activate_item_name_editor(created_file); + window.activate_item_name_editor(created_file); // Add action to actions_history for undo ability - actions_history.push({ + window.actions_history.push({ operation: 'create_file', data: created_file }); @@ -1242,11 +1247,11 @@ window.create_shortcut = async(filename, is_dir, basedir, appendto_element, shor } window.copy_clipboard_items = async function(dest_path, dest_container_element){ - let copy_op_id = operation_id++; - operation_cancelled[copy_op_id] = false; + let copy_op_id = window.operation_id++; + window.operation_cancelled[copy_op_id] = false; // unselect previously selected items in the target container $(dest_container_element).children('.item-selected').removeClass('item-selected'); - update_explorer_footer_selected_items_count($(dest_container_element).closest('.window')); + window.update_explorer_footer_selected_items_count($(dest_container_element).closest('.window')); let overwrite_all = false; (async()=>{ @@ -1260,8 +1265,8 @@ window.copy_clipboard_items = async function(dest_path, dest_container_element){ const copied_item_paths = [] - for(let i=0; i${html_encode(err.entry_name)} already exists.`, buttons:[ {label: i18n('replace'), type: 'primary', value: 'replace'}, - ... (clipboard.length > 1) ? [{label: i18n('replace_all'), value: 'replace_all'}] : [], - ... (clipboard.length > 1) ? [{label: i18n('skip'), value: 'skip'}] : [{label: i18n('cancel'), value: 'cancel'}], + ... (window.clipboard.length > 1) ? [{label: i18n('replace_all'), value: 'replace_all'}] : [], + ... (window.clipboard.length > 1) ? [{label: i18n('skip'), value: 'skip'}] : [{label: i18n('cancel'), value: 'cancel'}], ] }) if(alert_resp === 'replace'){ @@ -1324,7 +1329,7 @@ window.copy_clipboard_items = async function(dest_path, dest_container_element){ // done // Add action to actions_history for undo ability - actions_history.push({ + window.actions_history.push({ operation: 'copy', data: copied_item_paths }); @@ -1332,13 +1337,13 @@ window.copy_clipboard_items = async function(dest_path, dest_container_element){ clearTimeout(progwin_timeout); let copy_duration = (Date.now() - copy_progress_window_init_ts); - if(progwin && copy_duration >= copy_progress_hide_delay){ + if(progwin && copy_duration >= window.copy_progress_hide_delay){ $(progwin).close(); }else if(progwin){ setTimeout(() => { setTimeout(() => { $(progwin).close(); - }, Math.abs(copy_progress_hide_delay - copy_duration)); + }, Math.abs(window.copy_progress_hide_delay - copy_duration)); }) } })(); @@ -1351,7 +1356,7 @@ window.copy_clipboard_items = async function(dest_path, dest_container_element){ * @param {string} dest_path - Destination path to copy items to */ window.copy_items = function(el_items, dest_path){ - let copy_op_id = operation_id++; + let copy_op_id = window.operation_id++; let overwrite_all = false; (async()=>{ let copy_progress_window_init_ts = Date.now(); @@ -1374,7 +1379,7 @@ window.copy_items = function(el_items, dest_path){ if(overwrite) item_with_same_name_already_exists = false; // cancelled? - if(operation_cancelled[copy_op_id]) + if(window.operation_cancelled[copy_op_id]) return; try{ let resp = await puter.fs.copy({ @@ -1429,7 +1434,7 @@ window.copy_items = function(el_items, dest_path){ // done // Add action to actions_history for undo ability - actions_history.push({ + window.actions_history.push({ operation: 'copy', data: copied_item_paths }); @@ -1437,13 +1442,13 @@ window.copy_items = function(el_items, dest_path){ clearTimeout(progwin_timeout); let copy_duration = (Date.now() - copy_progress_window_init_ts); - if(progwin && copy_duration >= copy_progress_hide_delay){ + if(progwin && copy_duration >= window.copy_progress_hide_delay){ $(progwin).close(); }else if(progwin){ setTimeout(() => { setTimeout(() => { $(progwin).close(); - }, Math.abs(copy_progress_hide_delay - copy_duration)); + }, Math.abs(window.copy_progress_hide_delay - copy_duration)); }) } })() @@ -1483,8 +1488,8 @@ window.delete_item = async function(el_item, descendants_only = false){ $(`.item[data-uid='${$(el_item).attr('data-uid')}']`).removeItems(); // update parent windows' item counts $(parent_windows).each(function(index){ - update_explorer_footer_item_count(this); - update_explorer_footer_selected_items_count(this); + window.update_explorer_footer_item_count(this); + window.update_explorer_footer_selected_items_count(this); }); // update all shortcuts to this item $(`.item[data-shortcut_to_path="${html_encode($(el_item).attr('data-path'))}" i]`).attr(`data-shortcut_to_path`, ''); @@ -1497,15 +1502,15 @@ window.delete_item = async function(el_item, descendants_only = false){ window.move_clipboard_items = function (el_target_container, target_path){ let dest_path = target_path === undefined ? $(el_target_container).attr('data-path') : target_path; let el_items = []; - if(clipboard.length > 0){ - for(let i=0; i 0){ + for(let i=0; i 0) - move_items(el_items, dest_path); + window.move_items(el_items, dest_path); } - clipboard = []; + window.clipboard = []; } /** @@ -1534,7 +1539,7 @@ window.trigger_download = (paths)=>{ let urls = []; for (let index = 0; index < paths.length; index++) { urls.push({ - download: api_origin + "/down?path=" + paths[index] + "&auth_token=" + auth_token, + download: window.api_origin + "/down?path=" + paths[index] + "&auth_token=" + window.auth_token, filename: path.basename(paths[index]), }); } @@ -1553,7 +1558,7 @@ window.trigger_download = (paths)=>{ * @param {*} options */ window.launch_app = async (options)=>{ - const uuid = options.uuid ?? uuidv4(); + const uuid = options.uuid ?? window.uuidv4(); let icon, title, file_signature; const window_options = options.window_options ?? {}; @@ -1562,15 +1567,13 @@ window.launch_app = async (options)=>{ } // try to get 3rd-party app info - let app_info = options.app_obj ?? await get_apps(options.name); + let app_info = options.app_obj ?? await window.get_apps(options.name); //----------------------------------- // icon //----------------------------------- if(app_info.icon) icon = app_info.icon; - else if(app_info.icon) - icon = window.icons['app.svg']; else if(options.name === 'explorer') icon = window.icons['folder.svg']; else @@ -1636,7 +1639,7 @@ window.launch_app = async (options)=>{ title = 'Trash'; } else if(!options.path) - title = root_dirname; + title = window.root_dirname; else title = path.dirname(options.path); @@ -1681,7 +1684,7 @@ window.launch_app = async (options)=>{ iframe_url = new URL('https://'+options.name+'.' + window.app_domain + `/index.html`); } else if ( app_info.index_url.startsWith(BUILTIN_PREFIX) ) { const name = app_info.index_url.slice(BUILTIN_PREFIX.length); - iframe_url = new URL(`${gui_origin}/builtin/${name}`); + iframe_url = new URL(`${window.gui_origin}/builtin/${name}`); } else { iframe_url = new URL(app_info.index_url); } @@ -1708,7 +1711,7 @@ window.launch_app = async (options)=>{ iframe_url.searchParams.append('puter.item.accessed', file_signature.fsentry_accessed); iframe_url.searchParams.append('puter.item.modified', file_signature.fsentry_modified); iframe_url.searchParams.append('puter.item.created', file_signature.fsentry_created); - iframe_url.searchParams.append('puter.domain', app_domain); + iframe_url.searchParams.append('puter.domain', window.app_domain); } else if(options.readURL){ iframe_url.searchParams.append('puter.item.name', options.filename); @@ -1720,7 +1723,7 @@ window.launch_app = async (options)=>{ if (app_info.godmode && app_info.godmode === 1){ // Add auth_token to GODMODE apps - iframe_url.searchParams.append('puter.auth.token', auth_token); + iframe_url.searchParams.append('puter.auth.token', window.auth_token); iframe_url.searchParams.append('puter.auth.username', window.user.username); iframe_url.searchParams.append('puter.domain', window.app_domain); } else if (options.token){ @@ -1734,7 +1737,7 @@ window.launch_app = async (options)=>{ let response = await fetch(window.api_origin + "/auth/get-user-app-token", { "headers": { "Content-Type": "application/json", - "Authorization": "Bearer "+ auth_token, + "Authorization": "Bearer "+ window.auth_token, }, "body": JSON.stringify({app_uid: app_info.uid ?? app_info.uuid}), "method": "POST", @@ -1745,8 +1748,8 @@ window.launch_app = async (options)=>{ } } - if(api_origin) - iframe_url.searchParams.append('puter.api_origin', api_origin); + if(window.api_origin) + iframe_url.searchParams.append('puter.api_origin', window.api_origin); // Add options.params to URL if(options.params){ @@ -1797,17 +1800,17 @@ window.launch_app = async (options)=>{ // send post request to /rao to record app open if(options.name !== 'explorer'){ // add the app to the beginning of the array - launch_apps.recent.unshift(app_info); + window.launch_apps.recent.unshift(app_info); // dedupe the array by uuid, uid, and id - launch_apps.recent = _.uniqBy(launch_apps.recent, 'name'); + window.launch_apps.recent = _.uniqBy(window.launch_apps.recent, 'name'); // limit to window.launch_recent_apps_count - launch_apps.recent = launch_apps.recent.slice(0, window.launch_recent_apps_count); + window.launch_apps.recent = window.launch_apps.recent.slice(0, window.launch_recent_apps_count); // send post request to /rao to record app open $.ajax({ - url: api_origin + "/rao", + url: window.api_origin + "/rao", type: 'POST', data: JSON.stringify({ original_client_socket_id: window.socket?.id, @@ -1816,7 +1819,7 @@ window.launch_app = async (options)=>{ async: true, contentType: "application/json", headers: { - "Authorization": "Bearer "+auth_token + "Authorization": "Bearer "+window.auth_token }, }) } @@ -1864,13 +1867,13 @@ window.open_item = async function(options){ //---------------------------------------------------------------- // Is this a shortcut whose source is trashed? //---------------------------------------------------------------- - else if(is_shortcut && shortcut_to_path.startsWith(trash_path + '/')){ + else if(is_shortcut && shortcut_to_path.startsWith(window.trash_path + '/')){ UIAlert(`This shortcut can't be opened because its source has been deleted.`) } //---------------------------------------------------------------- // Is this a trashed file? //---------------------------------------------------------------- - else if(item_path.startsWith(trash_path + '/')){ + else if(item_path.startsWith(window.trash_path + '/')){ UIAlert(`This item can't be opened because it's in the trash. To use this item, first drag it out of the Trash.`) } //---------------------------------------------------------------- @@ -1939,21 +1942,21 @@ window.open_item = async function(options){ } // done let busy_duration = (Date.now() - busy_init_ts); - if( busy_duration >= busy_indicator_hide_delay){ + if( busy_duration >= window.busy_indicator_hide_delay){ $el_parent_window.close(); }else{ setTimeout(() => { // close this dialog $el_parent_window.close(); - }, Math.abs(busy_indicator_hide_delay - busy_duration)); + }, Math.abs(window.busy_indicator_hide_delay - busy_duration)); } } //---------------------------------------------------------------- // Does the user have a preference for this file type? //---------------------------------------------------------------- - else if(!associated_app_name && !is_dir && user_preferences[`default_apps${path.extname(item_path).toLowerCase()}`]) { - launch_app({ - name: user_preferences[`default_apps${path.extname(item_path).toLowerCase()}`], + else if(!associated_app_name && !is_dir && window.user_preferences[`default_apps${path.extname(item_path).toLowerCase()}`]) { + window.launch_app({ + name: window.user_preferences[`default_apps${path.extname(item_path).toLowerCase()}`], file_path: item_path, window_title: path.basename(item_path), maximized: options.maximized, @@ -1964,7 +1967,7 @@ window.open_item = async function(options){ // Is there an app associated with this item? //---------------------------------------------------------------- else if(associated_app_name !== ''){ - launch_app({ + window.launch_app({ name: associated_app_name, }) } @@ -1975,7 +1978,7 @@ window.open_item = async function(options){ UIWindow({ path: item_path, title: path.basename(item_path), - icon: await item_icon({is_dir: true, path: item_path}), + icon: await window.item_icon({is_dir: true, path: item_path}), uid: $(el_item).attr('data-uid'), is_dir: is_dir, app: 'explorer', @@ -1989,11 +1992,11 @@ window.open_item = async function(options){ // Dir with an open window: change the path of the open window //---------------------------------------------------------------- else if($el_parent_window.length > 0 && is_dir){ - window_nav_history[parent_win_id] = window_nav_history[parent_win_id].slice(0, window_nav_history_current_position[parent_win_id]+1); - window_nav_history[parent_win_id].push(item_path); - window_nav_history_current_position[parent_win_id]++; + window.window_nav_history[parent_win_id] = window.window_nav_history[parent_win_id].slice(0, window.window_nav_history_current_position[parent_win_id]+1); + window.window_nav_history[parent_win_id].push(item_path); + window.window_nav_history_current_position[parent_win_id]++; - update_window_path($el_parent_window, item_path); + window.update_window_path($el_parent_window, item_path); } //---------------------------------------------------------------- // all other cases: try to open using an app @@ -2006,7 +2009,7 @@ window.open_item = async function(options){ // get all info needed to open an item try{ open_item_meta = await $.ajax({ - url: api_origin + "/open_item", + url: window.api_origin + "/open_item", type: 'POST', contentType: "application/json", data: JSON.stringify({ @@ -2014,19 +2017,20 @@ window.open_item = async function(options){ path: fspath ?? undefined, }), headers: { - "Authorization": "Bearer "+auth_token + "Authorization": "Bearer "+window.auth_token }, statusCode: { 401: function () { - logout(); + window.logout(); }, }, }); }catch(err){ + // Ignored } // get a list of suggested apps for this file type. - let suggested_apps = open_item_meta?.suggested_apps ?? await suggest_apps_for_fsentry({uid: fsuid, path: fspath}); + let suggested_apps = open_item_meta?.suggested_apps ?? await window.suggest_apps_for_fsentry({uid: fsuid, path: fspath}); //--------------------------------------------- // No suitable apps, ask if user would like to @@ -2037,7 +2041,7 @@ window.open_item = async function(options){ // If .zip file, unzip it //--------------------------------------------- if(path.extname(item_path) === '.zip'){ - unzipItem(item_path); + window.unzipItem(item_path); return; } const alert_resp = await UIAlert( @@ -2054,7 +2058,7 @@ window.open_item = async function(options){ } ]) if(alert_resp === 'download_file'){ - trigger_download([item_path]); + window.trigger_download([item_path]); } return; } @@ -2062,7 +2066,7 @@ window.open_item = async function(options){ // First suggested app is default app to open this item //--------------------------------------------- else{ - launch_app({ + window.launch_app({ name: suggested_apps[0].name, token: open_item_meta.token, file_path: item_path, @@ -2084,8 +2088,8 @@ window.open_item = async function(options){ * @returns {Promise} */ window.move_items = async function(el_items, dest_path, is_undo = false){ - let move_op_id = operation_id++; - operation_cancelled[move_op_id] = false; + let move_op_id = window.operation_id++; + window.operation_cancelled[move_op_id] = false; // -------------------------------------------------------- // Optimization: in case all items being moved @@ -2126,7 +2130,7 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ let el_item = el_items[i]; // if operation cancelled by user, stop - if(operation_cancelled[move_op_id]) + if(window.operation_cancelled[move_op_id]) return; // cannot move an immutable item, skip it @@ -2164,13 +2168,14 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ try{ metadata = JSON.parse(metadata) }catch(e){ + // Ignored } } let new_name; // user cancelled? - if(operation_cancelled[move_op_id]) + if(window.operation_cancelled[move_op_id]) return; // indicates whether this is a recycling operation @@ -2179,7 +2184,7 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ // -------------------------------------------------------- // Trashing // -------------------------------------------------------- - if(dest_path === trash_path){ + if(dest_path === window.trash_path){ new_name = $(el_item).attr('data-uid'); metadata = { original_name: $(el_item).attr('data-name'), @@ -2193,12 +2198,12 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ // change trash icons to 'trash-full.svg' $(`[data-app="trash"]`).find('.taskbar-icon > img').attr('src', window.icons['trash-full.svg']); - $(`.item[data-path="${html_encode(trash_path)}" i], .item[data-shortcut_to_path="${html_encode(trash_path)}" i]`).find('.item-icon > img').attr('src', window.icons['trash-full.svg']); - $(`.window[data-path="${html_encode(trash_path)}" i]`).find('.window-head-icon').attr('src', window.icons['trash-full.svg']); + $(`.item[data-path="${html_encode(window.trash_path)}" i], .item[data-shortcut_to_path="${html_encode(window.trash_path)}" i]`).find('.item-icon > img').attr('src', window.icons['trash-full.svg']); + $(`.window[data-path="${html_encode(window.trash_path)}" i]`).find('.window-head-icon').attr('src', window.icons['trash-full.svg']); } // moving an item into a trashed directory? deny. - else if(dest_path.startsWith(trash_path)){ + else if(dest_path.startsWith(window.trash_path)){ $(progwin).close(); UIAlert('Cannot move items into a deleted folder.'); return; @@ -2212,7 +2217,7 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ new_name = metadata.original_name; metadata = {}; untrashed_at_least_one_item = true; - path_to_show_on_progwin = trash_path + '/' + new_name; + path_to_show_on_progwin = window.trash_path + '/' + new_name; } // -------------------------------------------------------- @@ -2251,13 +2256,13 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ $(this).removeItems(); // update parent windows' item counts and selected item counts in their footers $(parent_windows).each(function(){ - update_explorer_footer_item_count(this); - update_explorer_footer_selected_items_count(this) + window.update_explorer_footer_item_count(this); + window.update_explorer_footer_selected_items_count(this) }); }) // if trashing, close windows of trashed items and its descendants - if(dest_path === trash_path){ + if(dest_path === window.trash_path){ $(`.window[data-path="${html_encode($(el_item).attr('data-path'))}" i]`).close(); // todo this has to be case-insensitive but the `i` selector doesn't work on ^= $(`.window[data-path^="${html_encode($(el_item).attr('data-path'))}/"]`).close(); @@ -2267,16 +2272,17 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ else{ // todo this has to be case-insensitive but the `i` selector doesn't work on ^= $(`.window[data-path^="${html_encode($(el_item).attr('data-path'))}/"], .window[data-path="${html_encode($(el_item).attr('data-path'))}" i]`).each(function(){ - update_window_path(this, $(this).attr('data-path').replace($(el_item).attr('data-path'), path.join(dest_path, fsentry.name))); + window.update_window_path(this, $(this).attr('data-path').replace($(el_item).attr('data-path'), path.join(dest_path, fsentry.name))); }) } - if(dest_path === trash_path){ + if(dest_path === window.trash_path){ // if trashing dir... if($(el_item).attr('data-is_dir') === '1'){ // disassociate all its websites // todo, some client-side check to see if this dir has at least one associated website before sending ajax request - puter.hosting.delete(dir_uuid) + // FIXME: dir_uuid is not defined, is this the same as the data-uid attribute? + // puter.hosting.delete(dir_uuid) $(`.mywebsites-dir-path[data-uuid="${$(el_item).attr('data-uid')}"]`).remove(); // remove the website badge from all instances of the dir @@ -2299,14 +2305,14 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ associated_app_name: fsentry.associated_app?.name, uid: fsentry.uid, path: fsentry.path, - icon: await item_icon(fsentry), - name: (dest_path === trash_path) ? $(el_item).attr('data-name') : fsentry.name, + icon: await window.item_icon(fsentry), + name: (dest_path === window.trash_path) ? $(el_item).attr('data-name') : fsentry.name, is_dir: fsentry.is_dir, size: fsentry.size, type: fsentry.type, modified: fsentry.modified, is_selected: false, - is_shared: (dest_path === trash_path) ? false : fsentry.is_shared, + is_shared: (dest_path === window.trash_path) ? false : fsentry.is_shared, is_shortcut: fsentry.is_shortcut, shortcut_to: fsentry.shortcut_to, shortcut_to_path: fsentry.shortcut_to_path, @@ -2328,7 +2334,7 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ immutable: false, uid: dir.uid, path: dir.path, - icon: await item_icon(dir), + icon: await window.item_icon(dir), name: dir.name, size: dir.size, type: dir.type, @@ -2340,12 +2346,12 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ suggested_apps: dir.suggested_apps, }); } - sort_items(item_container); + window.sort_items(item_container); }); //sort each container $(`.item-container[data-path="${html_encode(dest_path)}" i]`).each(function(){ - sort_items(this, $(this).attr('data-sort_by'), $(this).attr('data-sort_order')) + window.sort_items(this, $(this).attr('data-sort_by'), $(this).attr('data-sort_order')) }) }catch(err){ // ----------------------------------------------------------------------- @@ -2388,14 +2394,14 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ // check if trash is empty if(untrashed_at_least_one_item){ - const trash = await puter.fs.stat(trash_path); + const trash = await puter.fs.stat(window.trash_path); if(window.socket){ window.socket.emit('trash.is_empty', {is_empty: trash.is_empty}); } if(trash.is_empty){ $(`[data-app="trash"]`).find('.taskbar-icon > img').attr('src', window.icons['trash.svg']); - $(`.item[data-path="${html_encode(trash_path)}" i]`).find('.item-icon > img').attr('src', window.icons['trash.svg']); - $(`.window[data-path="${html_encode(trash_path)}" i]`).find('.window-head-icon').attr('src', window.icons['trash.svg']); + $(`.item[data-path="${html_encode(window.trash_path)}" i]`).find('.item-icon > img').attr('src', window.icons['trash.svg']); + $(`.window[data-path="${html_encode(window.trash_path)}" i]`).find('.window-head-icon').attr('src', window.icons['trash.svg']); } } } @@ -2410,13 +2416,13 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ // DONE! close progress window with delay to allow user to see 100% progress // ----------------------------------------------------------------------- // Add action to actions_history for undo ability - if(!is_undo && dest_path !== trash_path){ - actions_history.push({ + if(!is_undo && dest_path !== window.trash_path){ + window.actions_history.push({ operation: 'move', data: moved_items, }); - }else if(!is_undo && dest_path === trash_path){ - actions_history.push({ + }else if(!is_undo && dest_path === window.trash_path){ + window.actions_history.push({ operation: 'delete', data: moved_items, }); @@ -2425,7 +2431,7 @@ window.move_items = async function(el_items, dest_path, is_undo = false){ if(progwin){ setTimeout(() => { $(progwin).close(); - }, copy_progress_hide_delay); + }, window.copy_progress_hide_delay); } } @@ -2638,7 +2644,7 @@ window.init_upload_using_dialog = function(el_target_container, target_path = nu const files = $('#upload-file-dialog')[0].files; if(files.length > 0){ try{ - upload_items(files, target_path); + window.upload_items(files, target_path); } catch(err){ UIAlert(err.message ?? err) @@ -2656,7 +2662,7 @@ window.upload_items = async function(items, dest_path){ let upload_progress_window; let opid; - if(dest_path == trash_path){ + if(dest_path == window.trash_path){ UIAlert('Uploading to trash is not allowed!'); return; } @@ -2676,11 +2682,11 @@ window.upload_items = async function(items, dest_path){ // cancel btn $(upload_progress_window).find('.upload-cancel-btn').on('click', function(e){ $(upload_progress_window).close(); - show_save_account_notice_if_needed(); + window.show_save_account_notice_if_needed(); xhr.abort(); }) // add to active_uploads - active_uploads[opid] = 0; + window.active_uploads[opid] = 0; }, // start start: async function(){ @@ -2692,7 +2698,7 @@ window.upload_items = async function(items, dest_path){ $(`[data-upload-operation-id="${operation_id}"]`).find('.upload-progress-bar').css( 'width', op_progress+'%'); $(`[data-upload-operation-id="${operation_id}"]`).find('.upload-progress-percent').html(op_progress+'%'); // update active_uploads - active_uploads[opid] = op_progress; + window.active_uploads[opid] = op_progress; // update title if window is not visible if(document.visibilityState !== "visible"){ update_title_based_on_uploads(); @@ -2711,32 +2717,32 @@ window.upload_items = async function(items, dest_path){ files.push(items.path) } - actions_history.push({ + window.actions_history.push({ operation: 'upload', data: files }); // close progress window after a bit of delay for a better UX setTimeout(() => { setTimeout(() => { - $(upload_progress_window).close(); - show_save_account_notice_if_needed(); - }, Math.abs(upload_progress_hide_delay)); + $(upload_progress_window).close(); + window.show_save_account_notice_if_needed(); + }, Math.abs(window.upload_progress_hide_delay)); }) // remove from active_uploads - delete active_uploads[opid]; + delete window.active_uploads[opid]; }, // error error: async function(err){ $(upload_progress_window).close(); // UIAlert(err?.message ?? 'An error occurred while uploading.'); // remove from active_uploads - delete active_uploads[opid]; + delete window.active_uploads[opid]; }, // abort abort: async function(operation_id){ // console.log('upload aborted'); // remove from active_uploads - delete active_uploads[opid]; + delete window.active_uploads[opid]; } } ); @@ -2763,13 +2769,13 @@ window.empty_trash = async function(){ // only show progress window if it takes longer than 500ms to create folder let init_ts = Date.now(); let progwin; - let op_id = uuidv4(); + let op_id = window.uuidv4(); let progwin_timeout = setTimeout(async () => { progwin = await UIWindowProgressEmptyTrash({operation_id: op_id}); }, 500); await puter.fs.delete({ - paths: trash_path, + paths: window.trash_path, descendantsOnly: true, recursive: true, success: async function (resp){ @@ -2779,24 +2785,24 @@ window.empty_trash = async function(){ } // use the 'empty trash' icon for Trash $(`[data-app="trash"]`).find('.taskbar-icon > img').attr('src', window.icons['trash.svg']); - $(`.item[data-path="${html_encode(trash_path)}" i], .item[data-shortcut_to_path="${html_encode(trash_path)}" i]`).find('.item-icon > img').attr('src', window.icons['trash.svg']); - $(`.window[data-path="${trash_path}"]`).find('.window-head-icon').attr('src', window.icons['trash.svg']); + $(`.item[data-path="${html_encode(window.trash_path)}" i], .item[data-shortcut_to_path="${html_encode(window.trash_path)}" i]`).find('.item-icon > img').attr('src', window.icons['trash.svg']); + $(`.window[data-path="${window.trash_path}"]`).find('.window-head-icon').attr('src', window.icons['trash.svg']); // remove all items with trash paths // todo this has to be case-insensitive but the `i` selector doesn't work on ^= - $(`.item[data-path^="${trash_path}/"]`).removeItems(); + $(`.item[data-path^="${window.trash_path}/"]`).removeItems(); // update the footer item count for Trash - update_explorer_footer_item_count($(`.window[data-path="${trash_path}"]`)) + window. update_explorer_footer_item_count($(`.window[data-path="${window.trash_path}"]`)) // close progress window clearTimeout(progwin_timeout); setTimeout(() => { $(progwin).close(); - }, Math.max(0, copy_progress_hide_delay - (Date.now() - init_ts))); + }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - init_ts))); }, error: async function (err){ clearTimeout(progwin_timeout); setTimeout(() => { $(progwin).close(); - }, Math.max(0, copy_progress_hide_delay - (Date.now() - init_ts))); + }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - init_ts))); } }); } @@ -2812,10 +2818,10 @@ window.copy_to_clipboard = async function(text){ } window.getUsage = () => { - return fetch(api_origin + "/drivers/usage", { + return fetch(window.api_origin + "/drivers/usage", { headers: { "Content-Type": "application/json", - "Authorization": "Bearer " + auth_token + "Authorization": "Bearer " + window.auth_token }, method: "GET" }) @@ -2988,14 +2994,14 @@ window.zipItems = async function(el_items, targetDirPath, download = true) { clearTimeout(progwin_timeout); setTimeout(() => { $(progwin).close(); - }, Math.max(0, copy_progress_hide_delay - (Date.now() - start_ts))); + }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); }) .catch(function (err) { // close progress window clearTimeout(progwin_timeout); setTimeout(() => { $(progwin).close(); - }, Math.max(0, copy_progress_hide_delay - (Date.now() - start_ts))); + }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); // handle errors console.error("Error in zipping files: ", err); @@ -3063,7 +3069,7 @@ window.unzipItem = async function(itemPath) { clearTimeout(progwin_timeout); setTimeout(() => { $(progwin).close(); - }, Math.max(0, copy_progress_hide_delay - (Date.now() - start_ts))); + }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); }).catch(function (e) { // UIAlert(e.message); @@ -3071,7 +3077,7 @@ window.unzipItem = async function(itemPath) { clearTimeout(progwin_timeout); setTimeout(() => { $(progwin).close(); - }, Math.max(0, copy_progress_hide_delay - (Date.now() - start_ts))); + }, Math.max(0, window.copy_progress_hide_delay - (Date.now() - start_ts))); }) } @@ -3083,7 +3089,7 @@ window.rename_file = async(options, new_name, old_name, old_path, el_item, el_it success: async (fsentry)=>{ // Add action to actions_history for undo ability if (!is_undo) - actions_history.push({ + window.actions_history.push({ operation: 'rename', data: {options, new_name, old_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url} }); @@ -3092,7 +3098,7 @@ window.rename_file = async(options, new_name, old_name, old_path, el_item, el_it const old_extension = path.extname(old_name); const new_extension = path.extname(new_name); if(old_extension !== new_extension){ - suggest_apps_for_fsentry({ + window.suggest_apps_for_fsentry({ uid: options.uid, onSuccess: function(suggested_apps){ options.suggested_apps = suggested_apps; @@ -3101,14 +3107,14 @@ window.rename_file = async(options, new_name, old_name, old_path, el_item, el_it } // Set new item name - $(`.item[data-uid='${$(el_item).attr('data-uid')}'] .item-name`).html(html_encode(truncate_filename(new_name, TRUNCATE_LENGTH)).replaceAll(' ', ' ')); + $(`.item[data-uid='${$(el_item).attr('data-uid')}'] .item-name`).html(html_encode(window.truncate_filename(new_name, window.TRUNCATE_LENGTH)).replaceAll(' ', ' ')); $(el_item_name).show(); // Hide item name editor $(el_item_name_editor).hide(); // Set new icon - const new_icon = (options.is_dir ? window.icons['folder.svg'] : (await item_icon(fsentry)).image); + const new_icon = (options.is_dir ? window.icons['folder.svg'] : (await window.item_icon(fsentry)).image); $(el_item_icon).find('.item-icon-icon').attr('src', new_icon); // Set new data-name @@ -3147,15 +3153,15 @@ window.rename_file = async(options, new_name, old_name, old_path, el_item, el_it // Update the 'Sites Cache' if($(el_item).attr('data-has_website') === '1') - await update_sites_cache(); + await window.update_sites_cache(); // Update website_url - website_url = determine_website_url(new_path); + website_url = window.determine_website_url(new_path); $(el_item).attr('data-website_url', website_url); // Update all exact-matching windows $(`.window-${options.uid}`).each(function(){ - update_window_path(this, options.path); + window.update_window_path(this, options.path); }) // Set new name for corresponding open windows @@ -3163,12 +3169,12 @@ window.rename_file = async(options, new_name, old_name, old_path, el_item, el_it // Re-sort all matching item containers $(`.item[data-uid='${$(el_item).attr('data-uid')}']`).parent('.item-container').each(function(){ - sort_items(this, $(el_item).closest('.item-container').attr('data-sort_by'), $(el_item).closest('.item-container').attr('data-sort_order')); + window.sort_items(this, $(el_item).closest('.item-container').attr('data-sort_by'), $(el_item).closest('.item-container').attr('data-sort_order')); }) }, error: function (err){ // reset to old name - $(el_item_name).text(truncate_filename(options.name, TRUNCATE_LENGTH)); + $(el_item_name).text(window.truncate_filename(options.name, window.TRUNCATE_LENGTH)); $(el_item_name).show(); // hide item name editor @@ -3202,28 +3208,28 @@ window.delete_item_with_path = async function(path){ } window.undo_last_action = async()=>{ - if (actions_history.length > 0) { - const last_action = actions_history.pop(); + if (window.actions_history.length > 0) { + const last_action = window.actions_history.pop(); // Undo the create file action if (last_action.operation === 'create_file' || last_action.operation === 'create_folder') { const lastCreatedItem = last_action.data; - undo_create_file_or_folder(lastCreatedItem); + window.undo_create_file_or_folder(lastCreatedItem); } else if(last_action.operation === 'rename') { const {options, new_name, old_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url} = last_action.data; - rename_file(options, old_name, new_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url, true); + window.rename_file(options, old_name, new_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url, true); } else if(last_action.operation === 'upload') { const files = last_action.data; - undo_upload(files); + window.undo_upload(files); } else if(last_action.operation === 'copy') { const files = last_action.data; - undo_copy(files); + window.undo_copy(files); } else if(last_action.operation === 'move') { const items = last_action.data; - undo_move(items); + window.undo_move(items); } else if(last_action.operation === 'delete') { const items = last_action.data; - undo_delete(items); + window.undo_delete(items); } } } @@ -3246,23 +3252,23 @@ window.undo_copy = async(files)=>{ window.undo_move = async(items)=>{ for (const item of items) { - const el = await get_html_element_from_options(item.options); + const el = await window.get_html_element_from_options(item.options); console.log(item.original_path) - move_items([el], path.dirname(item.original_path), true); + window.move_items([el], path.dirname(item.original_path), true); } } window.undo_delete = async(items)=>{ for (const item of items) { - const el = await get_html_element_from_options(item.options); + const el = await window.get_html_element_from_options(item.options); let metadata = $(el).attr('data-metadata') === '' ? {} : JSON.parse($(el).attr('data-metadata')) - move_items([el], path.dirname(metadata.original_path), true); + window.move_items([el], path.dirname(metadata.original_path), true); } } window.get_html_element_from_options = async function(options){ - const item_id = global_element_id++; + const item_id = window.global_element_id++; options.disabled = options.disabled ?? false; options.visible = options.visible ?? 'visible'; // one of 'visible', 'revealed', 'hidden' @@ -3279,7 +3285,7 @@ window.get_html_element_from_options = async function(options){ options.sort_container_after_append = (options.sort_container_after_append !== undefined ? options.sort_container_after_append : false); const is_shared_with_me = (options.path !== '/'+window.user.username && !options.path.startsWith('/'+window.user.username+'/')); - let website_url = determine_website_url(options.path); + let website_url = window.determine_website_url(options.path); // do a quick check to see if the target parent has any file type restrictions const appendto_allowed_file_types = $(options.appendTo).attr('data-allowed_file_types') @@ -3321,7 +3327,7 @@ window.get_html_element_from_options = async function(options){ h += ``; // size h += `
`; - h += `${options.size ? byte_format(options.size) : '-'}`; + h += `${options.size ? window.byte_format(options.size) : '-'}`; h += `
`; // type h += `
`; @@ -3378,7 +3384,7 @@ window.get_html_element_from_options = async function(options){ h += `
`; // name - h += `${html_encode(truncate_filename(options.name, TRUNCATE_LENGTH)).replaceAll(' ', ' ')}` + h += `${html_encode(window.truncate_filename(options.name, window.TRUNCATE_LENGTH)).replaceAll(' ', ' ')}` // name editor h += `` h += ``; @@ -3393,9 +3399,9 @@ window.store_auto_arrange_preference = (preference)=>{ window.get_auto_arrange_data = async()=>{ const preferenceValue = await puter.kv.get('user_preferences.auto_arrange_desktop'); - is_auto_arrange_enabled = preferenceValue === null ? true : preferenceValue; + window.is_auto_arrange_enabled = preferenceValue === null ? true : preferenceValue; const positions = await puter.kv.get('desktop_item_positions') - desktop_item_positions = (!positions || typeof positions !== 'object' || Array.isArray(positions)) ? {} : positions; + window.desktop_item_positions = (!positions || typeof positions !== 'object' || Array.isArray(positions)) ? {} : positions; } window.clear_desktop_item_positions = async(el_desktop)=>{ @@ -3405,14 +3411,14 @@ window.clear_desktop_item_positions = async(el_desktop)=>{ $(el_item).css('left', ''); $(el_item).css('top', ''); }); - if(reset_item_positions){ - delete_desktop_item_positions() + if(window.reset_item_positions){ + window.delete_desktop_item_positions() } } window.set_desktop_item_positions = async(el_desktop)=>{ $(el_desktop).find('.item').each(async function(){ - const position = desktop_item_positions[$(this).attr('data-uid')] + const position = window.desktop_item_positions[$(this).attr('data-uid')] const el_item = $(this)[0]; if(position){ $(el_item).css('position', 'absolute'); @@ -3423,11 +3429,11 @@ window.set_desktop_item_positions = async(el_desktop)=>{ } window.save_desktop_item_positions = ()=>{ - puter.kv.set('desktop_item_positions', desktop_item_positions); + puter.kv.set('desktop_item_positions', window.desktop_item_positions); } window.delete_desktop_item_positions = ()=>{ - desktop_item_positions = {} + window.desktop_item_positions = {} puter.kv.del('desktop_item_positions'); } @@ -3435,7 +3441,7 @@ window.change_clock_visible = (clock_visible) => { let newValue = clock_visible || window.user_preferences.clock_visible; - newValue === 'auto' && is_fullscreen() ? $('#clock').show() : $('#clock').hide(); + newValue === 'auto' && window.is_fullscreen() ? $('#clock').show() : $('#clock').hide(); newValue === 'show' && $('#clock').show(); newValue === 'hide' && $('#clock').hide(); @@ -3459,14 +3465,14 @@ window.window_for_app_instance = (instance_id) => { // Finds the `iframe` element for the given app instance ID window.iframe_for_app_instance = (instance_id) => { - return $(window_for_app_instance(instance_id)).find('.window-app-iframe').get(0); + return $(window.window_for_app_instance(instance_id)).find('.window-app-iframe').get(0); }; // Run any callbacks to say that the app has launched window.report_app_launched = (instance_id, { uses_sdk = true }) => { const child_launch_callback = window.child_launch_callbacks[instance_id]; if (child_launch_callback) { - const parent_iframe = iframe_for_app_instance(child_launch_callback.parent_instance_id); + const parent_iframe = window.iframe_for_app_instance(child_launch_callback.parent_instance_id); // send confirmation to requester window parent_iframe.contentWindow.postMessage({ msg: 'childAppLaunched', @@ -3480,7 +3486,7 @@ window.report_app_launched = (instance_id, { uses_sdk = true }) => { // Run any callbacks to say that the app has closed window.report_app_closed = (instance_id) => { - const el_window = window_for_app_instance(instance_id); + const el_window = window.window_for_app_instance(instance_id); // notify parent app, if we have one, that we're closing const parent_id = el_window.dataset['parent_instance_id']; @@ -3511,7 +3517,7 @@ window.check_password_strength = (password) => { hasUpperCase: /[A-Z]/.test(password), hasLowerCase: /[a-z]/.test(password), hasNumber: /\d/.test(password), - hasSpecialChar: /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password) + hasSpecialChar: /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(password) }; let overallPass = true;