Merge pull request #348 from AtkinsSJ/eslint

Set up eslint, and try to resolve the issues it finds
This commit is contained in:
Eric Dubé
2024-05-03 12:28:21 -04:00
committed by GitHub
124 changed files with 1855 additions and 1463 deletions
+106
View File
@@ -0,0 +1,106 @@
import js from "@eslint/js";
import globals from "globals";
export default [
js.configs.recommended,
{
// Global ignores
ignores: [
"**/*.min.js",
"**/src/lib/**",
"**/dist/",
"packages/backend/src/public/assets/**",
],
},
{
// Top-level and tools use Node
files: [
"tools/**/*.js",
],
languageOptions: {
globals: {
...globals.node,
}
}
},
{
// Back end
files: [
"packages/backend/**/*.js",
"dev-server.js",
"utils.js",
],
languageOptions: {
globals: {
...globals.node,
"kv": true,
}
}
},
{
// Front end
files: [
"index.js",
"initgui.js",
"src/**/*.js",
"packages/**/*.js",
],
ignores: [
"packages/backend/**/*.js",
],
languageOptions: {
globals: {
...globals.browser,
...globals.commonjs,
"puter": true,
"i18n": true,
"html_encode": true,
"html_decode": true,
"isMobile": true,
// Libraries
"saveAs": true, // FileSaver
"iro": true, // iro.js color picker
"$": true, // jQuery
"jQuery": true, // jQuery
"JSZip": true, // JSZip
"_": true, // lodash
"QRCode": true, // qrcode
"io": true, // socket.io
"timeago": true, // timeago
"SelectionArea": true, // viselect
}
}
},
{
// Tests
files: [
"**/test/**/*.js",
],
languageOptions: {
globals: {
...globals.mocha,
}
}
},
{
// Phoenix
files: [
"packages/phoenix/**/*.js",
],
languageOptions: {
globals: {
...globals.node,
}
}
},
{
// Global rule settings
rules: {
"no-prototype-builtins": "off", // Complains about any use of hasOwnProperty()
"no-unused-vars": "off", // Temporary, we just have a lot of these
"no-debugger": "warn",
"no-async-promise-executor": "off", // We do this quite often and it's fine
}
},
];
+598 -200
View File
File diff suppressed because it is too large Load Diff
+3
View File
@@ -11,10 +11,13 @@
"lib": "lib"
},
"devDependencies": {
"@eslint/js": "^9.1.1",
"chalk": "^4.1.0",
"clean-css": "^5.3.2",
"dotenv": "^16.4.5",
"eslint": "^9.1.1",
"express": "^4.18.2",
"globals": "^15.0.0",
"html-entities": "^2.3.3",
"nodemon": "^3.1.0",
"uglify-js": "^3.17.4",
@@ -16,6 +16,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const { APIError } = require('../../api/APIError');
module.exports = class FlagParam {
constructor (srckey, options) {
this.srckey = srckey;
@@ -16,6 +16,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const { APIError } = require('../../api/APIError');
module.exports = class StringParam {
constructor (srckey, options) {
this.srckey = srckey;
@@ -1,25 +0,0 @@
/*
* Copyright (C) 2024 Puter Technologies Inc.
*
* This file is part of Puter.
*
* Puter is free software: you can redistribute it and/or modify
* 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 <https://www.gnu.org/licenses/>.
*/
{
registries: {
type: {
description: 'high-level types'
}
}
}
@@ -1,31 +0,0 @@
/*
* Copyright (C) 2024 Puter Technologies Inc.
*
* This file is part of Puter.
*
* Puter is free software: you can redistribute it and/or modify
* 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 <https://www.gnu.org/licenses/>.
*/
class Registry {
constructor() {
this._registry = {};
}
put(name, value) {
this._registry[name] = value;
}
get(name) {
return this._registry[name];
}
}
@@ -138,7 +138,6 @@ class FilesystemService extends AdvancedBase {
return permission.startsWith('fs:');
},
checker: async (actor, permission) => {
debugger;
if ( !(actor.type instanceof UserActorType) ) {
return undefined;
}
@@ -363,7 +362,7 @@ class FilesystemService extends AdvancedBase {
[new_path, old_path.length + 1, old_path + '%', user_id]
);
const log = services.get('log-service').create('update_child_paths');
const log = this.services.get('log-service').create('update_child_paths');
log.info(`updated ${old_path} -> ${new_path}`);
monitor.end();
@@ -118,7 +118,7 @@ class BatchExecutor extends AdvancedBase {
alarm: true,
});
e = APIError.adapt(e);
e = APIError.adapt(e); // eslint-disable-line no-ex-assign
}
// Consume stream if there's a file
@@ -18,6 +18,9 @@
*/
const { stream_to_buffer } = require("../../util/streamutil");
const { HLFilesystemOperation } = require("./definitions");
const { chkperm } = require('../../helpers');
const { LLRead } = require('../ll_operations/ll_read');
const { APIError } = require('../../api/APIError');
/**
* HLDataRead reads a stream of objects from a file containing structured data.
@@ -38,6 +41,7 @@ class HLDataRead extends HLFilesystemOperation {
const {
fsNode,
version_id,
} = this.values;
if ( ! await fsNode.exists() ) {
@@ -85,6 +89,7 @@ class HLDataRead extends HLFilesystemOperation {
}
_stream_jsonl_lines_to_objects (stream) {
const { PassThrough } = this.modules.stream;
const output_stream = new PassThrough();
(async () => {
for await (const line of stream) {
@@ -63,6 +63,7 @@ class MkTree extends HLFilesystemOperation {
async _run () {
const { values, context } = this;
const fs = context.get('services').get('filesystem');
await this.create_branch_({
parent_node: values.parent || await fs.node(new RootNodeSelector()),
@@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const APIError = require("../../api/APIError");
const { chkperm, validate_fsentry_name, is_ancestor_of } = require("../../helpers");
const { chkperm, validate_fsentry_name, is_ancestor_of, df, get_user } = require("../../helpers");
const { LLMove } = require("../ll_operations/ll_move");
const { RootNodeSelector } = require("../node/selectors");
const { HLFilesystemOperation } = require("./definitions");
@@ -41,7 +41,7 @@ class HLRead extends HLFilesystemOperation {
}
const ll_read = new LLRead();
const stream = await ll_read.run({
let stream = await ll_read.run({
fsNode, actor,
version_id,
...(byte_count !== undefined ? {
@@ -19,6 +19,7 @@
const { chkperm } = require("../../helpers");
const { Context } = require("../../util/context");
const { HLFilesystemOperation } = require("./definitions");
const { APIError } = require('../../api/APIError');
class HLStat extends HLFilesystemOperation {
static MODULES = {
@@ -64,10 +64,6 @@ class PuterPath {
return ! this.isAbsolute();
}
get hasRelativePortion () {
}
get reference () {
if ( this.isAbsolute ) return this.constructor.NULL_UUID;
@@ -30,6 +30,7 @@
- easier to diagnose stuck operations
*/
/* eslint-disable */
const STEPS_COPY_CONTENTS = [
{
@@ -91,7 +91,7 @@ class LLRead extends LLFilesystemOperation {
const context = a.iget('context');
const svc_fileCache = context.get('services').get('file-cache');
const { fsNode } = a.values();
const { fsNode, offset, length } = a.values();
const maybe_buffer = await svc_fileCache.try_get(fsNode, a.log);
if ( maybe_buffer ) {
@@ -19,6 +19,7 @@
const { Context } = require("../../util/context");
const { ParallelTasks } = require("../../util/otelutil");
const { LLFilesystemOperation } = require("./definitions");
const { APIError } = require("../../api/APIError");
class LLRmNode extends LLFilesystemOperation {
async _run () {
@@ -17,6 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const { PuterPath } = require("../lib/PuterPath");
const _path = require('path');
// Redis keys:
// <env>:<service>:<class>:<type>:<property>:<id>
@@ -22,10 +22,12 @@ This module contains functions that validate filesystem operations.
*/
/* eslint-disable no-control-regex */
const config = require("../config");
const path_excludes = () => /[\x00-\x1F]/g;
const node_excludes = () => /[\/\x00-\x1F]/g;
const node_excludes = () => /[/\x00-\x1F]/g;
// this characters are not allowed in path names because
// they might be used to trick the user into thinking
+6 -6
View File
@@ -681,7 +681,7 @@ const get_descendants_0 = async (path, user, depth, return_thumbnail = false) =>
[user.id]
);
// users that have shared files/dirs with this user
sharing_users = await db.read(
const sharing_users = await db.read(
`SELECT DISTINCT(owner_user_id), user.username
FROM share
INNER JOIN user ON user.id = share.owner_user_id
@@ -719,7 +719,7 @@ const get_descendants_0 = async (path, user, depth, return_thumbnail = false) =>
return [];
// shared files/dirs with this user
shared_fsentries = await db.read(
const shared_fsentries = await db.read(
`SELECT
fsentries.id, fsentries.user_id, fsentries.uuid, fsentries.parent_uid, fsentries.bucket, fsentries.bucket_region,
fsentries.name, fsentries.shortcut_to, fsentries.is_shortcut, fsentries.metadata, fsentries.is_dir, fsentries.modified,
@@ -899,7 +899,7 @@ const get_descendants = async (...args) => {
if ( ! result || ! result[0] ) {
errors.report('id2path.select', {
alarm: true,
message: `no result for ${entry_uid}: ${e.message}`,
message: `no result for ${entry_uid}`,
extra: {
entry_uid,
}
@@ -953,12 +953,12 @@ function cp(source_path, dest_path, user, overwrite, change_name, check_perms =
throw new Error(`legacy copy function called`);
}
isString = function (variable) {
function isString(variable) {
return typeof variable === 'string' || variable instanceof String;
}
// checks to see if given variable is an object
isObject = function (variable) {
function isObject(variable) {
return variable !== null && typeof variable === 'object';
}
@@ -1809,7 +1809,7 @@ async function get_taskbar_items(user) {
try {
taskbar_items_from_db = JSON.parse(user.taskbar_items);
}catch(e){
// ignore errors
}
}
@@ -86,6 +86,7 @@ class ValidationES extends BaseES {
} catch ( e ) {
if ( ! (e instanceof APIError) ) {
console.log('THIS IS HAPPENING', e);
// eslint-disable-next-line no-ex-assign
e = APIError.create('field_invalid', null, {
key: prop.name,
converted_from_another_error: true,
+1 -1
View File
@@ -163,7 +163,7 @@ module.exports = {
},
async adapt (value, { descriptor }) {
if ( descriptor.debug ) {
debugger;
debugger; // eslint-disable-line no-debugger
}
if ( ! descriptor.service ) return value;
if ( ! value ) return null;
+1 -1
View File
@@ -402,7 +402,7 @@ router.all('*', async function(req, res, next) {
});
} catch (e) {
console.error('error from sendFile', e);
return res.status(err.statusCode).send('Error /apps/')
return res.status(e.statusCode).send('Error /apps/')
}
}
// --------------------------------------
@@ -21,6 +21,7 @@ const { get_app, get_user } = require("../../helpers");
const { UserActorType } = require("../../services/auth/Actor");
const { DB_READ } = require("../../services/database/consts");
const { Context } = require("../../util/context");
const { APIError } = require('../../api/APIError');
module.exports = eggspress('/auth/list-permissions', {
subdomain: 'api',
@@ -1,6 +1,7 @@
const eggspress = require("../../api/eggspress");
const { UserActorType } = require("../../services/auth/Actor");
const { Context } = require("../../util/context");
const { APIError } = require('../../api/APIError');
module.exports = eggspress('/auth/list-sessions', {
subdomain: 'api',
@@ -19,6 +19,7 @@
const eggspress = require("../../api/eggspress");
const { UserActorType } = require("../../services/auth/Actor");
const { Context } = require("../../util/context");
const { APIError } = require('../../api/APIError');
module.exports = eggspress('/auth/revoke-user-app', {
subdomain: 'api',
@@ -40,7 +40,6 @@ router.post('/delete-site', auth, express.json(), async (req, res, next)=>{
return res.status(400).send('site_uuid is required')
// modules
const {} = require('../helpers');
const db = req.services.get('database').get(DB_WRITE, 'subdomains:legacy');
await db.write(
@@ -143,7 +143,7 @@ module.exports = eggspress('/drivers/usage', {
// usages.apps.push(usage);
}
for ( k in usages.apps ) {
for ( const k in usages.apps ) {
usages.apps[k] = Object.values(usages.apps[k]);
}
+4 -3
View File
@@ -65,8 +65,9 @@ const script = async function script () {
return await response.json();
};
/* global window */
window.addEventListener('message', async event => {
const { id, interface, method, params } = event.data;
const { id, interface: interface_, method, params } = event.data;
let has_file = false;
for ( const k in params ) {
if ( params[k] instanceof File ) {
@@ -75,11 +76,11 @@ const script = async function script () {
}
}
const result = has_file ? await fcall({
interface_name: interface,
interface_name: interface_,
method_name: method,
params,
}) : await call({
interface_name: interface,
interface_name: interface_,
method_name: method,
params,
});
@@ -26,6 +26,7 @@ const Busboy = require('busboy');
const { BatchExecutor } = require("../../../filesystem/batch/BatchExecutor");
const { TeePromise } = require("../../../util/promise");
const { EWMA, MovingMode } = require("../../../util/opmath");
const { get_app } = require('../../../helpers');
const commands = require('../../../filesystem/batch/commands.js').commands;
@@ -221,28 +222,6 @@ module.exports = eggspress('/batch', {
let ps = [];
busboy.on('file', async (fieldname, stream, detais) => {
if (false) {
ended[i] = false;
ps[i] = new TeePromise();
const this_i = i;
stream.on('end', () => {
ps[this_i].resolve();
ended[this_i] = true;
batch_widget.ec++;
});
if ( i > 0 ) {
if ( ! ended[i-1] ) {
batch_widget.sc++;
// stream.pause();
batch_widget.wc++;
await Promise.all(Array(i).fill(0).map((_, j) => ps[j]));
batch_widget.wc--;
// stream.resume();
}
}
i++;
}
if ( batch_exe.total_tbd ) {
batch_exe.total_tbd = false;
batch_widget.ic = pending_operations.length;
@@ -66,18 +66,6 @@ module.exports = eggspress('/copy', {
x.set(operationTraceSvc.ckey('frame'), frame);
}
// TEMP: Testing copy with its own sql queue
if ( false ) {
const x = Context.get();
const svc = new ProxyContainer(x.get('services'));
const s = new DatabaseFSEntryService({
services: x.get('services'),
label: 'Copy-DatabaseFSEntryService',
});
svc.set('systemFSEntryService', s);
x.set('services', svc);
}
const log = req.services.get('log-service').create('copy');
const filesystem = req.services.get('filesystem');
@@ -103,7 +91,6 @@ module.exports = eggspress('/copy', {
source: req.values.source,
new_name: req.body.new_name,
new_name: req.body.new_name,
overwrite: req.body.overwrite ?? false,
dedupe_name,
@@ -74,15 +74,4 @@ module.exports = eggspress('/read', {
res.set('Content-Type', 'application/octet-stream');
stream.pipe(res);
return;
const filesystem = req.services.get('filesystem');
await filesystem.read(req.fs, res, {
...req.values,
user: req.user,
version_id: req.query.version_id,
line_count,
byte_count,
});
});
@@ -49,12 +49,10 @@ module.exports = eggspress('/token-read', {
const actor = await svc_auth.authenticate_from_token(access_jwt);
if ( ! actor ) {
throw new Error('A');
throw APIError.create('token_auth_failed');
}
if ( ! (actor.type instanceof AccessTokenActorType) ) {
throw new Error('B');
throw APIError.create('token_auth_failed');
}
@@ -98,16 +96,5 @@ module.exports = eggspress('/token-read', {
res.setHeader('Content-Type', mime_type);
stream.pipe(res);
return;
const filesystem = req.services.get('filesystem');
await filesystem.read(req.fs, res, {
...req.values,
user: req.user,
version_id: req.query.version_id,
line_count,
byte_count,
});
});
@@ -62,7 +62,7 @@ class PuterSiteMiddleware extends AdvancedBase {
req.subdomains[0] === 'devtest' ? 'devtest' :
req.hostname.slice(0, -1 * (config.static_hosting_domain.length + 1));
let path = (req.baseUrl + req.path) ?? 'index.html';
let path = (req.baseUrl + req.path) || 'index.html';
const context = Context.get();
const services = context.get('services');
+1 -1
View File
@@ -45,7 +45,7 @@ module.exports = eggspress('/open_item', {
const subject = req.values.subject;
const actor = Context.get('actor');
if ( ! actor.type instanceof UserActorType ) {
if ( ! (actor.type instanceof UserActorType) ) {
throw APIError.create('forbidden');
}
+1 -6
View File
@@ -19,7 +19,7 @@
"use strict"
const express = require('express');
const router = new express.Router();
const {get_taskbar_items, username_exists, send_email_verification_code, send_email_verification_token, invalidate_cached_user} = require('../helpers');
const {get_taskbar_items, username_exists, send_email_verification_code, send_email_verification_token, invalidate_cached_user, get_user } = require('../helpers');
const auth = require('../middleware/auth.js');
const config = require('../config');
const { Context } = require('../util/context');
@@ -85,11 +85,6 @@ router.post('/save_account', auth, express.json(), async (req, res, next)=>{
// get pseudo user, if exists
let pseudo_user = await db.read(`SELECT * FROM user WHERE email = ? AND password IS NULL`, [req.body.email]);
pseudo_user = pseudo_user[0];
// get uuid user, if exists
if(req.body.uuid){
uuid_user = await db.read(`SELECT * FROM user WHERE uuid = ? LIMIT 1`, [req.body.uuid]);
uuid_user = uuid_user[0];
}
// send_confirmation_code
req.body.send_confirmation_code = req.body.send_confirmation_code ?? true;
+4 -3
View File
@@ -34,7 +34,7 @@ module.exports = eggspress('/sign', {
allowedMethods: ['POST'],
}, async (req, res, next)=>{
const actor = Context.get('actor');
if ( ! actor.type instanceof UserActorType ) {
if ( ! (actor.type instanceof UserActorType) ) {
throw APIError.create('forbidden');
}
@@ -62,7 +62,8 @@ module.exports = eggspress('/sign', {
app = await get_app({ uid: req.body.app_uid });
if ( ! app ) {
throw APIError.create('no_suitable_app', null, { entry_name: subject.entry.name });
// FIXME: subject.entry.name isn't available here
throw APIError.create('no_suitable_app', null); //, { entry_name: subject.entry.name });
}
// Generate user-app token
const svc_auth = Context.get('services').get('auth');
@@ -111,7 +112,7 @@ module.exports = eggspress('/sign', {
const svc_acl = Context.get('services').get('acl');
if ( ! await svc_acl.check(actor, node, 'see') ) {
throw await svc_acl.get_safe_acl_error(actor, subject, 'see');
throw await svc_acl.get_safe_acl_error(actor, node, 'see');
}
if ( app !== null ) {
@@ -27,7 +27,7 @@ class ComplainAboutVersionsService extends BaseService {
if ( ! current_version_data ) {
this.log.warn(
`failed to check ${current_version} in the EOL database`
`failed to check ${major} in the EOL database`
);
return;
}
@@ -52,7 +52,7 @@ class ContextInitService extends BaseService {
key, value,
});
}
register_async_factory (key, factory) {
register_async_factory (key, async_factory) {
this.mw.register_initializer({
key, async_factory,
});
@@ -20,6 +20,7 @@ const { AdvancedBase } = require("@heyputer/puter-js-common");
class StorageService extends AdvancedBase {
constructor ({ services }) {
super(services);
//
}
}
@@ -255,7 +255,7 @@ class WebServerService extends BaseService {
onFinished(res, () => {
if ( res.statusCode !== 500 ) return;
if ( req.__error_handled ) return;
const alarm = services.get('alarm');
const alarm = this.services.get('alarm');
alarm.create('responded-500', 'server sent a 500 response', {
error: req.__error_source,
url: req.url,
@@ -55,27 +55,6 @@ class AuthService extends BaseService {
if ( ! decoded.hasOwnProperty('type') ) {
throw new LegacyTokenError();
const user = await this.db.requireRead(
"SELECT * FROM `user` WHERE `uuid` = ? LIMIT 1",
[decoded.uuid],
);
if ( ! user[0] ) {
throw APIError.create('token_auth_failed');
}
if ( user[0].suspended ) {
throw APIError.create('account_suspended');
}
const actor_type = new UserActorType({
user: user[0],
});
return new Actor({
user_uid: decoded.uuid,
type: actor_type,
});
}
if ( decoded.type === 'session' ) {
@@ -1,6 +1,6 @@
const BaseService = require("../BaseService");
def = o => {
const def = o => {
for ( let k in o ) {
if ( typeof o[k] === 'string' ) {
o[k] = { short: o[k] };
@@ -15,7 +15,7 @@ def = o => {
};
}
defv = o => {
const defv = o => {
return {
to_short: o,
to_long: Object.keys(o).reduce((acc, key) => {
@@ -60,6 +60,7 @@ class BaseImplementation extends AdvancedBase {
async _sla_enforcement (method) {
const context = Context.get();
const services = context.get('services');
const method_key = `${this.constructor.ID}:${method}`;
const svc_sla = services.get('sla');
@@ -41,6 +41,7 @@ class PuterDriverProxy extends AdvancedBase {
}
constructor ({ target }) {
super();
this.target = target;
}
@@ -119,10 +119,6 @@ class TypeSpec extends BasicBase {
equals (other) {
return this.raw.$ === other.raw.$;
// for ( k in this.raw ) {
// if ( this.raw[k] !== other.raw[k] ) return false;
// }
return true;
}
toString () {
@@ -91,12 +91,13 @@ class ExpectationService extends BaseService {
purgeExpectations_ () {
return;
for ( let i=0 ; i < this.expectations_.length ; i++ ) {
if ( this.expectations_[i].check() ) {
this.expectations_[i] = null;
}
}
this.expectations_ = this.expectations_.filter(v => v !== null);
// TODO: Re-enable this
// for ( let i=0 ; i < this.expectations_.length ; i++ ) {
// if ( this.expectations_[i].check() ) {
// this.expectations_[i] = null;
// }
// }
// this.expectations_ = this.expectations_.filter(v => v !== null);
}
expect_eventually ({ workUnit, checkpoint }) {
@@ -18,6 +18,7 @@
*/
const pdjs = require('@pagerduty/pdjs');
const BaseService = require('../BaseService');
const util = require('util');
class PagerService extends BaseService {
async _construct () {
+1
View File
@@ -23,6 +23,7 @@
* @param {*} str
*/
const visible_length = (str) => {
// eslint-disable-next-line no-control-regex
return str.replace(/\x1b\[[0-9;]*m/g, '').length;
};
+1 -1
View File
@@ -365,7 +365,7 @@ const stuck_detector_stream = (source, {
return stream;
}
string_to_stream = (str, chunk_size) => {
const string_to_stream = (str, chunk_size) => {
const s = new Readable();
s._read = () => {}; // redundant? see update below
// split string into chunks
+1 -1
View File
@@ -39,7 +39,7 @@ const osclink = (url, text) => {
return `\x1B]8;;${url}\x1B\\${text}\x1B]8;;\x1B\\`;
}
format_as_usd = (amount) => {
const format_as_usd = (amount) => {
if ( amount < 0.01 ) {
if ( amount < 0.00001 ) {
// scientific notation
+1
View File
@@ -19,6 +19,7 @@
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
import process from 'node:process';
const configFile = process.env.CONFIG_FILE ?? 'config/dev.js';
await import(`./${configFile}`);
+1 -1
View File
@@ -83,7 +83,7 @@ export class ANSIShell extends EventTarget {
Object.defineProperty(this.env, 'PWD', {
enumerable: true,
get: () => this.variables.pwd,
set: v => this.variables.pwd = v
set: v => { this.variables.pwd = v }
})
Object.defineProperty(this.env, 'ROWS', {
enumerable: true,
@@ -27,7 +27,6 @@ export default {
let result;
try {
if ( ! ctx.locals.args ) debugger;
result = parseArgs({ ...spec, args: ctx.locals.args });
} catch (e) {
await ctx.externs.out.write(
@@ -40,9 +40,9 @@ export class SignalReader extends ProxyReader {
return { value, done };
}
const tmp_value = value;
let tmp_value = value;
if ( ! tmp_value instanceof Uint8Array ) {
if ( ! (tmp_value instanceof Uint8Array) ) {
tmp_value = encoder.encode(value);
}
@@ -21,10 +21,7 @@ import { buildParserFirstHalf } from "./buildParserFirstHalf.js";
import { buildParserSecondHalf } from "./buildParserSecondHalf.js";
export class PuterShellParser {
constructor () {
{
}
}
constructor () {}
parseLineForSyntax () {}
parseLineForProcessing (input) {
const sp = new StrataParser();
@@ -68,7 +68,6 @@ export class Coupler {
break;
}
if ( this.on_ ) {
if ( ! value ) debugger;
await this.target.write(value);
}
}
@@ -151,11 +151,7 @@ const ReadlineProcessorBuilder = builder => builder
if ( completions.length > 1 ) {
let inCommon = '';
for ( let i=0 ; true ; i++ ) {
if ( ! completions.every(completion => {
return completion.length > i;
}) ) break;
for ( let i=0 ; completions.every(completion => completion.length > i) ; i++ ) {
let matches = true;
const chrFirst = completions[0][i];
@@ -104,7 +104,7 @@ const echo_escapes = {
caller.output(NUL);
return;
}
caller.output(String.fromCharCode(Number.parseInt(hexchars, 8)));
caller.output(String.fromCharCode(Number.parseInt(octchars, 8)));
},
'\\': caller => caller.output('\\'),
};
@@ -126,9 +126,9 @@ export default {
break;
}
// "Locale's abbreviated month name."
// b: "Locale's abbreviated month name."
// h: "A synonym for %b."
case 'b':
// "A synonym for %b."
case 'h': {
output += date.toLocaleDateString(locale, { timeZone: timeZone, month: 'short' });
break;
@@ -78,7 +78,7 @@ export default {
}
}
const do_grep_line = async ( line ) => {
const do_grep_line = async ( line, lineNumber ) => {
if ( line.endsWith('\n') ) line = line.slice(0, -1);
const re = new RegExp(
pattern,
@@ -97,10 +97,9 @@ export default {
);
if ( lxor(values['invert-match'], re.test(line)) ) {
const lineNumber = values['line-number'] ? i + 1 : '';
const lineToPrint =
lineNumber ? lineNumber + ':' : '' +
line;
const lineToPrint = values['line-number']
? `${lineNumber + 1}:${line}`
: line;
console.log(`LINE{${lineToPrint}}`);
await ctx.externs.out.write(lineToPrint + '\n');
@@ -111,7 +110,7 @@ export default {
for ( let i=0 ; i < lines.length ; i++ ) {
const line = lines[i];
await do_grep_line(line);
await do_grep_line(line, i);
}
}
@@ -139,10 +138,10 @@ export default {
for ( let file of files ) {
if ( file === '-' ) {
for ( ;; ) {
for ( let i = 0; ; i++) {
const { value, done } = await ctx.externs.in_.read();
if ( done ) break;
await do_grep_line(value);
await do_grep_line(value, i);
}
} else {
file = resolveRelativePath(ctx.vars, file);
@@ -24,7 +24,7 @@ export class ScriptCommandProvider {
async lookup (id, { ctx }) {
const { filesystem } = ctx.platform;
const is_path = id.match(/^[.\/]/);
const is_path = id.match(/^[./]/);
if ( ! is_path ) return undefined;
const absPath = resolveRelativePath(ctx.vars, id);
+2
View File
@@ -16,6 +16,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* eslint-disable no-control-regex */
export function lengthIgnoringEscapes(text) {
const escape = '\x1b';
// There are a lot of different ones, but we only use graphics-mode ones, so only parse those for now.
@@ -60,8 +60,6 @@ const upload = async function(items, dirPath, options = {}){
for(let i=0; i<items.length; i++){
if(items[i] instanceof DataTransferItem || items[i] instanceof DataTransferItemList){
seemsToBeParsedDataTransferItems = true;
}else{
}
}
}
@@ -171,6 +169,7 @@ const upload = async function(items, dirPath, options = {}){
return reject({code: 'NOT_ENOUGH_SPACE', message: 'Not enough storage space available.'});
}
}catch(e){
// Ignored
}
}
+2 -2
View File
@@ -415,8 +415,8 @@ class UI extends EventListener {
// Item Watch response
else if(e.data.msg === "itemChanged" && e.data.data && e.data.data.uid){
//excute callback
if(itemWatchCallbackFunctions[e.data.data.uid] && typeof itemWatchCallbackFunctions[e.data.data.uid] === 'function')
itemWatchCallbackFunctions[e.data.data.uid](e.data.data);
if(this.itemWatchCallbackFunctions[e.data.data.uid] && typeof this.itemWatchCallbackFunctions[e.data.data.uid] === 'function')
this.itemWatchCallbackFunctions[e.data.data.uid](e.data.data);
}
// Broadcasts
else if (e.data.msg === 'broadcast') {
+2
View File
@@ -1,3 +1,5 @@
/* eslint-disable */
// TODO: Make these more compatible with eslint
naughtyStrings = [
"文件.txt", // Chinese characters
"файл.txt", // Cyrillic characters
+2
View File
@@ -1,3 +1,5 @@
/* eslint-disable */
// TODO: Make these more compatible with eslint
window.kvTests = [
testSetKeyWithValue = async function() {
try {
+1
View File
@@ -19,6 +19,7 @@
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
import process from 'node:process';
const configFile = process.env.CONFIG_FILE ?? 'config/dev.js';
await import(`./${configFile}`);
+1
View File
@@ -21,6 +21,7 @@
*/
export class PTT {
constructor(pty) {
const encoder = new TextEncoder();
this.readableStream = new ReadableStream({
start: controller => {
this.readController = controller;
+3
View File
@@ -5,6 +5,9 @@
// The implementation of this in packages/backend might not
// work in older versions of node, so we instead re-implement
// it here.
import console from 'node:console';
import process from 'node:process';
const surrounding_box = (col, lines) => {
const lengths = lines.map(line => line.length);
+57 -56
View File
@@ -50,11 +50,11 @@ window.addEventListener('message', async (event) => {
// --------------------------------------------------------
// A response to a GUI message received from the app.
// --------------------------------------------------------
if (typeof event.data.original_msg_id !== "undefined" && typeof appCallbackFunctions[event.data.original_msg_id] !== "undefined") {
if (typeof event.data.original_msg_id !== "undefined" && typeof window.appCallbackFunctions[event.data.original_msg_id] !== "undefined") {
// Execute callback
appCallbackFunctions[event.data.original_msg_id](event.data);
window.appCallbackFunctions[event.data.original_msg_id](event.data);
// Remove this callback function since it won't be needed again
delete appCallbackFunctions[event.data.original_msg_id];
delete window.appCallbackFunctions[event.data.original_msg_id];
// Done
return;
@@ -78,10 +78,10 @@ window.addEventListener('message', async (event) => {
return;
}
const $el_parent_window = $(window_for_app_instance(event.data.appInstanceID));
const $el_parent_window = $(window.window_for_app_instance(event.data.appInstanceID));
const parent_window_id = $el_parent_window.attr('data-id');
const $el_parent_disable_mask = $el_parent_window.find('.window-disable-mask');
const target_iframe = iframe_for_app_instance(event.data.appInstanceID);
const target_iframe = window.iframe_for_app_instance(event.data.appInstanceID);
const msg_id = event.data.uuid;
const app_name = $(target_iframe).attr('data-app');
const app_uuid = $el_parent_window.attr('data-app_uuid');
@@ -103,6 +103,7 @@ window.addEventListener('message', async (event) => {
// windowFocused
//-------------------------------------------------
else if(event.data.msg === 'windowFocused'){
// TODO: Respond to this
}
//--------------------------------------------------------
// ALERT
@@ -177,7 +178,7 @@ window.addEventListener('message', async (event) => {
else if(event.data.msg === 'setItem' && event.data.key && event.data.value){
// todo: validate key and value to avoid unnecessary api calls
return await $.ajax({
url: api_origin + "/setItem",
url: window.api_origin + "/setItem",
type: 'POST',
data: JSON.stringify({
app: app_uuid,
@@ -187,11 +188,11 @@ window.addEventListener('message', async (event) => {
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
statusCode: {
401: function () {
logout();
window.logout();
},
},
success: function (fsentry){
@@ -204,7 +205,7 @@ window.addEventListener('message', async (event) => {
else if(event.data.msg === 'getItem' && event.data.key){
// todo: validate key to avoid unnecessary api calls
$.ajax({
url: api_origin + "/getItem",
url: window.api_origin + "/getItem",
type: 'POST',
data: JSON.stringify({
key: event.data.key,
@@ -213,11 +214,11 @@ window.addEventListener('message', async (event) => {
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
statusCode: {
401: function () {
logout();
window.logout();
},
},
success: function (result){
@@ -236,7 +237,7 @@ window.addEventListener('message', async (event) => {
else if(event.data.msg === 'removeItem' && event.data.key){
// todo: validate key to avoid unnecessary api calls
$.ajax({
url: api_origin + "/removeItem",
url: window.api_origin + "/removeItem",
type: 'POST',
data: JSON.stringify({
key: event.data.key,
@@ -245,11 +246,11 @@ window.addEventListener('message', async (event) => {
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
statusCode: {
401: function () {
logout();
window.logout();
},
},
success: function (result){
@@ -265,7 +266,7 @@ window.addEventListener('message', async (event) => {
//--------------------------------------------------------
else if(event.data.msg === 'showOpenFilePicker'){
// Auth
if(!is_auth() && !(await UIWindowSignup({referrer: app_name})))
if(!window.is_auth() && !(await UIWindowSignup({referrer: app_name})))
return;
// Disable parent window
@@ -306,7 +307,7 @@ window.addEventListener('message', async (event) => {
//--------------------------------------------------------
else if(event.data.msg === 'showDirectoryPicker'){
// Auth
if(!is_auth() && !(await UIWindowSignup({referrer: app_name})))
if(!window.is_auth() && !(await UIWindowSignup({referrer: app_name})))
return;
// Disable parent window
@@ -345,7 +346,7 @@ window.addEventListener('message', async (event) => {
// setWindowTitle
//--------------------------------------------------------
else if(event.data.msg === 'setWindowTitle' && event.data.new_title !== undefined){
const el_window = window_for_app_instance(event.data.appInstanceID);
const el_window = window.window_for_app_instance(event.data.appInstanceID);
// set window title
$(el_window).find(`.window-head-title`).html(html_encode(event.data.new_title));
// send confirmation to requester window
@@ -357,7 +358,7 @@ window.addEventListener('message', async (event) => {
// setMenubar
//--------------------------------------------------------
else if(event.data.msg === 'setMenubar') {
const el_window = window_for_app_instance(event.data.appInstanceID);
const el_window = window.window_for_app_instance(event.data.appInstanceID);
console.error(`EXPERIMENTAL: setMenubar is a work-in-progress`);
const hydrator = puter.util.rpc.getHydrator({
@@ -573,13 +574,13 @@ window.addEventListener('message', async (event) => {
else if(event.data.msg === 'launchApp'){
// TODO: Determine if the app is allowed to launch child apps? We may want to limit this to prevent abuse.
// remember app for launch callback later
const child_instance_id = uuidv4();
const child_instance_id = window.uuidv4();
window.child_launch_callbacks[child_instance_id] = {
parent_instance_id: event.data.appInstanceID,
launch_msg_id: msg_id,
};
// launch child app
launch_app({
window.launch_app({
name: event.data.app_name ?? app_name,
args: event.data.args ?? {},
parent_instance_id: event.data.appInstanceID,
@@ -594,7 +595,7 @@ window.addEventListener('message', async (event) => {
event.data.path = path.resolve(event.data.path);
// join with appdata dir
const file_path = path.join(appdata_path, app_uuid, event.data.path);
const file_path = path.join(window.appdata_path, app_uuid, event.data.path);
puter.fs.sign(app_uuid, {
path: file_path,
@@ -626,16 +627,16 @@ window.addEventListener('message', async (event) => {
//--------------------------------------------------------
// todo appdata should be provided from the /open_item api call
else if(event.data.msg === 'getAppData'){
if(appdata_signatures[app_uuid]){
if(window.appdata_signatures[app_uuid]){
target_iframe.contentWindow.postMessage({
msg: "getAppDataSucceeded",
original_msg_id: msg_id,
item: appdata_signatures[app_uuid],
item: window.appdata_signatures[app_uuid],
}, '*');
}
// make app directory if it doesn't exist
puter.fs.mkdir({
path: path.join( appdata_path, app_uuid),
path: path.join( window.appdata_path, app_uuid),
rename: false,
overwrite: false,
success: function(dir){
@@ -644,7 +645,7 @@ window.addEventListener('message', async (event) => {
action: 'write',
success: function(signature){
signature = signature.items;
appdata_signatures[app_uuid] = signature;
window.appdata_signatures[app_uuid] = signature;
// send confirmation to requester window
target_iframe.contentWindow.postMessage({
msg: "getAppDataSucceeded",
@@ -661,7 +662,7 @@ window.addEventListener('message', async (event) => {
action: 'write',
success: function(signature){
signature = signature.items;
appdata_signatures[app_uuid] = signature;
window.appdata_signatures[app_uuid] = signature;
// send confirmation to requester window
target_iframe.contentWindow.postMessage({
msg: "getAppDataSucceeded",
@@ -679,7 +680,7 @@ window.addEventListener('message', async (event) => {
//--------------------------------------------------------
else if(event.data.msg === 'requestPermission'){
// auth
if(!is_auth() && !(await UIWindowSignup({referrer: app_name})))
if(!window.is_auth() && !(await UIWindowSignup({referrer: app_name})))
return;
// options must be an object
@@ -714,7 +715,7 @@ window.addEventListener('message', async (event) => {
//--------------------------------------------------------
else if(event.data.msg === 'showFontPicker'){
// auth
if(!is_auth() && !(await UIWindowSignup({referrer: app_name})))
if(!window.is_auth() && !(await UIWindowSignup({referrer: app_name})))
return;
// set options
@@ -742,7 +743,7 @@ window.addEventListener('message', async (event) => {
//--------------------------------------------------------
else if(event.data.msg === 'showColorPicker'){
// Auth
if(!is_auth() && !(await UIWindowSignup({referrer: app_name})))
if(!window.is_auth() && !(await UIWindowSignup({referrer: app_name})))
return;
// set options
@@ -770,7 +771,7 @@ window.addEventListener('message', async (event) => {
//--------------------------------------------------------
else if(event.data.msg === 'setWallpaper'){
// Auth
if(!is_auth() && !(await UIWindowSignup({referrer: app_name})))
if(!window.is_auth() && !(await UIWindowSignup({referrer: app_name})))
return;
// No options?
@@ -780,7 +781,7 @@ window.addEventListener('message', async (event) => {
// /set-desktop-bg
try{
await $.ajax({
url: api_origin + "/set-desktop-bg",
url: window.api_origin + "/set-desktop-bg",
type: 'POST',
data: JSON.stringify({
url: event.data.readURL,
@@ -790,11 +791,11 @@ window.addEventListener('message', async (event) => {
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
statusCode: {
401: function () {
logout();
window.logout();
},
},
});
@@ -822,7 +823,7 @@ window.addEventListener('message', async (event) => {
//--------------------------------------------------------
else if(event.data.msg === 'showSaveFilePicker'){
//auth
if(!is_auth() && !(await UIWindowSignup({referrer: app_name})))
if(!window.is_auth() && !(await UIWindowSignup({referrer: app_name})))
return;
//disable parent window
@@ -854,7 +855,7 @@ window.addEventListener('message', async (event) => {
// -------------------------------------
if(event.data.url){
// download progress tracker
let dl_op_id = operation_id++;
let dl_op_id = window.operation_id++;
// upload progress tracker defaults
window.progress_tracker[dl_op_id] = [];
@@ -869,8 +870,8 @@ window.addEventListener('message', async (event) => {
url: event.data.url,
name: path.basename(target_path),
dest_path: path.dirname(target_path),
auth_token: auth_token,
api_origin: api_origin,
auth_token: window.auth_token,
api_origin: window.api_origin,
dedupe_name: false,
overwrite: false,
operation_id: dl_op_id,
@@ -936,7 +937,7 @@ window.addEventListener('message', async (event) => {
immutable: res.immutable,
associated_app_name: res.associated_app?.name,
path: target_path,
icon: await item_icon(res),
icon: await window.item_icon(res),
name: path.basename(target_path),
uid: res.uid,
size: res.size,
@@ -948,10 +949,10 @@ window.addEventListener('message', async (event) => {
});
// sort each window
$(`.item-container[data-path="${html_encode(path.dirname(target_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'))
});
$(el_filedialog_window).close();
show_save_account_notice_if_needed();
window.show_save_account_notice_if_needed();
}
catch(err){
// item with same name exists
@@ -995,13 +996,13 @@ window.addEventListener('message', async (event) => {
// 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_filedialog_window).close();
}else{
setTimeout(() => {
// close this dialog
$(el_filedialog_window).close();
}, Math.abs(busy_indicator_hide_delay - busy_duration));
}, Math.abs(window.busy_indicator_hide_delay - busy_duration));
}
}
});
@@ -1015,21 +1016,21 @@ window.addEventListener('message', async (event) => {
let create_missing_ancestors = false;
if(event.data.msg === 'saveToPictures')
target_path = path.join(pictures_path, event.data.filename);
target_path = path.join(window.pictures_path, event.data.filename);
else if(event.data.msg === 'saveToDesktop')
target_path = path.join(desktop_path, event.data.filename);
target_path = path.join(window.desktop_path, event.data.filename);
else if(event.data.msg === 'saveToDocuments')
target_path = path.join(documents_path, event.data.filename);
target_path = path.join(window.documents_path, event.data.filename);
else if(event.data.msg === 'saveToVideos')
target_path = path.join(videos_path, event.data.filename);
target_path = path.join(window.videos_path, event.data.filename);
else if(event.data.msg === 'saveToAudio')
target_path = path.join(audio_path, event.data.filename);
target_path = path.join(window.audio_path, event.data.filename);
else if(event.data.msg === 'saveToAppData'){
target_path = path.join(appdata_path, app_uuid, event.data.filename);
target_path = path.join(window.appdata_path, app_uuid, event.data.filename);
create_missing_ancestors = true;
}
//auth
if(!is_auth() && !(await UIWindowSignup({referrer: app_name})))
if(!window.is_auth() && !(await UIWindowSignup({referrer: app_name})))
return;
let item_with_same_name_already_exists = true;
@@ -1041,7 +1042,7 @@ window.addEventListener('message', async (event) => {
if(event.data.url){
let overwrite = false;
// download progress tracker
let dl_op_id = operation_id++;
let dl_op_id = window.operation_id++;
// upload progress tracker defaults
window.progress_tracker[dl_op_id] = [];
@@ -1056,8 +1057,8 @@ window.addEventListener('message', async (event) => {
url: event.data.url,
name: path.basename(target_path),
dest_path: path.dirname(target_path),
auth_token: auth_token,
api_origin: api_origin,
auth_token: window.auth_token,
api_origin: window.api_origin,
dedupe_name: true,
overwrite: false,
operation_id: dl_op_id,
@@ -1142,7 +1143,7 @@ window.addEventListener('message', async (event) => {
// TODO: Track message traffic between apps
// pass on the message
const target_iframe = iframe_for_app_instance(targetAppInstanceID);
const target_iframe = window.iframe_for_app_instance(targetAppInstanceID);
if (!target_iframe) {
console.error('Failed to send message to non-existent app', event);
return;
@@ -1160,7 +1161,7 @@ window.addEventListener('message', async (event) => {
else if (event.data.msg === 'closeApp') {
const { appInstanceID, targetAppInstanceID } = event.data;
const target_window = window_for_app_instance(targetAppInstanceID);
const target_window = window.window_for_app_instance(targetAppInstanceID);
if (!target_window) {
console.warn(`Failed to close non-existent app ${targetAppInstanceID}`);
return;
@@ -1175,7 +1176,7 @@ window.addEventListener('message', async (event) => {
}
// God-mode apps can close anything
const app_info = await get_apps(app_name);
const app_info = await window.get_apps(app_name);
if (app_info.godmode === 1) {
console.log(`⚠️ Allowing GODMODE app ${appInstanceID} to close app ${targetAppInstanceID}`);
return true;
@@ -1196,6 +1197,6 @@ window.addEventListener('message', async (event) => {
// exit
//--------------------------------------------------------
else if(event.data.msg === 'exit'){
$(window_for_app_instance(event.data.appInstanceID)).close({bypass_iframe_messaging: true});
$(window.window_for_app_instance(event.data.appInstanceID)).close({bypass_iframe_messaging: true});
}
});
+4 -4
View File
@@ -31,7 +31,7 @@ export default {
let h = `<h1>${i18n('account')}</h1>`;
// change password button
if(!user.is_temp){
if(!window.user.is_temp){
h += `<div class="settings-card">`;
h += `<strong>${i18n('password')}</strong>`;
h += `<div style="flex-grow:1;">`;
@@ -44,7 +44,7 @@ export default {
h += `<div class="settings-card">`;
h += `<div>`;
h += `<strong style="display:block;">${i18n('username')}</strong>`;
h += `<span class="username" style="display:block; margin-top:5px;">${html_encode(user.username)}</span>`;
h += `<span class="username" style="display:block; margin-top:5px;">${html_encode(window.user.username)}</span>`;
h += `</div>`;
h += `<div style="flex-grow:1;">`;
h += `<button class="button change-username" style="float:right;">${i18n('change_username')}</button>`;
@@ -52,11 +52,11 @@ export default {
h += `</div>`;
// change email button
if(user.email){
if(window.user.email){
h += `<div class="settings-card">`;
h += `<div>`;
h += `<strong style="display:block;">${i18n('email')}</strong>`;
h += `<span class="user-email" style="display:block; margin-top:5px;">${html_encode(user.email)}</span>`;
h += `<span class="user-email" style="display:block; margin-top:5px;">${html_encode(window.user.email)}</span>`;
h += `</div>`;
h += `<div style="flex-grow:1;">`;
h += `<button class="button change-email" style="float:right;">${i18n('change_email')}</button>`;
+1 -1
View File
@@ -32,7 +32,7 @@ export default {
</div>`;
// list of languages
const available_languages = listSupportedLanguages();
const available_languages = window.listSupportedLanguages();
h += `<div class="language-list">`;
for (let lang of available_languages) {
h += `<div class="language-item ${window.locale === lang.code ? 'active': ''}" data-lang="${lang.code}" data-english-name="${html_encode(lang.english_name)}">${html_encode(lang.name)}</div>`;
+9 -9
View File
@@ -42,16 +42,16 @@ export default {
},
init: ($el_window) => {
$.ajax({
url: api_origin + "/drivers/usage",
url: window.api_origin + "/drivers/usage",
type: 'GET',
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer " + auth_token
"Authorization": "Bearer " + window.auth_token
},
statusCode: {
401: function () {
logout();
window.logout();
},
},
success: function (res) {
@@ -93,16 +93,16 @@ export default {
// df
$.ajax({
url: api_origin + "/df",
url: window.api_origin + "/df",
type: 'GET',
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer " + auth_token
"Authorization": "Bearer " + window.auth_token
},
statusCode: {
401: function () {
logout();
window.logout();
},
},
success: function (res) {
@@ -113,15 +113,15 @@ export default {
let host_usage_percentage = 0;
if ( res.host_used ) {
$('#storage-puter-used').html(byte_format(res.used));
$('#storage-puter-used').html(window.byte_format(res.used));
$('#storage-puter-used-w').show();
general_used = res.host_used;
host_usage_percentage = ((res.host_used - res.used) / res.capacity * 100).toFixed(0);
}
$('#storage-used').html(byte_format(general_used));
$('#storage-capacity').html(byte_format(res.capacity));
$('#storage-used').html(window.byte_format(general_used));
$('#storage-capacity').html(window.byte_format(res.capacity));
$('#storage-used-percent').html(
usage_percentage + '%' +
(host_usage_percentage > 0
+2 -2
View File
@@ -93,11 +93,11 @@ async function UIWindowChangeEmail(options){
$(el_window).find('.new-email').attr('disabled', true);
$.ajax({
url: api_origin + "/change_email/start",
url: window.api_origin + "/change_email/start",
type: 'POST',
async: true,
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
contentType: "application/json",
data: JSON.stringify({
@@ -26,7 +26,7 @@ async function UIWindowFinalizeUserDeletion(options){
let h = '';
// if user is temporary, ask them to type in 'confirm' to delete their account
if(user.is_temp){
if(window.user.is_temp){
h += `<div style="padding: 20px;">`;
h += `<div class="generic-close-window-button disable-user-select"> &times; </div>`;
h += `<img src="${window.icons['danger.svg']}" class="account-deletion-confirmation-icon">`;
@@ -94,7 +94,7 @@ async function UIWindowFinalizeUserDeletion(options){
$(el_window).find('.proceed-with-user-deletion').on('click', function(){
$(el_window).find('.error-message').hide();
// if user is temporary, check if they typed 'confirm'
if(user.is_temp){
if(window.user.is_temp){
if($(el_window).find('.confirm-temporary-user-deletion').val() !== 'confirm'){
$(el_window).find('.error-message').html(i18n('type_confirm_to_delete_account'), false);
$(el_window).find('.error-message').show();
@@ -112,19 +112,19 @@ async function UIWindowFinalizeUserDeletion(options){
// delete user
$.ajax({
url: api_origin + "/delete-own-user",
url: window.api_origin + "/delete-own-user",
type: 'POST',
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer " + auth_token
"Authorization": "Bearer " + window.auth_token
},
data: JSON.stringify({
password: $(el_window).find('.confirm-user-deletion-password').val(),
}),
statusCode: {
401: function () {
logout();
window.logout();
},
400: function(){
$(el_window).find('.error-message').html(i18n('incorrect_password'));
@@ -136,7 +136,7 @@ async function UIWindowFinalizeUserDeletion(options){
// mark user as deleted
window.user.deleted = true;
// log user out
logout();
window.logout();
}
else{
$(el_window).find('.error-message').html(html_encode(data.error));
+1 -2
View File
@@ -45,7 +45,7 @@ async function UIWindowSettings(options){
// side bar
h += `<div class="settings-sidebar disable-user-select">`;
tabs.forEach((tab, i) => {
h += `<div class="settings-sidebar-item disable-user-select ${i === 0 ? 'active' : ''}" data-settings="${tab.id}" style="background-image: url(${icons[tab.icon]});">${i18n(tab.title_i18n_key)}</div>`;
h += `<div class="settings-sidebar-item disable-user-select ${i === 0 ? 'active' : ''}" data-settings="${tab.id}" style="background-image: url(${window.icons[tab.icon]});">${i18n(tab.title_i18n_key)}</div>`;
});
h += `</div>`;
@@ -82,7 +82,6 @@ async function UIWindowSettings(options){
allow_user_select: true,
backdrop: false,
width: 800,
height: 500,
height: 'auto',
dominant: true,
show_in_taskbar: false,
+1 -1
View File
@@ -23,7 +23,7 @@ function UIAlert(options){
// set sensible defaults
if(arguments.length > 0){
// if first argument is a string, then assume it is the message
if(isString(arguments[0])){
if(window.isString(arguments[0])){
options = {};
options.message = arguments[0];
}
+4 -4
View File
@@ -20,7 +20,7 @@
function UIContextMenu(options){
$('.window-active .window-app-iframe').css('pointer-events', 'none');
const menu_id = global_element_id++;
const menu_id = window.global_element_id++;
let h = '';
h += `<div
@@ -114,8 +114,8 @@ function UIContextMenu(options){
// Y position
let y_pos;
// is the menu going to go out of the window from the bottom?
if( (start_y + menu_height) > (window.innerHeight - taskbar_height - 10))
y_pos = window.innerHeight - menu_height - taskbar_height - 10;
if( (start_y + menu_height) > (window.innerHeight - window.taskbar_height - 10))
y_pos = window.innerHeight - menu_height - window.taskbar_height - 10;
else
y_pos = start_y;
@@ -257,7 +257,7 @@ function UIContextMenu(options){
$(options.parent_element).css('overflow', 'scroll');
$(options.parent_element).removeClass('has-open-contextmenu');
if($(options.parent_element).hasClass('taskbar-item')){
make_taskbar_sortable()
window.make_taskbar_sortable()
}
}
})
+123 -127
View File
@@ -41,9 +41,9 @@ async function UIDesktop(options){
let h = '';
// connect socket.
window.socket = io(gui_origin + '/', {
window.socket = io(window.gui_origin + '/', {
query: {
auth_token: auth_token
auth_token: window.auth_token
}
});
@@ -83,7 +83,7 @@ async function UIDesktop(options){
console.error('GUI Socket Error:', error);
});
socket.on('upload.progress', (msg) => {
window.socket.on('upload.progress', (msg) => {
if(window.progress_tracker[msg.operation_id]){
window.progress_tracker[msg.operation_id].cloud_uploaded += msg.loaded_diff
if(window.progress_tracker[msg.operation_id][msg.item_upload_id]){
@@ -92,7 +92,7 @@ async function UIDesktop(options){
}
});
socket.on('download.progress', (msg) => {
window.socket.on('download.progress', (msg) => {
if(window.progress_tracker[msg.operation_id]){
if(window.progress_tracker[msg.operation_id][msg.item_upload_id]){
window.progress_tracker[msg.operation_id][msg.item_upload_id].downloaded = msg.loaded;
@@ -101,30 +101,30 @@ async function UIDesktop(options){
}
});
socket.on('trash.is_empty', async (msg) => {
$(`.item[data-path="${html_encode(trash_path)}" i]`).find('.item-icon > img').attr('src', msg.is_empty ? window.icons['trash.svg'] : window.icons['trash-full.svg']);
$(`.window[data-path="${html_encode(trash_path)}" i]`).find('.window-head-icon').attr('src', msg.is_empty ? window.icons['trash.svg'] : window.icons['trash-full.svg']);
window.socket.on('trash.is_empty', async (msg) => {
$(`.item[data-path="${html_encode(window.trash_path)}" i]`).find('.item-icon > img').attr('src', msg.is_empty ? window.icons['trash.svg'] : window.icons['trash-full.svg']);
$(`.window[data-path="${html_encode(window.trash_path)}" i]`).find('.window-head-icon').attr('src', msg.is_empty ? window.icons['trash.svg'] : window.icons['trash-full.svg']);
// empty trash windows if needed
if(msg.is_empty)
$(`.window[data-path="${html_encode(trash_path)}" i]`).find('.item-container').empty();
$(`.window[data-path="${html_encode(window.trash_path)}" i]`).find('.item-container').empty();
})
socket.on('app.opened', async (app) => {
window.socket.on('app.opened', async (app) => {
// don't update if this is the original client that initiated the action
if(app.original_client_socket_id === window.socket.id)
return;
// add the app to the beginning of the array
launch_apps.recent.unshift(app);
window.launch_apps.recent.unshift(app);
// 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 5
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);
})
socket.on('item.removed', async (item) => {
window.socket.on('item.removed', async (item) => {
// don't update if this is the original client that initiated the action
if(item.original_client_socket_id === window.socket.id)
return;
@@ -143,17 +143,17 @@ async function UIDesktop(options){
});
})
socket.on('item.updated', async (item) => {
window.socket.on('item.updated', async (item) => {
// Don't update if this is the original client that initiated the action
if(item.original_client_socket_id === window.socket.id)
return;
// Update matching items
// set new item name
$(`.item[data-uid='${html_encode(item.uid)}'] .item-name`).html(html_encode(truncate_filename(item.name, TRUNCATE_LENGTH)).replaceAll(' ', '&nbsp;'));
$(`.item[data-uid='${html_encode(item.uid)}'] .item-name`).html(html_encode(window.truncate_filename(item.name, window.TRUNCATE_LENGTH)).replaceAll(' ', '&nbsp;'));
// Set new icon
const new_icon = (item.is_dir ? window.icons['folder.svg'] : (await item_icon(item)).image);
const new_icon = (item.is_dir ? window.icons['folder.svg'] : (await window.item_icon(item)).image);
$(`.item[data-uid='${item.uid}']`).find('.item-icon-thumb').attr('src', new_icon);
$(`.item[data-uid='${item.uid}']`).find('.item-icon-icon').attr('src', new_icon);
@@ -189,21 +189,21 @@ async function UIDesktop(options){
// Update all exact-matching windows
$(`.window-${item.uid}`).each(function(){
update_window_path(this, new_path);
window.update_window_path(this, new_path);
})
// Set new name for matching open windows
$(`.window-${item.uid} .window-head-title`).text(item.name);
// Re-sort all matching item containers
$(`.item[data-uid='${item.uid}']`).parent('.item-container').each(function(){
sort_items(this, $(this).closest('.item-container').attr('data-sort_by'), $(this).closest('.item-container').attr('data-sort_order'));
window.sort_items(this, $(this).closest('.item-container').attr('data-sort_by'), $(this).closest('.item-container').attr('data-sort_order'));
})
})
socket.on('item.moved', async (resp) => {
window.socket.on('item.moved', async (resp) => {
let fsentry = resp;
// Notify all apps that are watching this item
sendItemChangeEventToWatchingApps(fsentry.uid, {
window.sendItemChangeEventToWatchingApps(fsentry.uid, {
event: 'moved',
uid: fsentry.uid,
name: fsentry.name,
@@ -216,9 +216,6 @@ async function UIDesktop(options){
let dest_path = path.dirname(fsentry.path);
let metadata = fsentry.metadata;
// path must use the real name from DB
fsentry.path = fsentry.path;
// update all shortcut_to_path
$(`.item[data-shortcut_to_path="${html_encode(resp.old_path)}" i]`).attr(`data-shortcut_to_path`, html_encode(fsentry.path));
@@ -230,13 +227,13 @@ async function UIDesktop(options){
$(this).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)
});
})
// 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(resp.old_path)}" i]`).close();
// todo this has to be case-insensitive but the `i` selector doesn't work on ^=
$(`.window[data-path^="${html_encode(resp.old_path)}/"]`).close();
@@ -246,11 +243,11 @@ async function UIDesktop(options){
else{
// todo this has to be case-insensitive but the `i` selector doesn't work on ^=
$(`.window[data-path^="${html_encode(resp.old_path)}/"], .window[data-path="${html_encode(resp.old_path)}" i]`).each(function(){
update_window_path(this, $(this).attr('data-path').replace(resp.old_path, fsentry.path));
window.update_window_path(this, $(this).attr('data-path').replace(resp.old_path, fsentry.path));
})
}
if(dest_path === trash_path){
if(dest_path === window.trash_path){
$(`.item[data-uid="${fsentry.uid}"]`).find('.item-is-shared').fadeOut(300);
// if trashing dir...
@@ -277,14 +274,14 @@ async function UIDesktop(options){
immutable: fsentry.immutable,
uid: fsentry.uid,
path: fsentry.path,
icon: await item_icon(fsentry),
name: (dest_path === trash_path) ? metadata.original_name : fsentry.name,
icon: await window.item_icon(fsentry),
name: (dest_path === window.trash_path) ? metadata.original_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,
@@ -305,7 +302,7 @@ async function UIDesktop(options){
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,
@@ -316,34 +313,34 @@ async function UIDesktop(options){
has_website: false,
});
}
sort_items(item_container, $(item_container).attr('data-sort_by'), $(item_container).attr('data-sort_order'));
window.sort_items(item_container, $(item_container).attr('data-sort_by'), $(item_container).attr('data-sort_order'));
});
}
//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'))
})
});
socket.on('user.email_confirmed', (msg) => {
window.socket.on('user.email_confirmed', (msg) => {
// don't update if this is the original client that initiated the action
if(msg.original_client_socket_id === window.socket.id)
return;
refresh_user_data(window.auth_token);
window.refresh_user_data(window.auth_token);
});
socket.on('user.email_changed', (msg) => {
window.socket.on('user.email_changed', (msg) => {
// don't update if this is the original client that initiated the action
if(msg.original_client_socket_id === window.socket.id)
return;
refresh_user_data(window.auth_token);
window.refresh_user_data(window.auth_token);
});
socket.on('item.renamed', async (item) => {
window.socket.on('item.renamed', async (item) => {
// Notify all apps that are watching this item
sendItemChangeEventToWatchingApps(item.uid, {
window.sendItemChangeEventToWatchingApps(item.uid, {
event: 'rename',
uid: item.uid,
// path: item.path,
@@ -357,10 +354,10 @@ async function UIDesktop(options){
// Update matching items
// Set new item name
$(`.item[data-uid='${html_encode(item.uid)}'] .item-name`).html(html_encode(truncate_filename(item.name, TRUNCATE_LENGTH)).replaceAll(' ', '&nbsp;'));
$(`.item[data-uid='${html_encode(item.uid)}'] .item-name`).html(html_encode(window.truncate_filename(item.name, window.TRUNCATE_LENGTH)).replaceAll(' ', '&nbsp;'));
// Set new icon
const new_icon = (item.is_dir ? window.icons['folder.svg'] : (await item_icon(item)).image);
const new_icon = (item.is_dir ? window.icons['folder.svg'] : (await window.item_icon(item)).image);
$(`.item[data-uid='${item.uid}']`).find('.item-icon-icon').attr('src', new_icon);
// Set new data-name
@@ -395,24 +392,24 @@ async function UIDesktop(options){
// Update all exact-matching windows
$(`.window-${item.uid}`).each(function(){
update_window_path(this, new_path);
window.update_window_path(this, new_path);
})
// Set new name for matching open windows
$(`.window-${item.uid} .window-head-title`).text(item.name);
// Re-sort all matching item containers
$(`.item[data-uid='${item.uid}']`).parent('.item-container').each(function(){
sort_items(this, $(this).closest('.item-container').attr('data-sort_by'), $(this).closest('.item-container').attr('data-sort_order'));
window.sort_items(this, $(this).closest('.item-container').attr('data-sort_by'), $(this).closest('.item-container').attr('data-sort_order'));
})
});
socket.on('item.added', async (item) => {
window.socket.on('item.added', async (item) => {
// if item is empty, don't proceed
if(_.isEmpty(item))
return;
// Notify all apps that are watching this item
sendItemChangeEventToWatchingApps(item.uid, {
window.sendItemChangeEventToWatchingApps(item.uid, {
event: 'write',
uid: item.uid,
// path: item.path,
@@ -437,12 +434,12 @@ async function UIDesktop(options){
'data-type': item.type,
})
// set new icon
const new_icon = (item.is_dir ? window.icons['folder.svg'] : (await item_icon(item)).image);
const new_icon = (item.is_dir ? window.icons['folder.svg'] : (await window.item_icon(item)).image);
$(`.item[data-uid="${item.overwritten_uid}"]`).find('.item-icon > img').attr('src', new_icon);
//sort each window
$(`.item-container[data-path='${html_encode(item.dirpath)}' 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'))
})
}
else{
@@ -452,7 +449,7 @@ async function UIDesktop(options){
immutable: item.immutable,
associated_app_name: item.associated_app?.name,
path: item.path,
icon: await item_icon(item),
icon: await window.item_icon(item),
name: item.name,
size: item.size,
type: item.type,
@@ -460,14 +457,13 @@ async function UIDesktop(options){
is_dir: item.is_dir,
is_shared: item.is_shared,
is_shortcut: item.is_shortcut,
associated_app_name: item.associated_app?.name,
shortcut_to: item.shortcut_to,
shortcut_to_path: item.shortcut_to_path,
});
//sort each window
$(`.item-container[data-path='${html_encode(item.dirpath)}' 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'))
})
}
});
@@ -488,12 +484,12 @@ async function UIDesktop(options){
data-uid="${options.desktop_fsentry.uid}"
data-sort_by="${!options.desktop_fsentry.sort_by ? 'name' : options.desktop_fsentry.sort_by}"
data-sort_order="${!options.desktop_fsentry.sort_order ? 'asc' : options.desktop_fsentry.sort_order}"
data-path="${html_encode(desktop_path)}"
data-path="${html_encode(window.desktop_path)}"
>`;
h += `</div>`;
// Get window sidebar width
getItem({
window.getItem({
key: "window_sidebar_width",
success: async function(res){
let value = parseInt(res.value);
@@ -505,7 +501,7 @@ async function UIDesktop(options){
})
// Remove `?ref=...` from navbar URL
if(url_query_params.has('ref')){
if(window.url_query_params.has('ref')){
window.history.pushState(null, document.title, '/');
}
@@ -522,7 +518,7 @@ async function UIDesktop(options){
user_preferences[default_app_keys[key].substring(17)] = await puter.kv.get(default_app_keys[key]);
}
update_user_preferences(user_preferences);
window.update_user_preferences(user_preferences);
});
// Append to <body>
@@ -557,7 +553,7 @@ async function UIDesktop(options){
return false;
// recursively create directories and upload files
if(e.dataTransfer?.items?.length>0){
upload_items(e.dataTransfer.items, desktop_path);
window.upload_items(e.dataTransfer.items, window.desktop_path);
}
e.stopPropagation();
@@ -574,7 +570,7 @@ async function UIDesktop(options){
tolerance: "intersect",
drop: function( event, ui ) {
// Check if item was actually dropped on desktop and not a window
if(mouseover_window !== undefined)
if(window.mouseover_window !== undefined)
return;
// Can't drop anything but UIItems on desktop
@@ -582,7 +578,7 @@ async function UIDesktop(options){
return;
// Don't move an item to its current directory
if( path.dirname($(ui.draggable).attr('data-path')) === desktop_path && !event.ctrlKey)
if( path.dirname($(ui.draggable).attr('data-path')) === window.desktop_path && !event.ctrlKey)
return;
// If ctrl is pressed and source is Trashed, cancel whole operation
@@ -610,11 +606,11 @@ async function UIDesktop(options){
if(path.dirname($(ui.draggable).attr('data-path')) === window.trash_path)
return;
copy_items(items_to_move, desktop_path)
window.copy_items(items_to_move, window.desktop_path)
}
// otherwise, move items
else{
move_items(items_to_move, desktop_path);
window.move_items(items_to_move, window.desktop_path);
}
}
});
@@ -646,16 +642,16 @@ async function UIDesktop(options){
items: [
{
html: i18n('auto_arrange'),
icon: is_auto_arrange_enabled ? '✓' : '',
icon: window.is_auto_arrange_enabled ? '✓' : '',
onClick: async function(){
is_auto_arrange_enabled = !is_auto_arrange_enabled;
store_auto_arrange_preference(is_auto_arrange_enabled);
if(is_auto_arrange_enabled){
sort_items(el_desktop, $(el_desktop).attr('data-sort_by'), $(el_desktop).attr('data-sort_order'));
set_sort_by(options.desktop_fsentry.uid, $(el_desktop).attr('data-sort_by'), $(el_desktop).attr('data-sort_order'))
clear_desktop_item_positions(el_desktop);
window.is_auto_arrange_enabled = !window.is_auto_arrange_enabled;
window.store_auto_arrange_preference(window.is_auto_arrange_enabled);
if(window.is_auto_arrange_enabled){
window.sort_items(el_desktop, $(el_desktop).attr('data-sort_by'), $(el_desktop).attr('data-sort_order'));
window.set_sort_by(options.desktop_fsentry.uid, $(el_desktop).attr('data-sort_by'), $(el_desktop).attr('data-sort_order'))
window.clear_desktop_item_positions(el_desktop);
}else{
set_desktop_item_positions(el_desktop)
window.set_desktop_item_positions(el_desktop)
}
}
},
@@ -665,38 +661,38 @@ async function UIDesktop(options){
'-',
{
html: i18n('name'),
disabled: !is_auto_arrange_enabled,
disabled: !window.is_auto_arrange_enabled,
icon: $(el_desktop).attr('data-sort_by') === 'name' ? '✓' : '',
onClick: async function(){
sort_items(el_desktop, 'name', $(el_desktop).attr('data-sort_order'));
set_sort_by(options.desktop_fsentry.uid, 'name', $(el_desktop).attr('data-sort_order'))
window.sort_items(el_desktop, 'name', $(el_desktop).attr('data-sort_order'));
window.set_sort_by(options.desktop_fsentry.uid, 'name', $(el_desktop).attr('data-sort_order'))
}
},
{
html: i18n('date_modified'),
disabled: !is_auto_arrange_enabled,
disabled: !window.is_auto_arrange_enabled,
icon: $(el_desktop).attr('data-sort_by') === 'modified' ? '✓' : '',
onClick: async function(){
sort_items(el_desktop, 'modified', $(el_desktop).attr('data-sort_order'));
set_sort_by(options.desktop_fsentry.uid, 'modified', $(el_desktop).attr('data-sort_order'))
window.sort_items(el_desktop, 'modified', $(el_desktop).attr('data-sort_order'));
window.set_sort_by(options.desktop_fsentry.uid, 'modified', $(el_desktop).attr('data-sort_order'))
}
},
{
html: i18n('type'),
disabled: !is_auto_arrange_enabled,
disabled: !window.is_auto_arrange_enabled,
icon: $(el_desktop).attr('data-sort_by') === 'type' ? '✓' : '',
onClick: async function(){
sort_items(el_desktop, 'type', $(el_desktop).attr('data-sort_order'));
set_sort_by(options.desktop_fsentry.uid, 'type', $(el_desktop).attr('data-sort_order'))
window.sort_items(el_desktop, 'type', $(el_desktop).attr('data-sort_order'));
window.set_sort_by(options.desktop_fsentry.uid, 'type', $(el_desktop).attr('data-sort_order'))
}
},
{
html: i18n('size'),
disabled: !is_auto_arrange_enabled,
disabled: !window.is_auto_arrange_enabled,
icon: $(el_desktop).attr('data-sort_by') === 'size' ? '✓' : '',
onClick: async function(){
sort_items(el_desktop, 'size', $(el_desktop).attr('data-sort_order'));
set_sort_by(options.desktop_fsentry.uid, 'size', $(el_desktop).attr('data-sort_order'))
window.sort_items(el_desktop, 'size', $(el_desktop).attr('data-sort_order'));
window.set_sort_by(options.desktop_fsentry.uid, 'size', $(el_desktop).attr('data-sort_order'))
}
},
// -------------------------------------------
@@ -705,22 +701,22 @@ async function UIDesktop(options){
'-',
{
html: i18n('ascending'),
disabled: !is_auto_arrange_enabled,
disabled: !window.is_auto_arrange_enabled,
icon: $(el_desktop).attr('data-sort_order') === 'asc' ? '✓' : '',
onClick: async function(){
const sort_by = $(el_desktop).attr('data-sort_by')
sort_items(el_desktop, sort_by, 'asc');
set_sort_by(options.desktop_fsentry.uid, sort_by, 'asc')
window.sort_items(el_desktop, sort_by, 'asc');
window.set_sort_by(options.desktop_fsentry.uid, sort_by, 'asc')
}
},
{
html: i18n('descending'),
disabled: !is_auto_arrange_enabled,
disabled: !window.is_auto_arrange_enabled,
icon: $(el_desktop).attr('data-sort_order') === 'desc' ? '✓' : '',
onClick: async function(){
const sort_by = $(el_desktop).attr('data-sort_by')
sort_items(el_desktop, sort_by, 'desc');
set_sort_by(options.desktop_fsentry.uid, sort_by, 'desc')
window.sort_items(el_desktop, sort_by, 'desc');
window.set_sort_by(options.desktop_fsentry.uid, sort_by, 'desc')
}
},
]
@@ -754,7 +750,7 @@ async function UIDesktop(options){
// -------------------------------------------
// New File
// -------------------------------------------
new_context_menu_item(desktop_path, el_desktop),
new_context_menu_item(window.desktop_path, el_desktop),
// -------------------------------------------
// -
// -------------------------------------------
@@ -764,12 +760,12 @@ async function UIDesktop(options){
// -------------------------------------------
{
html: i18n('paste'),
disabled: clipboard.length > 0 ? false : true,
disabled: window.clipboard.length > 0 ? false : true,
onClick: function(){
if(clipboard_op === 'copy')
copy_clipboard_items(desktop_path, el_desktop);
else if(clipboard_op === 'move')
move_clipboard_items(el_desktop)
if(window.clipboard_op === 'copy')
window.copy_clipboard_items(window.desktop_path, el_desktop);
else if(window.clipboard_op === 'move')
window.move_clipboard_items(el_desktop)
}
},
// -------------------------------------------
@@ -777,9 +773,9 @@ async function UIDesktop(options){
// -------------------------------------------
{
html: i18n('undo'),
disabled: actions_history.length > 0 ? false : true,
disabled: window.actions_history.length > 0 ? false : true,
onClick: function(){
undo_last_action();
window.undo_last_action();
}
},
// -------------------------------------------
@@ -788,7 +784,7 @@ async function UIDesktop(options){
{
html: i18n('upload_here'),
onClick: function(){
init_upload_using_dialog(el_desktop);
window.init_upload_using_dialog(el_desktop);
}
},
// -------------------------------------------
@@ -815,7 +811,7 @@ async function UIDesktop(options){
// we don't need to get the desktop items if we're in embedded or fullpage mode
// because the items aren't visible anyway and we don't need to waste bandwidth/server resources
//-------------------------------------------
if(!is_embedded && !window.is_fullpage_mode){
if(!window.is_embedded && !window.is_fullpage_mode){
refresh_item_container(el_desktop, {fadeInItems: true})
}
@@ -908,7 +904,7 @@ async function UIDesktop(options){
}
// refer
if(user.referral_code){
if(window.user.referral_code){
ht += `<div class="toolbar-btn refer-btn" title="Refer" style="background-image:url(${window.icons['gift.svg']});"></div>`;
}
@@ -919,7 +915,7 @@ async function UIDesktop(options){
}
// qr code button -- only show if not embedded
if(!is_embedded)
if(!window.is_embedded)
ht += `<div class="toolbar-btn qr-btn" title="QR code" style="background-image:url(${window.icons['qr.svg']})"></div>`;
// user options menu
@@ -937,17 +933,17 @@ async function UIDesktop(options){
// ---------------------------------------------
// Run apps from insta-login URL
// ---------------------------------------------
if(url_query_params.has('app')){
let url_app_name = url_query_params.get('app');
if(window.url_query_params.has('app')){
let url_app_name = window.url_query_params.get('app');
if(url_app_name === 'explorer'){
let predefined_path = home_path;
if(url_query_params.has('path'))
predefined_path =url_query_params.get('path')
let predefined_path = window.home_path;
if(window.url_query_params.has('path'))
predefined_path =window.url_query_params.get('path')
// launch explorer
UIWindow({
path: predefined_path,
title: path.basename(predefined_path),
icon: await item_icon({is_dir: true, path: predefined_path}),
icon: await window.item_icon({is_dir: true, path: predefined_path}),
// todo
// uid: $(el_item).attr('data-uid'),
is_dir: true,
@@ -963,11 +959,11 @@ async function UIDesktop(options){
else if(window.app_launched_from_url){
let qparams = new URLSearchParams(window.location.search);
if(!qparams.has('c')){
launch_app({
name: app_launched_from_url,
window.launch_app({
name: window.app_launched_from_url,
readURL: qparams.get('readURL'),
maximized: qparams.get('maximized'),
params: app_query_params ?? [],
params: window.app_query_params ?? [],
is_fullpage: window.is_fullpage_mode,
window_options: {
stay_on_top: false,
@@ -1014,21 +1010,21 @@ async function UIDesktop(options){
var x1=month + "/" + dt + "/" + x.getFullYear();
x1 = x1 + " - " + hours + ":" + minutes + ":" + seconds + " " + ampm;
$('#clock').html(x1);
$('#clock').css('line-height', taskbar_height + 'px');
$('#clock').css('line-height', window.taskbar_height + 'px');
}
setInterval(display_ct, 1000);
// show referral notice window
if(window.show_referral_notice && !user.email_confirmed){
getItem({
if(window.show_referral_notice && !window.user.email_confirmed){
window.getItem({
key: "shown_referral_notice",
success: async function(res){
if(!res){
setTimeout(() => {
UIWindowClaimReferral();
}, 1000);
setItem({
window.setItem({
key: "shown_referral_notice",
value: true,
})
@@ -1122,13 +1118,13 @@ $(document).on('click', '.user-options-menu-btn', async function(e){
items.push(
{
html: l_user.username,
icon: l_user.username === user.username ? '✓' : '',
icon: l_user.username === window.user.username ? '✓' : '',
onClick: async function(val){
// don't reload everything if clicked on already-logged-in user
if(l_user.username === user.username)
if(l_user.username === window.user.username)
return;
// update auth data
update_auth_data(l_user.auth_token, l_user);
window.update_auth_data(l_user.auth_token, l_user);
// refresh
location.reload();
}
@@ -1167,7 +1163,7 @@ $(document).on('click', '.user-options-menu-btn', async function(e){
// -------------------------------------------
// Load available languages
// -------------------------------------------
const supportedLanguagesItems = listSupportedLanguages().map(lang => {
const supportedLanguagesItems = window.listSupportedLanguages().map(lang => {
return {
html: lang.name,
icon: window.locale === lang.code ? '✓' : '',
@@ -1246,11 +1242,11 @@ $(document).on('click', '.user-options-menu-btn', async function(e){
]
})
if(alert_resp === 'close_and_log_out')
logout();
window.logout();
}
// no open windows
else
logout();
window.logout();
}
},
]
@@ -1258,7 +1254,7 @@ $(document).on('click', '.user-options-menu-btn', async function(e){
})
$(document).on('click', '.fullscreen-btn', async function (e) {
if(!is_fullscreen()) {
if(!window.is_fullscreen()) {
var elem = document.documentElement;
if (elem.requestFullscreen) {
elem.requestFullscreen();
@@ -1305,7 +1301,7 @@ $(document).on('click', '.refer-btn', async function(e){
})
$(document).on('click', '.start-app', async function(e){
launch_app({
window.launch_app({
name: $(this).attr('data-app-name')
})
// close popovers
@@ -1367,7 +1363,7 @@ $(document).on('focus', '.launch-search', function(e){
})
$(document).on('change keyup keypress keydown paste', '.launch-search', function(e){
// search launch_apps.recommended for query
// search window.launch_apps.recommended for query
const query = $(this).val().toLowerCase();
if(query === ''){
$('.launch-search-clear').hide();
@@ -1378,7 +1374,7 @@ $(document).on('change keyup keypress keydown paste', '.launch-search', function
$('.launch-apps-recent').hide();
$('.start-section-heading').hide();
$('.launch-search-clear').show();
launch_apps.recommended.forEach((app)=>{
window.launch_apps.recommended.forEach((app)=>{
if(app.title.toLowerCase().includes(query.toLowerCase())){
$(`.start-app-card[data-name="${app.name}"]`).show();
}else{
@@ -1457,7 +1453,7 @@ window.update_taskbar = function(){
// update taskbar in the server-side
$.ajax({
url: api_origin + "/update-taskbar-items",
url: window.api_origin + "/update-taskbar-items",
type: 'POST',
data: JSON.stringify({
items: items,
@@ -1465,7 +1461,7 @@ window.update_taskbar = function(){
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
})
}
@@ -1485,7 +1481,7 @@ window.enter_fullpage_mode = (el_window)=>{
$(el_window).css({
width: '100%',
height: '100%',
top: toolbar_height + 'px',
top: window.toolbar_height + 'px',
left: 0,
'border-radius': 0,
});
@@ -1499,7 +1495,7 @@ window.exit_fullpage_mode = (el_window)=>{
refresh_item_container($('.desktop.item-container'), {fadeInItems: true});
$(el_window).removeAttr('data-is_fullpage');
if(el_window){
reset_window_size_and_position(el_window)
window.reset_window_size_and_position(el_window)
$(el_window).find('.window-head').show();
}
@@ -1510,14 +1506,14 @@ window.exit_fullpage_mode = (el_window)=>{
$('.show-desktop-btn').hide();
// refresh desktop background
refresh_desktop_background();
window.refresh_desktop_background();
}
window.reset_window_size_and_position = (el_window)=>{
$(el_window).css({
width: 680,
height: 380,
'border-radius': window_border_radius,
'border-radius': window.window_border_radius,
top: 'calc(50% - 190px)',
left: 'calc(50% - 340px)',
});
+78 -78
View File
@@ -39,7 +39,7 @@ function UIItem(options){
return;
}
const item_id = global_element_id++;
const item_id = window.global_element_id++;
let last_mousedown_ts = 999999999999999;
let rename_cancelled = false;
@@ -59,7 +59,7 @@ function UIItem(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')
@@ -101,7 +101,7 @@ function UIItem(options){
h += `</div>`;
// size
h += `<div class="item-attr item-attr--size">`;
h += `<span>${options.size ? byte_format(options.size) : '-'}</span>`;
h += `<span>${options.size ? window.byte_format(options.size) : '-'}</span>`;
h += `</div>`;
// type
h += `<div class="item-attr item-attr--type">`;
@@ -158,7 +158,7 @@ function UIItem(options){
h += `</div>`;
// name
h += `<span class="item-name" data-item-id="${item_id}" title="${html_encode(options.name)}">${options.is_trash ? i18n('trash') : html_encode(truncate_filename(options.name, TRUNCATE_LENGTH)).replaceAll(' ', '&nbsp;')}</span>`
h += `<span class="item-name" data-item-id="${item_id}" title="${html_encode(options.name)}">${options.is_trash ? i18n('trash') : html_encode(window.truncate_filename(options.name, window.TRUNCATE_LENGTH)).replaceAll(' ', '&nbsp;')}</span>`
// name editor
h += `<textarea class="item-name-editor hide-scrollbar" spellcheck="false" autocomplete="off" autocorrect="off" autocapitalize="off" data-gramm_editor="false">${html_encode(options.name)}</textarea>`
h += `</div>`;
@@ -168,14 +168,14 @@ function UIItem(options){
// updte item_container
const item_container = $(options.appendTo).closest('.item-container');
show_or_hide_empty_folder_message(item_container);
window.show_or_hide_empty_folder_message(item_container);
// get all the elements needed
const el_item = document.getElementById(`item-${item_id}`);
const el_item_name = document.querySelector(`#item-${item_id} > .item-name`);
const el_item_icon = document.querySelector(`#item-${item_id} .item-icon`);
const el_item_name_editor = document.querySelector(`#item-${item_id} > .item-name-editor`);
const is_trashed = $(el_item).attr('data-path').startsWith(trash_path + '/');
const is_trashed = $(el_item).attr('data-path').startsWith(window.trash_path + '/');
// update parent window's explorer item count if applicable
if(options.appendTo !== undefined){
@@ -183,11 +183,11 @@ function UIItem(options){
if(!$(el_window).hasClass('.window'))
el_window = $(el_window).closest('.window');
update_explorer_footer_item_count(el_window);
window.update_explorer_footer_item_count(el_window);
}
// manual positioning
if( !is_auto_arrange_enabled &&
if( !window.is_auto_arrange_enabled &&
options.position &&
// item is on the desktop (must be desktop itself and not a window, hence the '.desktop' class check)
$(el_item).closest('.item-container.desktop').attr('data-path') === window.desktop_path
@@ -214,7 +214,7 @@ function UIItem(options){
$(el_item).removeClass('item-selected');
// if files were dropped...
if(e.dataTransfer?.items?.length > 0){
upload_items( e.dataTransfer.items, $(el_item).attr('data-path'))
window.upload_items( e.dataTransfer.items, $(el_item).attr('data-path'))
}
e.stopPropagation();
@@ -333,13 +333,13 @@ function UIItem(options){
}
// send drag event to iframe if mouse is inside iframe
if(mouseover_window){
const $app_iframe = $(mouseover_window).find('.window-app-iframe');
if(!$(mouseover_window).hasClass('window-disabled') && $app_iframe.length > 0){
if(window.mouseover_window){
const $app_iframe = $(window.mouseover_window).find('.window-app-iframe');
if(!$(window.mouseover_window).hasClass('window-disabled') && $app_iframe.length > 0){
var rect = $app_iframe.get(0).getBoundingClientRect();
// if mouse is inside iframe, send drag message to iframe
if(mouseX > rect.left && mouseX < rect.right && mouseY > rect.top && mouseY < rect.bottom){
$app_iframe.get(0).contentWindow.postMessage({msg: "drag", x: (mouseX - rect.left), y: (mouseY - rect.top)}, '*');
if(window.mouseX > rect.left && window.mouseX < rect.right && window.mouseY > rect.top && window.mouseY < rect.bottom){
$app_iframe.get(0).contentWindow.postMessage({msg: "drag", x: (window.mouseX - rect.left), y: (window.mouseY - rect.top)}, '*');
}
}
}
@@ -347,16 +347,16 @@ function UIItem(options){
stop: function(event, ui){
// Allow rearranging only if item is on desktop, not trash container, auto arrange is disabled and item is not dropped into another item
if($(el_item).closest('.item-container').attr('data-path') === window.desktop_path &&
!is_auto_arrange_enabled && $(el_item).attr('data-path') !== trash_path && !ui.helper.data('dropped') &&
!window.is_auto_arrange_enabled && $(el_item).attr('data-path') !== window.trash_path && !ui.helper.data('dropped') &&
// Item must be dropped on the Desktop and not on the taskbar
mouseover_window === undefined && ui.position.top <= window.desktop_height - window.taskbar_height - 15){
window.mouseover_window === undefined && ui.position.top <= window.desktop_height - window.taskbar_height - 15){
el_item.style.position = 'absolute';
el_item.style.left = ui.position.left + 'px';
el_item.style.top = ui.position.top + 'px';
$('.ui-draggable-dragging').remove();
desktop_item_positions[$(el_item).attr('data-uid')] = ui.position;
save_desktop_item_positions()
window.desktop_item_positions[$(el_item).attr('data-uid')] = ui.position;
window.save_desktop_item_positions()
}
$('.item-selected-clone').remove();
@@ -380,7 +380,7 @@ function UIItem(options){
tolerance: 'pointer',
drop: async function( event, ui ) {
// Check if hovering over an item that is VISIBILE
if($(event.target).closest('.window').attr('data-id') !== $(mouseover_window).attr('data-id'))
if($(event.target).closest('.window').attr('data-id') !== $(window.mouseover_window).attr('data-id'))
return;
// If ctrl is pressed and source is Trashed, cancel whole operation
@@ -424,7 +424,7 @@ function UIItem(options){
// open each item
for (let i = 0; i < items_to_open.length; i++) {
const item = items_to_open[i];
launch_app({
window.launch_app({
name: options.associated_app_name,
file_path: item.path,
// app_obj: open_item_meta.suggested_apps[0],
@@ -445,14 +445,14 @@ function UIItem(options){
// If ctrl key is down, copy items. Except if target or source is Trash
if(event.ctrlKey){
if(options.is_dir && $(el_item).attr('data-path') !== window.trash_path )
copy_items(items_to_move, $(el_item).attr('data-path'))
window.copy_items(items_to_move, $(el_item).attr('data-path'))
else if(!options.is_dir)
copy_items(items_to_move, path.dirname($(el_item).attr('data-path')));
window.copy_items(items_to_move, path.dirname($(el_item).attr('data-path')));
}
// If alt key is down, create shortcut items
else if(event.altKey && window.feature_flags.create_shortcut){
items_to_move.forEach((item_to_move) => {
create_shortcut(
window.create_shortcut(
path.basename($(item_to_move).attr('data-path')),
$(item_to_move).attr('data-is_dir') === '1',
options.is_dir ? $(el_item).attr('data-path') : path.dirname($(el_item).attr('data-path')),
@@ -465,10 +465,10 @@ function UIItem(options){
// Otherwise, move items
else if(options.is_dir){
if($(el_item).closest('.item-container').attr('data-path') === window.desktop_path){
delete desktop_item_positions[$(el_item).attr('data-uid')];
save_desktop_item_positions()
delete window.desktop_item_positions[$(el_item).attr('data-uid')];
window.save_desktop_item_positions()
}
move_items(items_to_move, $(el_item).attr('data-shortcut_to_path') !== '' ? $(el_item).attr('data-shortcut_to_path') : $(el_item).attr('data-path'));
window.move_items(items_to_move, $(el_item).attr('data-shortcut_to_path') !== '' ? $(el_item).attr('data-shortcut_to_path') : $(el_item).attr('data-path'));
}
}
@@ -480,7 +480,7 @@ function UIItem(options){
over: function(event, ui){
// Check hovering over an item that is VISIBILE
const $event_parent_win = $(event.target).closest('.window')
if( $event_parent_win.length > 0 && $event_parent_win.attr('data-id') !== $(mouseover_window).attr('data-id'))
if( $event_parent_win.length > 0 && $event_parent_win.attr('data-id') !== $(window.mouseover_window).attr('data-id'))
return;
// Don't do anything if the dragged item is NOT a UIItem
if(!$(ui.draggable).hasClass('item'))
@@ -522,7 +522,7 @@ function UIItem(options){
if($(e.target).hasClass('item-name-editor'))
return false;
open_item({
window.open_item({
item: el_item,
maximized: true,
});
@@ -537,7 +537,7 @@ function UIItem(options){
if($(e.target).hasClass('item-name-editor'))
return false;
open_item({
window.open_item({
item: el_item,
new_window: e.metaKey || e.ctrlKey,
});
@@ -576,7 +576,7 @@ function UIItem(options){
else{
$(this).addClass('item-selected')
}
update_explorer_footer_selected_items_count($el_parent_window)
window.update_explorer_footer_selected_items_count($el_parent_window)
});
// --------------------------------------------------------
// Click
@@ -593,7 +593,7 @@ function UIItem(options){
// CTRL/Command key is pressed or clicking an item that is already selected
if(!e.ctrlKey && !e.metaKey){
$(this).closest('.item-container').find('.item-selected').not(this).removeClass('item-selected');
update_explorer_footer_selected_items_count($el_parent_window)
window.update_explorer_footer_selected_items_count($el_parent_window)
}
//----------------------------------------------------------------
// On an OpenFileDialog?
@@ -648,7 +648,7 @@ function UIItem(options){
UIAlert(`The name ".." is not allowed, because it is a reserved name. Please choose another name.`)
}
$(el_item_name).html(truncate_filename(options.name, TRUNCATE_LENGTH).replaceAll(' ', '&nbsp;'));
$(el_item_name).html(window.truncate_filename(options.name, window.TRUNCATE_LENGTH).replaceAll(' ', '&nbsp;'));
$(el_item_name).show();
$(el_item_name_editor).val($(el_item).attr('data-name'));
$(el_item_name_editor).hide();
@@ -658,7 +658,7 @@ function UIItem(options){
$(el_item_name_editor).removeClass('item-name-editor-active');
// Perform rename request
rename_file(options, new_name, old_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url);
window.rename_file(options, new_name, old_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url);
}
// --------------------------------------------------------
@@ -675,8 +675,8 @@ function UIItem(options){
e.preventDefault();
$(el_item_name_editor).blur();
$(el_item).addClass('item-selected');
last_enter_pressed_to_rename_ts = Date.now();
update_explorer_footer_selected_items_count($(el_item).closest('.item-container'));
window.last_enter_pressed_to_rename_ts = Date.now();
window.update_explorer_footer_selected_items_count($(el_item).closest('.item-container'));
return false;
}
})
@@ -715,7 +715,7 @@ function UIItem(options){
setTimeout(() => {
if(!skip_a_rename_click && (Date.now() - last_mousedown_ts) > 400){
if (!e.ctrlKey && !e.metaKey)
activate_item_name_editor(el_item)
window.activate_item_name_editor(el_item)
last_mousedown_ts = 0
}else{
last_mousedown_ts = Date.now() + 500;
@@ -760,7 +760,7 @@ function UIItem(options){
// Multiple items selected
// -------------------------------------------------------
if($selected_items.length > 1){
const are_trashed = $selected_items.attr('data-path').startsWith(trash_path + '/');
const are_trashed = $selected_items.attr('data-path').startsWith(window.trash_path + '/');
menu_items = []
// -------------------------------------------
// Restore
@@ -772,7 +772,7 @@ function UIItem(options){
$selected_items.each(function() {
const ell = this;
let metadata = $(ell).attr('data-metadata') === '' ? {} : JSON.parse($(ell).attr('data-metadata'))
move_items([ell], path.dirname(metadata.original_path));
window.move_items([ell], path.dirname(metadata.original_path));
})
}
});
@@ -793,7 +793,7 @@ function UIItem(options){
items.push($selected_items[index]);
}
zipItems(items, path.dirname($(el_item).attr('data-path')), true);
window.zipItems(items, path.dirname($(el_item).attr('data-path')), true);
}
});
// -------------------------------------------
@@ -807,7 +807,7 @@ function UIItem(options){
items.push($selected_items[index]);
}
zipItems(items, path.dirname($(el_item).attr('data-path')), false);
window.zipItems(items, path.dirname($(el_item).attr('data-path')), false);
}
});
// -------------------------------------------
@@ -872,9 +872,9 @@ function UIItem(options){
if((alert_resp) === 'Delete'){
for (let index = 0; index < $selected_items.length; index++) {
const element = $selected_items[index];
await delete_item(element);
await window.delete_item(element);
}
const trash = await puter.fs.stat(trash_path);
const trash = await puter.fs.stat(window.trash_path);
// update other clients
if(window.socket){
@@ -882,8 +882,8 @@ function UIItem(options){
}
if(trash.is_empty){
$(`.item[data-path="${html_encode(trash_path)}" i], .item[data-shortcut_to_path="${trash_path}" i]`).find('.item-icon > img').attr('src', window.icons['trash.svg']);
$(`.window[data-path="${html_encode(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="${window.trash_path}" i]`).find('.item-icon > img').attr('src', window.icons['trash.svg']);
$(`.window[data-path="${html_encode(window.trash_path)}"]`).find('.window-head-icon').attr('src', window.icons['trash.svg']);
}
}
}
@@ -903,7 +903,7 @@ function UIItem(options){
base_dir = window.desktop_path;
}
// create shortcut
create_shortcut(
window.create_shortcut(
path.basename($(this).attr('data-path')),
$(this).attr('data-is_dir') === '1',
base_dir,
@@ -922,7 +922,7 @@ function UIItem(options){
menu_items.push({
html: i18n('delete'),
onClick: async function(){
move_items($selected_items, trash_path);
window.move_items($selected_items, window.trash_path);
}
});
}
@@ -933,7 +933,7 @@ function UIItem(options){
// One item selected
// -------------------------------------------------------
else{
const is_trash = $(el_item).attr('data-path') === trash_path || $(el_item).attr('data-shortcut_to_path') === trash_path;
const is_trash = $(el_item).attr('data-path') === window.trash_path || $(el_item).attr('data-shortcut_to_path') === window.trash_path;
menu_items = [];
// -------------------------------------------
// Open
@@ -942,7 +942,7 @@ function UIItem(options){
menu_items.push({
html: i18n('open'),
onClick: function(){
open_item({item: el_item});
window.open_item({item: el_item});
}
});
@@ -959,7 +959,7 @@ function UIItem(options){
let items = [];
if(!options.suggested_apps || options.suggested_apps.length === 0){
// try to find suitable apps
const suitable_apps = await suggest_apps_for_fsentry({
const suitable_apps = await window.suggest_apps_for_fsentry({
uid: options.uid,
path: options.path,
});
@@ -981,12 +981,12 @@ function UIItem(options){
onClick: async function(){
var extension = path.extname($(el_item).attr('data-path')).toLowerCase();
if(
user_preferences[`default_apps${extension}`] !== suggested_app.name
window.user_preferences[`default_apps${extension}`] !== suggested_app.name
&&
(
(!user_preferences[`default_apps${extension}`] && index > 0)
(!window.user_preferences[`default_apps${extension}`] && index > 0)
||
(user_preferences[`default_apps${extension}`])
(window.user_preferences[`default_apps${extension}`])
)
){
const alert_resp = await UIAlert({
@@ -1004,11 +1004,11 @@ function UIItem(options){
]
})
if((alert_resp) === 'yes'){
user_preferences['default_apps' + extension] = suggested_app.name;
window.mutate_user_preferences(user_preferences);
window.user_preferences['default_apps' + extension] = suggested_app.name;
window.mutate_user_preferences(window.user_preferences);
}
}
launch_app({
window.launch_app({
name: suggested_app.name,
file_path: $(el_item).attr('data-path'),
window_title: $(el_item).attr('data-name'),
@@ -1044,7 +1044,7 @@ function UIItem(options){
html: i18n('open_in_new_window'),
onClick: function(){
if(options.is_dir){
open_item({item: el_item, new_window: true})
window.open_item({item: el_item, new_window: true})
}
}
});
@@ -1090,7 +1090,7 @@ function UIItem(options){
html: i18n('deploy_as_app'),
disabled: !options.is_dir,
onClick: async function () {
launch_app({
window.launch_app({
name: 'dev-center',
file_path: $(el_item).attr('data-path'),
file_uid: $(el_item).attr('data-uid'),
@@ -1111,7 +1111,7 @@ function UIItem(options){
menu_items.push({
html: i18n('empty_trash'),
onClick: async function(){
empty_trash();
window.empty_trash();
}
});
}
@@ -1124,9 +1124,9 @@ function UIItem(options){
disabled: options.is_dir && !window.feature_flags.download_directory,
onClick: async function(){
if(options.is_dir)
zipItems(el_item, path.dirname($(el_item).attr('data-path')), true);
window.zipItems(el_item, path.dirname($(el_item).attr('data-path')), true);
else
trigger_download([options.path]);
window.trigger_download([options.path]);
}
});
}
@@ -1137,7 +1137,7 @@ function UIItem(options){
menu_items.push({
html: i18n('zip'),
onClick: function(){
zipItems(el_item, path.dirname($(el_item).attr('data-path')), false);
window.zipItems(el_item, path.dirname($(el_item).attr('data-path')), false);
}
})
}
@@ -1177,7 +1177,7 @@ function UIItem(options){
html: i18n('restore'),
onClick: async function(){
let metadata = $(el_item).attr('data-metadata') === '' ? {} : JSON.parse($(el_item).attr('data-metadata'))
move_items([el_item], path.dirname(metadata.original_path));
window.move_items([el_item], path.dirname(metadata.original_path));
}
});
}
@@ -1216,12 +1216,12 @@ function UIItem(options){
if($(el_item).attr('data-is_dir') === '1' && !is_trashed && !is_trash){
menu_items.push({
html: i18n('paste_into_folder'),
disabled: clipboard.length > 0 ? false : true,
disabled: window.clipboard.length > 0 ? false : true,
onClick: function(){
if(clipboard_op === 'copy')
copy_clipboard_items($(el_item).attr('data-path'), null);
else if(clipboard_op === 'move')
move_clipboard_items(null, $(el_item).attr('data-path'))
if(window.clipboard_op === 'copy')
window.copy_clipboard_items($(el_item).attr('data-path'), null);
else if(window.clipboard_op === 'move')
window.move_clipboard_items(null, $(el_item).attr('data-path'))
}
})
}
@@ -1244,7 +1244,7 @@ function UIItem(options){
base_dir = window.desktop_path;
}
create_shortcut(
window.create_shortcut(
path.basename($(el_item).attr('data-path')),
options.is_dir,
base_dir,
@@ -1262,7 +1262,7 @@ function UIItem(options){
menu_items.push({
html: i18n('delete'),
onClick: async function(){
move_items([el_item], trash_path);
window.move_items([el_item], window.trash_path);
}
});
}
@@ -1287,17 +1287,17 @@ function UIItem(options){
})
if((alert_resp) === 'Delete'){
await delete_item(el_item);
await window.delete_item(el_item);
// check if trash is empty
const trash = await puter.fs.stat(trash_path);
const trash = await puter.fs.stat(window.trash_path);
// update other clients
if(window.socket){
window.socket.emit('trash.is_empty', {is_empty: trash.is_empty});
}
// update this client
if(trash.is_empty){
$(`.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']);
}
}
}
@@ -1310,7 +1310,7 @@ function UIItem(options){
menu_items.push({
html: i18n('rename'),
onClick: function(){
activate_item_name_editor(el_item)
window.activate_item_name_editor(el_item)
}
});
}
@@ -1370,10 +1370,10 @@ function UIItem(options){
})
if(options.sort_container_after_append){
sort_items(options.appendTo, $(el_item).closest('.item-container').attr('data-sort_by'), $(el_item).closest('.item-container').attr('data-sort_order'));
window.sort_items(options.appendTo, $(el_item).closest('.item-container').attr('data-sort_by'), $(el_item).closest('.item-container').attr('data-sort_order'));
}
if(options.editable){
activate_item_name_editor(el_item)
window.activate_item_name_editor(el_item)
}
}
@@ -1430,7 +1430,7 @@ $(document).on('contextmenu', '.item-has-website-url-badge', async function(e){
onClick: async function(){
const website_url = $(e.target).closest('.item').attr('data-website_url');
if(website_url){
await copy_to_clipboard(website_url);
await window.copy_to_clipboard(website_url);
}
}
},
@@ -1514,7 +1514,7 @@ $.fn.removeItems = async function(options) {
$(this).each(async function() {
const parent_container = $(this).closest('.item-container');
$(this).remove();
show_or_hide_empty_folder_message(parent_container);
window.show_or_hide_empty_folder_message(parent_container);
});
return this;
+8 -7
View File
@@ -18,12 +18,12 @@
*/
function UINotification(options){
global_element_id++;
window.global_element_id++;
options.content = options.content ?? '';
let h = '';
h += `<div id="ui-notification__${global_element_id}" class="notification antialiased animate__animated animate__fadeInRight animate__slow">`;
h += `<div id="ui-notification__${window.global_element_id}" class="notification antialiased animate__animated animate__fadeInRight animate__slow">`;
h += `<img class="notification-close" src="${html_encode(window.icons['close.svg'])}">`;
h += html_encode(options.content);
h += `</div>`;
@@ -31,7 +31,7 @@ function UINotification(options){
$('body').append(h);
const el_notification = document.getElementById(`ui-notification__${global_element_id}`);
const el_notification = document.getElementById(`ui-notification__${window.global_element_id}`);
$(el_notification).show(0, function(e){
// options.onAppend()
@@ -44,7 +44,7 @@ function UINotification(options){
$(el_notification).delay(100).show(0).
// In the right position (the mouse)
css({
top: toolbar_height + 15,
top: window.toolbar_height + 15,
});
return el_notification;
@@ -52,9 +52,10 @@ function UINotification(options){
$(document).on('click', '.notification', function(e){
if($(e.target).hasClass('notification')){
if(options.click && typeof options.click === 'function'){
options.click(e);
}
// TODO: options isn't available here
// if(options.click && typeof options.click === 'function'){
// options.click(e);
// }
window.close_notification(e.target);
}else{
window.close_notification($(e.target).closest('.notification'));
+4 -4
View File
@@ -25,19 +25,19 @@ function UIPopover(options){
$('.window-active .window-app-iframe').css('pointer-events', 'none');
global_element_id++;
window.global_element_id++;
options.content = options.content ?? '';
let h = '';
h += `<div id="popover-${global_element_id}" class="popover">`;
h += `<div id="popover-${window.global_element_id}" class="popover">`;
h += options.content;
h += `</div>`;
$('body').append(h);
const el_popover = document.getElementById(`popover-${global_element_id}`);
const el_popover = document.getElementById(`popover-${window.global_element_id}`);
$(el_popover).show(0, function(e){
// options.onAppend()
@@ -73,7 +73,7 @@ function UIPopover(options){
// Y position
const popover_height = options.height ?? $(el_popover).height();
if(options.center_horizontally){
y_pos = options.top ?? (window.innerHeight - (taskbar_height + popover_height + 10));
y_pos = options.top ?? (window.innerHeight - (window.taskbar_height + popover_height + 10));
}else{
y_pos = options.top ?? ($(options.snapToElement).offset().top + $(options.snapToElement).height() + 5);
}
+1 -1
View File
@@ -23,7 +23,7 @@ function UIPrompt(options){
// set sensible defaults
if(arguments.length > 0){
// if first argument is a string, then assume it is the message
if(isString(arguments[0])){
if(window.isString(arguments[0])){
options = {};
options.message = arguments[0];
}
+26 -27
View File
@@ -21,19 +21,19 @@ import UITaskbarItem from './UITaskbarItem.js'
import UIPopover from './UIPopover.js'
async function UITaskbar(options){
global_element_id++;
window.global_element_id++;
options = options ?? {};
options.content = options.content ?? '';
// get launch apps
$.ajax({
url: api_origin + "/get-launch-apps",
url: window.api_origin + "/get-launch-apps",
type: 'GET',
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
success: function (apps){
window.launch_apps = apps;
@@ -41,7 +41,7 @@ async function UITaskbar(options){
});
let h = '';
h += `<div id="ui-taskbar_${global_element_id}" class="taskbar" style="height:${window.taskbar_height}px;"><span id='clock'></span></div>`;
h += `<div id="ui-taskbar_${window.global_element_id}" class="taskbar" style="height:${window.taskbar_height}px;"><span id='clock'></span></div>`;
$('.desktop').append(h);
@@ -74,15 +74,15 @@ async function UITaskbar(options){
// In the rare case that launch_apps is not populated yet, get it from the server
// then populate the popover
if(!launch_apps || !launch_apps.recent || launch_apps.recent.length === 0){
if(!window.launch_apps || !window.launch_apps.recent || window.launch_apps.recent.length === 0){
// get launch apps
launch_apps = await $.ajax({
url: api_origin + "/get-launch-apps",
window.launch_apps = await $.ajax({
url: window.api_origin + "/get-launch-apps",
type: 'GET',
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
});
}
@@ -96,14 +96,14 @@ async function UITaskbar(options){
// -------------------------------------------
// Recent apps
// -------------------------------------------
if(launch_apps.recent.length > 0){
if(window.launch_apps.recent.length > 0){
// heading
apps_str += `<h1 class="start-section-heading start-section-heading-recent">${i18n('recent')}</h1>`;
// apps
apps_str += `<div class="launch-apps-recent">`;
for (let index = 0; index < window.launch_recent_apps_count && index < launch_apps.recent.length; index++) {
const app_info = launch_apps.recent[index];
for (let index = 0; index < window.launch_recent_apps_count && index < window.launch_apps.recent.length; index++) {
const app_info = window.launch_apps.recent[index];
apps_str += `<div title="${html_encode(app_info.title)}" data-name="${html_encode(app_info.name)}" class="start-app-card">`;
apps_str += `<div class="start-app" data-app-name="${html_encode(app_info.name)}" data-app-uuid="${html_encode(app_info.uuid)}" data-app-icon="${html_encode(app_info.icon)}" data-app-title="${html_encode(app_info.title)}">`;
apps_str += `<img class="start-app-icon" src="${html_encode(app_info.icon ? app_info.icon : window.icons['app.svg'])}">`;
@@ -116,14 +116,14 @@ async function UITaskbar(options){
// -------------------------------------------
// Reccomended apps
// -------------------------------------------
if(launch_apps.recommended.length > 0){
if(window.launch_apps.recommended.length > 0){
// heading
apps_str += `<h1 class="start-section-heading start-section-heading-recommended" style="${launch_apps.recent.length > 0 ? 'padding-top: 30px;' : ''}">Recommended</h1>`;
apps_str += `<h1 class="start-section-heading start-section-heading-recommended" style="${window.launch_apps.recent.length > 0 ? 'padding-top: 30px;' : ''}">Recommended</h1>`;
// apps
apps_str += `<div class="launch-apps-recommended">`;
for (let index = 0; index < launch_apps.recommended.length; index++) {
const app_info = launch_apps.recommended[index];
for (let index = 0; index < window.launch_apps.recommended.length; index++) {
const app_info = window.launch_apps.recommended[index];
apps_str += `<div title="${html_encode(app_info.title)}" data-name="${html_encode(app_info.name)}" class="start-app-card">`;
apps_str += `<div class="start-app" data-app-name="${html_encode(app_info.name)}" data-app-uuid="${html_encode(app_info.uuid)}" data-app-icon="${html_encode(app_info.icon)}" data-app-title="${html_encode(app_info.title)}">`;
apps_str += `<img class="start-app-icon" src="${html_encode(app_info.icon ? app_info.icon : window.icons['app.svg'])}">`;
@@ -176,7 +176,7 @@ async function UITaskbar(options){
onClick: function(){
let open_window_count = parseInt($(`.taskbar-item[data-app="explorer"]`).attr('data-open-windows'));
if(open_window_count === 0){
launch_app({ name: 'explorer', path: window.home_path});
window.launch_app({ name: 'explorer', path: window.home_path});
}else{
return false;
}
@@ -198,7 +198,7 @@ async function UITaskbar(options){
onClick: function(){
let open_window_count = parseInt($(`.taskbar-item[data-app="${app_info.name}"]`).attr('data-open-windows'));
if(open_window_count === 0){
launch_app({
window.launch_app({
name: app_info.name,
})
}else{
@@ -212,7 +212,7 @@ async function UITaskbar(options){
//---------------------------------------------
// add `Trash` to the taskbar
//---------------------------------------------
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});
}
@@ -225,19 +225,19 @@ async function UITaskbar(options){
keep_in_taskbar: true,
lock_keep_in_taskbar: true,
onClick: function(){
let open_windows = $(`.window[data-path="${html_encode(trash_path)}"]`);
let open_windows = $(`.window[data-path="${html_encode(window.trash_path)}"]`);
if(open_windows.length === 0){
launch_app({ name: 'explorer', path: window.trash_path});
window.launch_app({ name: 'explorer', path: window.trash_path});
}else{
open_windows.focusWindow();
}
},
onItemsDrop: function(items){
move_items(items, trash_path);
window.move_items(items, window.trash_path);
}
})
make_taskbar_sortable();
window.make_taskbar_sortable();
}
window.make_taskbar_sortable = function(){
@@ -259,7 +259,6 @@ window.make_taskbar_sortable = function(){
$(this).sortable('cancel');
$('.taskbar .start-app').remove();
return;
}else{
}
}
},
@@ -281,7 +280,7 @@ window.make_taskbar_sortable = function(){
onClick: function(){
let open_window_count = parseInt($(`.taskbar-item[data-app="${$(ui.item).attr('data-app-name')}"]`).attr('data-open-windows'));
if(open_window_count === 0){
launch_app({
window.launch_app({
name: $(ui.item).attr('data-app-name'),
})
}else{
@@ -293,12 +292,12 @@ window.make_taskbar_sortable = function(){
$(el).insertAfter(ui.item);
// $(ui.item).insertBefore(`<h1>Hello!</h1>`);
$(el).show();
$(ui.item).removeItems();
update_taskbar();
$(ui.item).removeItems();
window.update_taskbar();
}
// only proceed to update DB if the item sorted was a pinned item otherwise no point in updating the taskbar in DB
else if($(ui.item).attr('data-keep-in-taskbar') === 'true'){
update_taskbar();
window.update_taskbar();
}
},
});
+10 -9
View File
@@ -18,6 +18,7 @@
*/
import UIContextMenu from './UIContextMenu.js';
import path from '../lib/path.js';
let tray_item_id = 1;
@@ -28,7 +29,7 @@ function UITaskbarItem(options){
options.open_windows_count = options.open_windows_count ?? 0;
options.lock_keep_in_taskbar = options.lock_keep_in_taskbar ?? false;
options.append_to_taskbar = options.append_to_taskbar ?? true;
const element_id = global_element_id++;
const element_id = window.global_element_id++;
h += `<div class = "taskbar-item ${options.sortable ? 'taskbar-item-sortable' : ''} disable-user-select"
id = "taskbar-item-${tray_item_id}"
@@ -121,7 +122,7 @@ function UITaskbarItem(options){
html: 'New Window',
val: $(this).attr('data-id'),
onClick: function(){
launch_app({
window.launch_app({
name: options.app,
maximized: (isMobile.phone || isMobile.tablet),
})
@@ -140,7 +141,7 @@ function UITaskbarItem(options){
html: i18n('empty_trash'),
val: $(this).attr('data-id'),
onClick: async function(){
empty_trash();
window.empty_trash();
}
})
}
@@ -155,9 +156,9 @@ function UITaskbarItem(options){
onClick: function(){
$(el_taskbar_item).attr('data-keep-in-taskbar', 'false');
if($(el_taskbar_item).attr('data-open-windows') === '0'){
remove_taskbar_item(el_taskbar_item);
window.remove_taskbar_item(el_taskbar_item);
}
update_taskbar();
window.update_taskbar();
options.keep_in_taskbar = false;
}
})
@@ -171,7 +172,7 @@ function UITaskbarItem(options){
val: $(this).attr('data-id'),
onClick: function(){
$(el_taskbar_item).attr('data-keep-in-taskbar', 'true');
update_taskbar();
window.update_taskbar();
options.keep_in_taskbar = true;
}
})
@@ -247,7 +248,7 @@ function UITaskbarItem(options){
tolerance: 'pointer',
drop: async function( event, ui ) {
// Check if hovering over an item that is VISIBILE
if($(event.target).closest('.window').attr('data-id') !== $(mouseover_window).attr('data-id'))
if($(event.target).closest('.window').attr('data-id') !== $(window.mouseover_window).attr('data-id'))
return;
// If ctrl is pressed and source is Trashed, cancel whole operation
@@ -294,7 +295,7 @@ function UITaskbarItem(options){
// open each item
for (let i = 0; i < items_to_sign.length; i++) {
const item = items_to_sign[i];
launch_app({
window.launch_app({
name: options.app,
file_path: item.path,
// app_obj: open_item_meta.suggested_apps[0],
@@ -325,7 +326,7 @@ function UITaskbarItem(options){
over: function(event, ui){
// Check hovering over an item that is VISIBILE
const $event_parent_win = $(event.target).closest('.window')
if( $event_parent_win.length > 0 && $event_parent_win.attr('data-id') !== $(mouseover_window).attr('data-id'))
if( $event_parent_win.length > 0 && $event_parent_win.attr('data-id') !== $(window.mouseover_window).attr('data-id'))
return;
// Don't do anything if the dragged item is NOT a UIItem
if(!$(ui.draggable).hasClass('item'))
+229 -227
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -104,7 +104,7 @@ async function UIWindowChangePassword(options){
return;
}
// check password strength
const pass_strength = check_password_strength(new_password);
const pass_strength = window.check_password_strength(new_password);
if(!pass_strength.overallPass){
$(el_window).find('.form-error-msg').html(i18n('password_strength_error'));
$(el_window).find('.form-error-msg').fadeIn();
@@ -114,11 +114,11 @@ async function UIWindowChangePassword(options){
$(el_window).find('.form-error-msg').hide();
$.ajax({
url: api_origin + "/passwd",
url: window.api_origin + "/passwd",
type: 'POST',
async: true,
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
contentType: "application/json",
data: JSON.stringify({
+2 -2
View File
@@ -94,11 +94,11 @@ async function UIWindowChangeUsername(options){
$(el_window).find('.new-username').attr('disabled', true);
$.ajax({
url: api_origin + "/change_username",
url: window.api_origin + "/change_username",
type: 'POST',
async: true,
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
contentType: "application/json",
data: JSON.stringify({
+1 -1
View File
@@ -23,7 +23,7 @@ async function UIWindowColorPicker(options){
// set sensible defaults
if(arguments.length > 0){
// if first argument is a string, then assume it is the default color
if(isString(arguments[0])){
if(window.isString(arguments[0])){
options = {};
options.default = arguments[0];
}
+1 -1
View File
@@ -71,7 +71,7 @@ async function UIWindowCopyProgress(options){
});
$(el_window).find('.copy-cancel-btn').on('click', function(e){
operation_cancelled[options.operation_id] = true;
window.operation_cancelled[options.operation_id] = true;
$(el_window).close();
})
+4 -3
View File
@@ -165,7 +165,7 @@ async function UIWindowDesktopBGSettings(options){
// /set-desktop-bg
try{
$.ajax({
url: api_origin + "/set-desktop-bg",
url: window.api_origin + "/set-desktop-bg",
type: 'POST',
data: JSON.stringify({
url: window.desktop_bg_url,
@@ -175,17 +175,18 @@ async function UIWindowDesktopBGSettings(options){
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
statusCode: {
401: function () {
logout();
window.logout();
},
},
})
$(el_window).close();
resolve(true);
}catch(err){
// Ignore
}
})
+1 -1
View File
@@ -71,7 +71,7 @@ async function UIWindowDownloadProgress(options){
// cancel download button clicked
$(el_window).find('.download-cancel-btn').on('click', function(){
operation_cancelled[options.operation_id] = true;
window.operation_cancelled[options.operation_id] = true;
$(el_window).close();
})
+8 -8
View File
@@ -110,7 +110,7 @@ function UIWindowEmailConfirmationRequired(options){
setTimeout(() => {
$.ajax({
url: api_origin + "/confirm-email",
url: window.api_origin + "/confirm-email",
type: 'POST',
data: JSON.stringify({
code: final_code,
@@ -118,17 +118,17 @@ function UIWindowEmailConfirmationRequired(options){
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
statusCode: {
401: function () {
logout();
window.logout();
},
},
success: function (res){
if(res.email_confirmed){
$(el_window).close();
refresh_user_data(window.auth_token)
window.refresh_user_data(window.auth_token)
resolve(true);
}else{
$(el_window).find('.error').html('Invalid confirmation code.');
@@ -157,16 +157,16 @@ function UIWindowEmailConfirmationRequired(options){
// send email confirmation
$(el_window).find('.send-conf-email').on('click', function(e){
$.ajax({
url: api_origin + "/send-confirm-email",
url: window.api_origin + "/send-confirm-email",
type: 'POST',
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
statusCode: {
401: function () {
logout();
window.logout();
},
},
success: async function (res){
@@ -185,7 +185,7 @@ function UIWindowEmailConfirmationRequired(options){
// logout
$(el_window).find('.conf-email-log-out').on('click', function(e){
logout();
window.logout();
$(el_window).close();
})
+2 -2
View File
@@ -76,12 +76,12 @@ async function UIWindowQR(options){
if(message)
$(this).prop('disabled', true);
$.ajax({
url: api_origin + "/contactUs",
url: window.api_origin + "/contactUs",
type: 'POST',
async: true,
contentType: "application/json",
headers: {
"Authorization": "Bearer "+auth_token
"Authorization": "Bearer "+window.auth_token
},
data: JSON.stringify({
message: message,
+2 -2
View File
@@ -42,7 +42,7 @@ async function UIWindowFontPicker(options){
// set sensible defaults
if(arguments.length > 0){
// if first argument is a string, then assume it is the default color
if(isString(arguments[0])){
if(window.isString(arguments[0])){
options = {};
options.default = arguments[0];
}
@@ -92,7 +92,7 @@ async function UIWindowFontPicker(options){
onAppend: function(window){
let active_font = $(window).find('.font-selector-active');
if(active_font.length > 0){
scrollParentToChild($(window).find('.font-list').get(0), active_font.get(0));
window.scrollParentToChild($(window).find('.font-list').get(0), active_font.get(0));
}
},
window_class: 'window-login',
+5 -3
View File
@@ -132,7 +132,9 @@ async function UIWindowItemProperties(item_name, item_path, item_uid, left, top,
$(el_window).find('.item-prop-val-original-path').text(metadata.original_path);
$(el_window).find('.item-prop-original-path').show();
}
}catch(e){}
}catch(e){
// Ignored
}
}
// shortcut to
@@ -144,7 +146,7 @@ async function UIWindowItemProperties(item_name, item_path, item_uid, left, top,
// type
$(el_window).find('.item-prop-val-type').html(fsentry.is_dir ? 'Directory' : (fsentry.type === null ? '-' : fsentry.type));
// size
$(el_window).find('.item-prop-val-size').html(fsentry.size === null || fsentry.size === undefined ? '-' : byte_format(fsentry.size));
$(el_window).find('.item-prop-val-size').html(fsentry.size === null || fsentry.size === undefined ? '-' : window.byte_format(fsentry.size));
// modified
$(el_window).find('.item-prop-val-modified').html(fsentry.modified === 0 ? '-' : timeago.format(fsentry.modified*1000));
// created
@@ -152,7 +154,7 @@ async function UIWindowItemProperties(item_name, item_path, item_uid, left, top,
// subdomains
if(fsentry.subdomains && fsentry.subdomains.length > 0 ){
fsentry.subdomains.forEach(subdomain => {
$(el_window).find('.item-prop-val-websites').append(`<p class="item-prop-website-entry" data-uuid="${html_encode(subdomain.uuid)}" style="margin-bottom:5px; margin-top:5px;"><a target="_blank" href="${html_encode(subdomain.address)}">${html_encode(subdomain.address)}</a> (<span class="disassociate-website-link" data-uuid="${html_encode(subdomain.uuid)}" data-subdomain="${extractSubdomain(subdomain.address)}">disassociate</span>)</p>`);
$(el_window).find('.item-prop-val-websites').append(`<p class="item-prop-website-entry" data-uuid="${html_encode(subdomain.uuid)}" style="margin-bottom:5px; margin-top:5px;"><a target="_blank" href="${html_encode(subdomain.address)}">${html_encode(subdomain.address)}</a> (<span class="disassociate-website-link" data-uuid="${html_encode(subdomain.uuid)}" data-subdomain="${window.extractSubdomain(subdomain.address)}">disassociate</span>)</p>`);
});
}
else{
+6 -6
View File
@@ -138,7 +138,7 @@ async function UIWindowLogin(options){
const password = $(el_window).find('.password').val();
let data;
if(is_email(email_username)){
if(window.is_email(email_username)){
data = JSON.stringify({
email: email_username,
password: password
@@ -157,14 +157,14 @@ async function UIWindowLogin(options){
headers = window.custom_headers;
$.ajax({
url: gui_origin + "/login",
url: window.gui_origin + "/login",
type: 'POST',
async: false,
headers: headers,
contentType: "application/json",
data: data,
success: function (data){
update_auth_data(data.token, data.user);
window.update_auth_data(data.token, data.user);
if(options.reload_on_success){
window.onbeforeunload = null;
@@ -177,15 +177,15 @@ async function UIWindowLogin(options){
const $errorMessage = $(el_window).find('.login-error-msg');
if (err.status === 404) {
// Don't include the whole 404 page
$errorMessage.html(`Error 404: "${gui_origin}/login" not found`);
$errorMessage.html(`Error 404: "${window.gui_origin}/login" not found`);
} else if (err.responseText) {
$errorMessage.html(html_encode(err.responseText));
} else {
// No message was returned. *Probably* this means we couldn't reach the server.
// If this is a self-hosted instance, it's probably a configuration issue.
if (app_domain !== 'puter.com') {
if (window.app_domain !== 'puter.com') {
$errorMessage.html(`<div style="text-align: left;">
<p>Error reaching "${gui_origin}/login". This is likely to be a configuration issue.</p>
<p>Error reaching "${window.gui_origin}/login". This is likely to be a configuration issue.</p>
<p>Make sure of the following:</p>
<ul style="padding-left: 2em;">
<li><code>domain</code> in config.json is set to the domain you're using to access puter</li>
+2 -2
View File
@@ -88,7 +88,7 @@ const UIWindowManageSessions = async function UIWindowManageSessions (options) {
return;
}
const resp = await fetch(`${api_origin}/auth/revoke-session`, {
const resp = await fetch(`${window.api_origin}/auth/revoke-session`, {
method: 'POST',
headers: {
Authorization: `Bearer ${puter.authToken}`,
@@ -119,7 +119,7 @@ const UIWindowManageSessions = async function UIWindowManageSessions (options) {
};
const reload_sessions = async () => {
const resp = await fetch(`${api_origin}/auth/list-sessions`, {
const resp = await fetch(`${window.api_origin}/auth/list-sessions`, {
headers: {
Authorization: `Bearer ${puter.authToken}`,
},

Some files were not shown because too many files have changed in this diff Show More