diff --git a/.env.example b/.env.example
new file mode 100644
index 00000000..57727ee9
--- /dev/null
+++ b/.env.example
@@ -0,0 +1 @@
+PORT=4000
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 8b23bc40..6988d808 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,4 +4,8 @@ node_modules/
*.tgz
license.config.json
license-header.txt
-dist/
\ No newline at end of file
+dist/
+.vscode/
+.env
+# this is for jetbrain IDEs
+.idea/
\ No newline at end of file
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 00000000..d1326460
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,73 @@
+# Contributing to Puter
+
+Welcome to Puter, the open-source distributed internet operating system. We're excited to have you contribute to our project, whether you're reporting bugs, suggesting new features, or contributing code. This guide will help you get started with contributing to Puter in different ways.
+
+
+
+# Report bugs
+
+Before reporting a bug, please check our [the issues on our GitHub repository](https://github.com/HeyPuter/puter/issues) to see if the bug has already been reported. If it has, you can add a comment to the existing issue with any additional information you have.
+
+If you find a new bug in Puter, please [open an issue on our GitHub repository](https://github.com/HeyPuter/puter/issues/new). We'll do our best to address the issue as soon as possible. When reporting a bug, please include as much information as possible, including:
+
+- A clear and descriptive title
+- A description of the issue
+- Steps to reproduce the bug
+- Expected behavior
+- Actual behavior
+- Screenshots, if applicable
+- Your host operating system and browser
+- Your Puter version, location, ...
+
+Please open a separate issue for each bug you find.
+
+Maintainers will apply the appropriate labels to your issue.
+
+
+
+# Suggest new features
+
+If you have an idea for a new feature in Puter, please open a new discussion thread on our [GitHub repository](https://github.com/HeyPuter/puter/discussions) to discuss your idea with the community. We'll do our best to respond to your suggestion as soon as possible.
+
+When suggesting a new feature, please include as much information as possible, including:
+
+- A clear and descriptive title
+- A description of the feature
+- The problem the feature will solve
+- Any relevant screenshots or mockups
+- Any relevant links or resources
+
+
+
+# Contribute code
+
+If you'd like to contribute code to Puter, you need to fork the project and submit a pull request. If this is your first time contributing to an open-source project, we recommend reading this short guide by GitHub on [how to contribute to a project](https://docs.github.com/en/get-started/exploring-projects-on-github/contributing-to-a-project).
+
+We'll review your pull request and work with you to get your changes merged into the project.
+
+## Your first code contribution
+
+We maintain a list of issues that are good for first-time contributors. You can find these issues by searching for the [`good first issue`](https://github.com/HeyPuter/puter/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label in our [GitHub repository](https://github.com/HeyPuter/puter). These issues are designed to be relatively easy to fix, and we're happy to help you get started. Pick an issue that interests you, and leave a comment on the issue to let us know you're working on it.
+
+
+
+## Code Review
+
+Once you've submitted your pull request, the project maintainers will review your changes. We may suggest some changes or improvements. This is a normal part of the process, and your contributions are greatly appreciated!
+
+
+
+## Contribution License Agreement (CLA)
+
+Like many open source projects, we require contributors to sign a Contribution License Agreement (CLA) before we can accept your code. When you open a pull request for the first time, a bot will automatically add a comment with a link to the CLA. You can sign the CLA electronically by following the link and filling out the form.
+
+
+
+# Getting Help
+
+If you have any questions about Puter, please feel free to reach out to us through the following channels:
+
+- [Discord](https://discord.com/invite/PQcx7Teh8u)
+- [Reddit](https://www.reddit.com/r/Puter/)
+- [Twitter](https://twitter.com/HeyPuter)
+- [Email](mailto:support@puter.com)
diff --git a/README.md b/README.md
index 9436bb2b..a14609ba 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
-Internet OS and Desktop Environment in the Browser!
+The Internet OS, Free and Open-Source!
« LIVE DEMO »
diff --git a/SECURITY-ACKNOWLEDGEMENTS.md b/SECURITY-ACKNOWLEDGEMENTS.md
new file mode 100644
index 00000000..4ad8908d
--- /dev/null
+++ b/SECURITY-ACKNOWLEDGEMENTS.md
@@ -0,0 +1,7 @@
+We would like to thank the following security researchers for their responsible disclosures:
+
+
+# 2024
+
+- Tim Suess: [GitHub](https://github.com/blackfortresslabs) | [Email](tim@blackfortresslabs.com) | [Website](blackfortresslabs.com)
+- xyzeva: [Github](https://github.com/xyzeva) | [Email](mailto:xyzeva@riseup.net) | [Website](https://kibty.town/)
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 00000000..0466993a
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,40 @@
+# Puter Security Policy
+
+Thank you for helping make Puter safe. Keeping user information safe and secure is a top priority, and we welcome the contribution of external security researchers.
+
+
+
+# Scope
+
+If you believe you've found a security issue in software that is maintained in this repository, we encourage you to notify us.
+
+
+
+# How to Submit a Report
+
+To submit a vulnerability report, please contact us at security@puter.com. Your submission will be reviewed and validated by a member of our team.
+
+**⚠ Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests. ⚠**
+
+
+
+# Safe Harbor
+
+We support safe harbor for security researchers who:
+
+* Make a good faith effort to avoid privacy violations, destruction of data, and interruption or degradation of our services.
+* Only interact with accounts you own or with explicit permission of the account holder. If you do encounter Personally Identifiable Information (PII) contact us immediately, do not proceed with access, and immediately purge any local information.
+* Provide us with a reasonable amount of time to resolve vulnerabilities prior to any disclosure to the public or a third-party.
+
+We will consider activities conducted consistent with this policy to constitute "authorized" conduct and will not pursue civil action or initiate a complaint to law enforcement. We will help to the extent we can if legal action is initiated by a third party against you.
+
+Please submit a report to us before engaging in conduct that may be inconsistent with or unaddressed by this policy.
+
+
+
+# Preferences
+
+* Please provide detailed reports with reproducible steps and a clearly defined impact.
+* Include the version number of the vulnerable package in your report
+* Social engineering (e.g. phishing, vishing, smishing) is prohibited.
+
diff --git a/dev-server.js b/dev-server.js
index 9dfc3b30..2add5966 100644
--- a/dev-server.js
+++ b/dev-server.js
@@ -2,21 +2,22 @@ const express = require("express");
const { generateDevHtml, build } = require("./utils.js");
const { argv } = require('node:process');
const chalk = require('chalk');
+const dotenv = require('dotenv');
+dotenv.config();
const app = express();
-let port = 4000; // Starting port
+let port = process.env.PORT ?? 4000; // Starting port
const maxAttempts = 10; // Maximum number of ports to try
const env = argv[2] ?? "dev";
-const startServer = (attempt) => {
+const startServer = (attempt, useAnyFreePort = false) => {
if (attempt > maxAttempts) {
- console.error(chalk.red(`ERROR: Unable to find an available port after ${maxAttempts} attempts.`));
- return;
+ useAnyFreePort = true; // Use any port that is free
}
- app.listen(port, () => {
+ const server = app.listen(useAnyFreePort ? 0 : port, () => {
console.log("\n-----------------------------------------------------------\n");
- console.log(`Puter is now live at: `, chalk.underline.blue(`http://localhost:${port}`));
+ console.log(`Puter is now live at: `, chalk.underline.blue(`http://localhost:${server.address().port}`));
console.log("\n-----------------------------------------------------------\n");
}).on('error', (err) => {
if (err.code === 'EADDRINUSE') { // Check if the error is because the port is already in use
diff --git a/incubator/x86emu/README.md b/incubator/x86emu/README.md
new file mode 100644
index 00000000..e74e444d
--- /dev/null
+++ b/incubator/x86emu/README.md
@@ -0,0 +1,17 @@
+# Research + Planning for x86 Emulation in Puter
+
+## Resources
+- [copy.sh/v86 docs](https://github.com/copy/v86/blob/master/docs)
+- [greenfield github](https://github.com/udevbe/greenfield)
+
+## TODO
+
+### Documents to Write
+
+- [ ] specification for Puter network driver
+- [ ] specification for Puter network relay
+
+### Things to Try
+
+- [ ] greenfield/wayland/arch/v86
+- [ ] puter-fuse in v86
diff --git a/package-lock.json b/package-lock.json
index 9087a096..06af7d6d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11,6 +11,7 @@
"devDependencies": {
"chalk": "^4.1.0",
"clean-css": "^5.3.2",
+ "dotenv": "^16.4.5",
"express": "^4.18.2",
"html-entities": "^2.3.3",
"nodemon": "^2.0.22",
@@ -781,6 +782,18 @@
"npm": "1.2.8000 || >= 1.4.16"
}
},
+ "node_modules/dotenv": {
+ "version": "16.4.5",
+ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz",
+ "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==",
+ "dev": true,
+ "engines": {
+ "node": ">=12"
+ },
+ "funding": {
+ "url": "https://dotenvx.com"
+ }
+ },
"node_modules/ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
diff --git a/package.json b/package.json
index e9074d8f..986ff893 100644
--- a/package.json
+++ b/package.json
@@ -11,11 +11,12 @@
"devDependencies": {
"chalk": "^4.1.0",
"clean-css": "^5.3.2",
- "html-entities": "^2.3.3",
- "webpack": "^5.88.2",
+ "dotenv": "^16.4.5",
"express": "^4.18.2",
+ "html-entities": "^2.3.3",
"nodemon": "^2.0.22",
"uglify-js": "^3.17.4",
+ "webpack": "^5.88.2",
"webpack-cli": "^5.1.1"
},
"scripts": {
diff --git a/src/UI/UIDesktop.js b/src/UI/UIDesktop.js
index 6b85a06e..2926f433 100644
--- a/src/UI/UIDesktop.js
+++ b/src/UI/UIDesktop.js
@@ -498,6 +498,12 @@ async function UIDesktop(options){
window.history.pushState(null, document.title, '/');
}
+ // update local user preferences
+ const user_preferences = {
+ show_hidden_files: (await puter.kv.get('user_preferences.show_hidden_files')) === 'true',
+ };
+ update_user_preferences(user_preferences);
+
// Append to
$('body').append(h);
@@ -683,6 +689,18 @@ async function UIDesktop(options){
}
},
// -------------------------------------------
+ // Show/Hide hidden files
+ // -------------------------------------------
+ {
+ html: `${window.user_preferences.show_hidden_files ? 'Hide' : 'Show'} hidden files`,
+ onClick: function(){
+ window.mutate_user_preferences({
+ show_hidden_files : !window.user_preferences.show_hidden_files,
+ });
+ window.show_or_hide_files(document.querySelectorAll('.item-container'));
+ }
+ },
+ // -------------------------------------------
// -
// -------------------------------------------
'-',
@@ -708,6 +726,16 @@ async function UIDesktop(options){
}
},
// -------------------------------------------
+ // Undo
+ // -------------------------------------------
+ {
+ html: "Undo",
+ disabled: actions_history.length > 0 ? false : true,
+ onClick: function(){
+ undo_last_action();
+ }
+ },
+ // -------------------------------------------
// Upload Here
// -------------------------------------------
{
diff --git a/src/UI/UIItem.js b/src/UI/UIItem.js
index 989ed77c..e90f420f 100644
--- a/src/UI/UIItem.js
+++ b/src/UI/UIItem.js
@@ -46,6 +46,7 @@ function UIItem(options){
// set options defaults
options.disabled = options.disabled ?? false;
+ options.visible = options.visible ?? 'visible'; // one of 'visible', 'revealed', 'hidden'
options.is_dir = options.is_dir ?? false;
options.is_selected = options.is_selected ?? false;
options.is_shared = options.is_shared ?? false;
@@ -71,7 +72,7 @@ function UIItem(options){
// --------------------------------------------------------
let h = '';
h += `{
- // Has the extension changed? in that case update options.sugggested_apps
- const old_extension = path.extname(old_name);
- const new_extension = path.extname(new_name);
- if(old_extension !== new_extension){
- suggest_apps_for_fsentry({
- uid: options.uid,
- onSuccess: function(suggested_apps){
- options.suggested_apps = suggested_apps;
- }
- });
- }
-
- // Set new item name
- $(`.item[data-uid='${$(el_item).attr('data-uid')}'] .item-name`).html(html_encode(truncate_filename(new_name, TRUNCATE_LENGTH)).replaceAll(' ', ' '));
- $(el_item_name).show();
-
- // Hide item name editor
- $(el_item_name_editor).hide();
-
- // Set new icon
- const new_icon = (options.is_dir ? window.icons['folder.svg'] : (await item_icon(fsentry)).image);
- $(el_item_icon).find('.item-icon-icon').attr('src', new_icon);
-
- // Set new data-name
- options.name = new_name;
- $(el_item).attr('data-name', html_encode(new_name));
- $(`.item[data-uid='${$(el_item).attr('data-uid')}']`).attr('data-name', html_encode(new_name));
- $(`.window-${options.uid}`).attr('data-name', html_encode(new_name));
-
- // Set new title attribute
- $(`.item[data-uid='${$(el_item).attr('data-uid')}']`).attr('title', html_encode(new_name));
- $(`.window-${options.uid}`).attr('title', html_encode(new_name));
-
- // Set new value for item-name-editor
- $(`.item[data-uid='${$(el_item).attr('data-uid')}'] .item-name-editor`).val(html_encode(new_name));
- $(`.item[data-uid='${$(el_item).attr('data-uid')}'] .item-name`).attr('title', html_encode(new_name));
-
- // Set new data-path
- options.path = path.join( path.dirname(options.path), options.name);
- const new_path = options.path;
- $(el_item).attr('data-path', new_path);
- $(`.item[data-uid='${$(el_item).attr('data-uid')}']`).attr('data-path', new_path);
- $(`.window-${options.uid}`).attr('data-path', new_path);
-
- // Update all elements that have matching paths
- $(`[data-path="${html_encode(old_path)}" i]`).each(function(){
- $(this).attr('data-path', new_path)
- if($(this).hasClass('window-navbar-path-dirname'))
- $(this).text(new_name);
- });
-
- // Update the paths of all elements whose paths start with old_path
- $(`[data-path^="${html_encode(old_path) + '/'}"]`).each(function(){
- const new_el_path = _.replace($(this).attr('data-path'), old_path + '/', new_path+'/');
- $(this).attr('data-path', new_el_path);
- });
-
- // Update the 'Sites Cache'
- if($(el_item).attr('data-has_website') === '1')
- await update_sites_cache();
-
- // Update website_url
- website_url = determine_website_url(new_path);
- $(el_item).attr('data-website_url', website_url);
-
- // Update all exact-matching windows
- $(`.window-${options.uid}`).each(function(){
- update_window_path(this, options.path);
- })
-
- // Set new name for corresponding open windows
- $(`.window-${options.uid} .window-head-title`).text(new_name);
-
- // Re-sort all matching item containers
- $(`.item[data-uid='${$(el_item).attr('data-uid')}']`).parent('.item-container').each(function(){
- sort_items(this, $(el_item).closest('.item-container').attr('data-sort_by'), $(el_item).closest('.item-container').attr('data-sort_order'));
- })
- },
- error: function (err){
- // reset to old name
- $(el_item_name).text(truncate_filename(options.name, TRUNCATE_LENGTH));
- $(el_item_name).show();
-
- // hide item name editor
- $(el_item_name_editor).hide();
- $(el_item_name_editor).val(html_encode($(el_item).attr('data-name')));
-
- //show error
- if(err.message){
- UIAlert(err.message)
- }
- },
- });
+ rename_file(options, new_name, old_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url);
}
// --------------------------------------------------------
@@ -1066,7 +970,7 @@ function UIItem(options){
});
// -------------------------------------------
- // -- seperator --
+ // -- separator --
// -------------------------------------------
menu_items.push('-');
}
@@ -1085,7 +989,7 @@ function UIItem(options){
}
});
// -------------------------------------------
- // -- seperator --
+ // -- separator --
// -------------------------------------------
if(!is_trash && !is_trashed && options.is_dir)
menu_items.push('-');
@@ -1617,4 +1521,4 @@ window.activate_item_name_editor= function(el_item){
$(el_item_name_editor).select();
}
-export default UIItem;
\ No newline at end of file
+export default UIItem;
diff --git a/src/UI/UIWindow.js b/src/UI/UIWindow.js
index d3da06f1..3a90926f 100644
--- a/src/UI/UIWindow.js
+++ b/src/UI/UIWindow.js
@@ -1880,6 +1880,18 @@ async function UIWindow(options) {
}
},
// -------------------------------------------
+ // Show/Hide hidden files
+ // -------------------------------------------
+ {
+ html: `${window.user_preferences.show_hidden_files ? "Hide" : "Show"} hidden files`,
+ onClick: function(){
+ window.mutate_user_preferences({
+ show_hidden_files : !window.user_preferences.show_hidden_files,
+ });
+ window.show_or_hide_files(document.querySelectorAll('.item-container'));
+ }
+ },
+ // -------------------------------------------
// -
// -------------------------------------------
'-',
@@ -1905,6 +1917,16 @@ async function UIWindow(options) {
}
},
// -------------------------------------------
+ // Undo
+ // -------------------------------------------
+ {
+ html: "Undo",
+ disabled: actions_history.length > 0 ? false : true,
+ onClick: function(){
+ undo_last_action();
+ }
+ },
+ // -------------------------------------------
// Upload Here
// -------------------------------------------
{
diff --git a/src/css/style.css b/src/css/style.css
index 50367484..5dd97c1e 100644
--- a/src/css/style.css
+++ b/src/css/style.css
@@ -306,6 +306,18 @@ input[type=text]:focus, input[type=password]:focus, input[type=email]:focus, sel
pointer-events: none;
}
+.item-revealed {
+ opacity: 0.9;
+}
+
+.item-hidden {
+ display: none
+}
+
+.item-revealed.item-disabled {
+ opacity: 0.7
+}
+
.item-container-list .item {
height: initial;
width: max-content;
@@ -2117,16 +2129,16 @@ label {
.ui-tooltip, .arrow:after {
background-color: rgba(231, 238, 245, .92);
- backdrop-filter: blur(3px);
+ box-shadow: none;
}
.ui-tooltip {
- padding: 5px 10px;
+ padding: 7px 11px;
border-radius: 2px;
font: 14px "Helvetica Neue", Sans-Serif;
- box-shadow: 0 0 3px rgba(0, 0, 0, 0.455);
- background-color: rgba(231, 238, 245, .92);
+ border: none !important;
backdrop-filter: blur(3px);
+ filter: drop-shadow(0 0 3px rgba(0,0,0,.455));
}
.arrow {
diff --git a/src/globals.js b/src/globals.js
index 1a0e4c18..f5ff998a 100644
--- a/src/globals.js
+++ b/src/globals.js
@@ -19,6 +19,7 @@
window.clipboard_op = '';
window.clipboard = [];
+window.actions_history = [];
window.window_nav_history = {};
window.window_nav_history_current_position = {};
window.progress_tracker = [];
@@ -85,6 +86,19 @@ if(window.user !== undefined && window.user !== null){
}
window.root_dirname = 'Puter';
+// user preferences, persisted across sessions, cached in localStorage
+try {
+ window.user_preferences = JSON.parse(localStorage.getItem('user_preferences'))
+}catch(e){
+ window.user_preferences = null;
+}
+// default values
+if (window.user_preferences === null) {
+ window.user_preferences = {
+ show_hidden_files: false,
+ }
+}
+
window.window_stack = []
window.toolbar_height = 30;
window.default_taskbar_height = 50;
diff --git a/src/helpers.js b/src/helpers.js
index d2a40fce..a12fb405 100644
--- a/src/helpers.js
+++ b/src/helpers.js
@@ -656,7 +656,7 @@ window.refresh_user_data = async (auth_token)=>{
// update local user data
if(whoami){
update_auth_data(auth_token, whoami)
- }
+ }
}
window.update_auth_data = (auth_token, user)=>{
@@ -710,6 +710,20 @@ window.update_auth_data = (auth_token, user)=>{
}
}
+window.mutate_user_preferences = function(user_preferences_delta) {
+ for (const [key, value] of Object.entries(user_preferences_delta)) {
+ // Don't wait for set to be done for better efficiency
+ puter.kv.set(`user_preferences.${key}`, String(value));
+ }
+ // There may be syncing issues across multiple devices
+ update_user_preferences({ ...window.user_preferences, ...user_preferences_delta });
+}
+
+window.update_user_preferences = function(user_preferences) {
+ window.user_preferences = user_preferences;
+ localStorage.setItem('user_preferences', JSON.stringify(user_preferences));
+}
+
window.sendWindowWillCloseMsg = function(iframe_element) {
return new Promise(function(resolve){
const msg_id = uuidv4();
@@ -1255,11 +1269,18 @@ window.refresh_item_container = function(el_item_container, options){
if(!window.check_fsentry_against_allowed_file_types_string(fsentry, allowed_file_types))
is_disabled = true;
- // skip if hidden (i.e. name starts with `.`)
- if(fsentry.name.startsWith('.'))
- continue;
+ // set visibility based on user preferences and whether file is hidden by default
+ const is_hidden_file = fsentry.name.startsWith('.');
+ let visible;
+ if (!is_hidden_file){
+ visible = 'visible';
+ }else if (window.user_preferences.show_hidden_files) {
+ visible = 'revealed';
+ }else{
+ visible = 'hidden';
+ }
- //metadata
+ // metadata
let metadata;
if(fsentry.metadata !== ''){
try{
@@ -1295,6 +1316,7 @@ window.refresh_item_container = function(el_item_container, options){
modified: fsentry.modified,
suggested_apps: fsentry.suggested_apps,
disabled: is_disabled,
+ visible: visible,
});
}
}
@@ -1380,6 +1402,16 @@ window.sort_items = (item_container, sort_by, sort_order)=>{
}).appendTo(item_container);
}
+window.show_or_hide_files = (item_containers) => {
+ const show_hidden_files = window.user_preferences.show_hidden_files;
+ const class_to_add = show_hidden_files ? 'item-revealed' : 'item-hidden';
+ const class_to_remove = show_hidden_files ? 'item-hidden' : 'item-revealed';
+ $(item_containers)
+ .find('.item')
+ .filter((_, item) => item.dataset.name.startsWith('.'))
+ .removeClass(class_to_remove).addClass(class_to_add);
+}
+
window.create_folder = async(basedir, appendto_element)=>{
let dirname = basedir;
let folder_name = 'New Folder';
@@ -1402,9 +1434,15 @@ window.create_folder = async(basedir, appendto_element)=>{
overwrite: false,
success: function (data){
const el_created_dir = $(appendto_element).find('.item[data-path="'+html_encode(dirname)+'/'+html_encode(data.name)+'"]');
- if(el_created_dir.length > 0)
+ if(el_created_dir.length > 0){
activate_item_name_editor(el_created_dir);
+ // Add action to actions_history for undo ability
+ actions_history.push({
+ operation: 'create_folder',
+ data: el_created_dir
+ });
+ }
clearTimeout(progwin_timeout);
// done
@@ -1440,6 +1478,12 @@ window.create_file = async(options)=>{
const created_file = $(appendto_element).find('.item[data-path="'+html_encode(dirname)+'/'+html_encode(data.name)+'"]');
if(created_file.length > 0){
activate_item_name_editor(created_file);
+
+ // Add action to actions_history for undo ability
+ actions_history.push({
+ operation: 'create_file',
+ data: created_file
+ });
}
}
});
@@ -1476,7 +1520,15 @@ window.copy_clipboard_items = async function(dest_path, dest_container_element){
let overwrite_all = false;
(async()=>{
let copy_progress_window_init_ts = Date.now();
- let progwin = await UIWindowCopyProgress({operation_id: copy_op_id});
+
+ // only show progress window if it takes longer than 2s to copy
+ let progwin;
+ let progwin_timeout = setTimeout(async () => {
+ progwin = await UIWindowCopyProgress({operation_id: copy_op_id});
+ }, 2000);
+
+ const copied_item_paths = []
+
for(let i=0; i
= copy_progress_hide_delay){
+ if(progwin && copy_duration >= copy_progress_hide_delay){
$(progwin).close();
- }else{
+ }else if(progwin){
setTimeout(() => {
setTimeout(() => {
$(progwin).close();
@@ -1555,7 +1619,15 @@ window.copy_items = function(el_items, dest_path){
let overwrite_all = false;
(async()=>{
let copy_progress_window_init_ts = Date.now();
- let progwin = await UIWindowCopyProgress({operation_id: copy_op_id});
+
+ // only show progress window if it takes longer than 2s to copy
+ let progwin;
+ let progwin_timeout = setTimeout(async () => {
+ progwin = await UIWindowCopyProgress({operation_id: copy_op_id});
+ }, 2000);
+
+ const copied_item_paths = []
+
for(let i=0; i < el_items.length; i++){
let copy_path = $(el_items[i]).attr('data-path');
let item_with_same_name_already_exists = true;
@@ -1569,7 +1641,7 @@ window.copy_items = function(el_items, dest_path){
if(operation_cancelled[copy_op_id])
return;
try{
- await puter.fs.copy({
+ let resp = await puter.fs.copy({
source: copy_path,
destination: dest_path,
overwrite: overwrite || overwrite_all,
@@ -1577,6 +1649,9 @@ window.copy_items = function(el_items, dest_path){
dedupeName: dest_path === path.dirname(copy_path),
})
+ // copy new path for undo copy
+ copied_item_paths.push(resp[0].path);
+
// skips next loop iteration
item_with_same_name_already_exists = false;
}catch(err){
@@ -1612,10 +1687,18 @@ window.copy_items = function(el_items, dest_path){
}
// done
+ // Add action to actions_history for undo ability
+ actions_history.push({
+ operation: 'copy',
+ data: copied_item_paths
+ });
+
+ clearTimeout(progwin_timeout);
+
let copy_duration = (Date.now() - copy_progress_window_init_ts);
- if( copy_duration >= copy_progress_hide_delay){
+ if(progwin && copy_duration >= copy_progress_hide_delay){
$(progwin).close();
- }else{
+ }else if(progwin){
setTimeout(() => {
setTimeout(() => {
$(progwin).close();
@@ -2222,7 +2305,7 @@ window.new_context_menu_item = function(dirname, append_to_element){
* @param {string} dest_path - The destination path to move the items to
* @returns {Promise}
*/
-window.move_items = async function(el_items, dest_path){
+window.move_items = async function(el_items, dest_path, is_undo = false){
let move_op_id = operation_id++;
operation_cancelled[move_op_id] = false;
@@ -2250,8 +2333,14 @@ window.move_items = async function(el_items, dest_path){
// when did this operation start
let move_init_ts = Date.now();
- // create progress window
- let progwin = await UIWindowMoveProgress({operation_id: move_op_id});
+ // only show progress window if it takes longer than 2s to move
+ let progwin;
+ let progwin_timeout = setTimeout(async () => {
+ progwin = await UIWindowMoveProgress({operation_id: move_op_id});
+ }, 2000);
+
+ // storing moved items for undo ability
+ const moved_items = []
// Go through each item and try to move it
for(let i=0; i 1 ? 's':''} in ${move_duration}ms`);
@@ -2604,9 +2697,24 @@ window.move_items = async function(el_items, dest_path){
// -----------------------------------------------------------------------
// DONE! close progress window with delay to allow user to see 100% progress
// -----------------------------------------------------------------------
- setTimeout(() => {
- $(progwin).close();
- }, copy_progress_hide_delay);
+ // Add action to actions_history for undo ability
+ if(!is_undo && dest_path !== trash_path){
+ actions_history.push({
+ operation: 'move',
+ data: moved_items,
+ });
+ }else if(!is_undo && dest_path === trash_path){
+ actions_history.push({
+ operation: 'delete',
+ data: moved_items,
+ });
+ }
+
+ if(progwin){
+ setTimeout(() => {
+ $(progwin).close();
+ }, copy_progress_hide_delay);
+ }
}
/**
@@ -2836,6 +2944,11 @@ window.upload_items = async function(items, dest_path){
let upload_progress_window;
let opid;
+ if(dest_path == trash_path){
+ UIAlert('Uploading to trash is not allowed!');
+ return;
+ }
+
puter.fs.upload(
// what to upload
items,
@@ -2876,6 +2989,20 @@ window.upload_items = async function(items, dest_path){
// success
success: async function(items){
// DONE
+ // Add action to actions_history for undo ability
+ const files = []
+ if(typeof items[Symbol.iterator] === 'function'){
+ for(const item of items){
+ files.push(item.path)
+ }
+ }else{
+ files.push(items.path)
+ }
+
+ actions_history.push({
+ operation: 'upload',
+ data: files
+ });
// close progress window after a bit of delay for a better UX
setTimeout(() => {
setTimeout(() => {
@@ -3258,3 +3385,314 @@ window.unzipItem = async function(itemPath) {
}, Math.max(0, copy_progress_hide_delay - (Date.now() - start_ts)));
})
}
+
+window.rename_file = async(options, new_name, old_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url, is_undo = false)=>{
+ puter.fs.rename({
+ uid: options.uid === 'null' ? null : options.uid,
+ new_name: new_name,
+ excludeSocketID: window.socket.id,
+ success: async (fsentry)=>{
+ // Add action to actions_history for undo ability
+ if (!is_undo)
+ actions_history.push({
+ operation: 'rename',
+ data: {options, new_name, old_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url}
+ });
+
+ // Has the extension changed? in that case update options.sugggested_apps
+ const old_extension = path.extname(old_name);
+ const new_extension = path.extname(new_name);
+ if(old_extension !== new_extension){
+ suggest_apps_for_fsentry({
+ uid: options.uid,
+ onSuccess: function(suggested_apps){
+ options.suggested_apps = suggested_apps;
+ }
+ });
+ }
+
+ // Set new item name
+ $(`.item[data-uid='${$(el_item).attr('data-uid')}'] .item-name`).html(html_encode(truncate_filename(new_name, TRUNCATE_LENGTH)).replaceAll(' ', ' '));
+ $(el_item_name).show();
+
+ // Hide item name editor
+ $(el_item_name_editor).hide();
+
+ // Set new icon
+ const new_icon = (options.is_dir ? window.icons['folder.svg'] : (await item_icon(fsentry)).image);
+ $(el_item_icon).find('.item-icon-icon').attr('src', new_icon);
+
+ // Set new data-name
+ options.name = new_name;
+ $(el_item).attr('data-name', html_encode(new_name));
+ $(`.item[data-uid='${$(el_item).attr('data-uid')}']`).attr('data-name', html_encode(new_name));
+ $(`.window-${options.uid}`).attr('data-name', html_encode(new_name));
+
+ // Set new title attribute
+ $(`.item[data-uid='${$(el_item).attr('data-uid')}']`).attr('title', html_encode(new_name));
+ $(`.window-${options.uid}`).attr('title', html_encode(new_name));
+
+ // Set new value for item-name-editor
+ $(`.item[data-uid='${$(el_item).attr('data-uid')}'] .item-name-editor`).val(html_encode(new_name));
+ $(`.item[data-uid='${$(el_item).attr('data-uid')}'] .item-name`).attr('title', html_encode(new_name));
+
+ // Set new data-path
+ options.path = path.join( path.dirname(options.path), options.name);
+ const new_path = options.path;
+ $(el_item).attr('data-path', new_path);
+ $(`.item[data-uid='${$(el_item).attr('data-uid')}']`).attr('data-path', new_path);
+ $(`.window-${options.uid}`).attr('data-path', new_path);
+
+ // Update all elements that have matching paths
+ $(`[data-path="${html_encode(old_path)}" i]`).each(function(){
+ $(this).attr('data-path', new_path)
+ if($(this).hasClass('window-navbar-path-dirname'))
+ $(this).text(new_name);
+ });
+
+ // Update the paths of all elements whose paths start with old_path
+ $(`[data-path^="${html_encode(old_path) + '/'}"]`).each(function(){
+ const new_el_path = _.replace($(this).attr('data-path'), old_path + '/', new_path+'/');
+ $(this).attr('data-path', new_el_path);
+ });
+
+ // Update the 'Sites Cache'
+ if($(el_item).attr('data-has_website') === '1')
+ await update_sites_cache();
+
+ // Update website_url
+ website_url = determine_website_url(new_path);
+ $(el_item).attr('data-website_url', website_url);
+
+ // Update all exact-matching windows
+ $(`.window-${options.uid}`).each(function(){
+ update_window_path(this, options.path);
+ })
+
+ // Set new name for corresponding open windows
+ $(`.window-${options.uid} .window-head-title`).text(new_name);
+
+ // Re-sort all matching item containers
+ $(`.item[data-uid='${$(el_item).attr('data-uid')}']`).parent('.item-container').each(function(){
+ sort_items(this, $(el_item).closest('.item-container').attr('data-sort_by'), $(el_item).closest('.item-container').attr('data-sort_order'));
+ })
+ },
+ error: function (err){
+ // reset to old name
+ $(el_item_name).text(truncate_filename(options.name, TRUNCATE_LENGTH));
+ $(el_item_name).show();
+
+ // hide item name editor
+ $(el_item_name_editor).hide();
+ $(el_item_name_editor).val(html_encode($(el_item).attr('data-name')));
+
+ //show error
+ if(err.message){
+ UIAlert(err.message)
+ }
+ },
+ });
+}
+
+/**
+ * Deletes the given item with path.
+ *
+ * @param {string} path - path of the item to delete
+ * @returns {Promise}
+ */
+window.delete_item_with_path = async function(path){
+ try{
+ await puter.fs.delete({
+ paths: path,
+ descendantsOnly: false,
+ recursive: true,
+ });
+ }catch(err){
+ UIAlert(err.responseText);
+ }
+}
+
+window.undo_last_action = async()=>{
+ if (actions_history.length > 0) {
+ const last_action = actions_history.pop();
+
+ // Undo the create file action
+ if (last_action.operation === 'create_file' || last_action.operation === 'create_folder') {
+ const lastCreatedItem = last_action.data;
+ undo_create_file_or_folder(lastCreatedItem);
+ } else if(last_action.operation === 'rename') {
+ const {options, new_name, old_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url} = last_action.data;
+ rename_file(options, old_name, new_name, old_path, el_item, el_item_name, el_item_icon, el_item_name_editor, website_url, true);
+ } else if(last_action.operation === 'upload') {
+ const files = last_action.data;
+ undo_upload(files);
+ } else if(last_action.operation === 'copy') {
+ const files = last_action.data;
+ undo_copy(files);
+ } else if(last_action.operation === 'move') {
+ const items = last_action.data;
+ undo_move(items);
+ } else if(last_action.operation === 'delete') {
+ const items = last_action.data;
+ undo_delete(items);
+ }
+ }
+}
+
+window.undo_create_file_or_folder = async(item)=>{
+ await window.delete_item(item);
+}
+
+window.undo_upload = async(files)=>{
+ for (const file of files) {
+ await window.delete_item_with_path(file);
+ }
+}
+
+window.undo_copy = async(files)=>{
+ for (const file of files) {
+ await window.delete_item_with_path(file);
+ }
+}
+
+window.undo_move = async(items)=>{
+ for (const item of items) {
+ const el = await get_html_element_from_options(item.options);
+ console.log(item.original_path)
+ move_items([el], path.dirname(item.original_path), true);
+ }
+}
+
+window.undo_delete = async(items)=>{
+ for (const item of items) {
+ const el = await get_html_element_from_options(item.options);
+ let metadata = $(el).attr('data-metadata') === '' ? {} : JSON.parse($(el).attr('data-metadata'))
+ move_items([el], path.dirname(metadata.original_path), true);
+ }
+}
+
+
+window.get_html_element_from_options = async function(options){
+ const item_id = global_element_id++;
+
+ options.disabled = options.disabled ?? false;
+ options.visible = options.visible ?? 'visible'; // one of 'visible', 'revealed', 'hidden'
+ options.is_dir = options.is_dir ?? false;
+ options.is_selected = options.is_selected ?? false;
+ options.is_shared = options.is_shared ?? false;
+ options.is_shortcut = options.is_shortcut ?? 0;
+ options.is_trash = options.is_trash ?? false;
+ options.metadata = options.metadata ?? '';
+ options.multiselectable = options.multiselectable ?? true;
+ options.shortcut_to = options.shortcut_to ?? '';
+ options.shortcut_to_path = options.shortcut_to_path ?? '';
+ options.immutable = (options.immutable === false || options.immutable === 0 || options.immutable === undefined ? 0 : 1);
+ 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);
+
+ // 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')
+ if(!window.check_fsentry_against_allowed_file_types_string({is_dir: options.is_dir, name:options.name, type:options.type}, appendto_allowed_file_types))
+ options.disabled = true;
+
+ // --------------------------------------------------------
+ // HTML for Item
+ // --------------------------------------------------------
+ let h = '';
+ h += ``;
+
+ // spinner
+ h += `
`;
+ h += `
`;
+ // modified
+ h += `
`;
+ h += `${options.modified === 0 ? '-' : timeago.format(options.modified*1000)}`;
+ h += `
`;
+ // size
+ h += `
`;
+ h += `${options.size ? byte_format(options.size) : '-'}`;
+ h += `
`;
+ // type
+ h += `
`;
+ if(options.is_dir)
+ h += `Folder`;
+ else
+ h += `${options.type ? html_encode(options.type) : '-'}`;
+ h += `
`;
+
+
+ // icon
+ h += `
`;
+ h += `
`;
+ h += `
`;
+ // badges
+ h += `
`;
+ // website badge
+ h += `
`;
+ // link badge
+ h += `
`;
+
+ // shared badge
+ h += `
`;
+ // owner-shared badge
+ h += `
`;
+ // shortcut badge
+ h += `
`;
+
+ h += `
`;
+
+ // name
+ h += `
${html_encode(truncate_filename(options.name, TRUNCATE_LENGTH)).replaceAll(' ', ' ')}`
+ // name editor
+ h += `
`
+ h += `
`;
+
+ return h;
+}
\ No newline at end of file
diff --git a/src/initgui.js b/src/initgui.js
index 306e070f..097dd037 100644
--- a/src/initgui.js
+++ b/src/initgui.js
@@ -1677,6 +1677,14 @@ window.initgui = async function(){
}
return false;
}
+ //-----------------------------------------------------------------------------
+ // Undo
+ // ctrl/command + z, will undo last action
+ //-----------------------------------------------------------------------------
+ if((e.ctrlKey || e.metaKey) && e.which === 90){
+ undo_last_action();
+ return false;
+ }
});
$(document).on('click', '.remove-permission-link', async function(e){
diff --git a/src/lib/jquery-ui-1.12.1.custom/AUTHORS.txt b/src/lib/jquery-ui-1.12.1.custom/AUTHORS.txt
deleted file mode 100644
index a75056b9..00000000
--- a/src/lib/jquery-ui-1.12.1.custom/AUTHORS.txt
+++ /dev/null
@@ -1,333 +0,0 @@
-Authors ordered by first contribution
-A list of current team members is available at http://jqueryui.com/about
-
-Paul Bakaus
-Richard Worth
-Yehuda Katz
-Sean Catchpole
-John Resig
-Tane Piper
-Dmitri Gaskin
-Klaus Hartl
-Stefan Petre
-Gilles van den Hoven
-Micheil Bryan Smith
-Jörn Zaefferer
-Marc Grabanski
-Keith Wood
-Brandon Aaron
-Scott González
-Eduardo Lundgren
-Aaron Eisenberger
-Joan Piedra
-Bruno Basto
-Remy Sharp
-Bohdan Ganicky
-David Bolter
-Chi Cheng
-Ca-Phun Ung
-Ariel Flesler
-Maggie Wachs
-Scott Jehl
-Todd Parker
-Andrew Powell
-Brant Burnett
-Douglas Neiner
-Paul Irish
-Ralph Whitbeck
-Thibault Duplessis
-Dominique Vincent
-Jack Hsu
-Adam Sontag
-Carl Fürstenberg
-Kevin Dalman
-Alberto Fernández Capel
-Jacek Jędrzejewski (http://jacek.jedrzejewski.name)
-Ting Kuei
-Samuel Cormier-Iijima
-Jon Palmer
-Ben Hollis
-Justin MacCarthy
-Eyal Kobrigo
-Tiago Freire
-Diego Tres
-Holger Rüprich
-Ziling Zhao
-Mike Alsup
-Robson Braga Araujo
-Pierre-Henri Ausseil
-Christopher McCulloh
-Andrew Newcomb
-Lim Chee Aun
-Jorge Barreiro
-Daniel Steigerwald
-John Firebaugh
-John Enters
-Andrey Kapitcyn
-Dmitry Petrov
-Eric Hynds
-Chairat Sunthornwiphat
-Josh Varner
-Stéphane Raimbault
-Jay Merrifield
-J. Ryan Stinnett
-Peter Heiberg
-Alex Dovenmuehle
-Jamie Gegerson
-Raymond Schwartz
-Phillip Barnes
-Kyle Wilkinson
-Khaled AlHourani
-Marian Rudzynski
-Jean-Francois Remy
-Doug Blood
-Filippo Cavallarin
-Heiko Henning
-Aliaksandr Rahalevich
-Mario Visic
-Xavi Ramirez
-Max Schnur
-Saji Nediyanchath
-Corey Frang
-Aaron Peterson
-Ivan Peters
-Mohamed Cherif Bouchelaghem
-Marcos Sousa
-Michael DellaNoce
-George Marshall
-Tobias Brunner
-Martin Solli
-David Petersen
-Dan Heberden
-William Kevin Manire
-Gilmore Davidson
-Michael Wu
-Adam Parod
-Guillaume Gautreau
-Marcel Toele
-Dan Streetman
-Matt Hoskins
-Giovanni Giacobbi
-Kyle Florence
-Pavol Hluchý
-Hans Hillen
-Mark Johnson
-Trey Hunner
-Shane Whittet
-Edward A Faulkner
-Adam Baratz
-Kato Kazuyoshi
-Eike Send
-Kris Borchers
-Eddie Monge
-Israel Tsadok
-Carson McDonald
-Jason Davies
-Garrison Locke
-David Murdoch
-Benjamin Scott Boyle
-Jesse Baird
-Jonathan Vingiano
-Dylan Just
-Hiroshi Tomita
-Glenn Goodrich
-Tarafder Ashek-E-Elahi
-Ryan Neufeld
-Marc Neuwirth
-Philip Graham
-Benjamin Sterling
-Wesley Walser
-Kouhei Sutou
-Karl Kirch
-Chris Kelly
-Jason Oster
-Felix Nagel
-Alexander Polomoshnov
-David Leal
-Igor Milla
-Dave Methvin
-Florian Gutmann
-Marwan Al Jubeh
-Milan Broum
-Sebastian Sauer
-Gaëtan Muller
-Michel Weimerskirch
-William Griffiths
-Stojce Slavkovski
-David Soms
-David De Sloovere
-Michael P. Jung
-Shannon Pekary
-Dan Wellman
-Matthew Edward Hutton
-James Khoury
-Rob Loach
-Alberto Monteiro
-Alex Rhea
-Krzysztof Rosiński
-Ryan Olton
-Genie <386@mail.com>
-Rick Waldron
-Ian Simpson
-Lev Kitsis
-TJ VanToll
-Justin Domnitz
-Douglas Cerna
-Bert ter Heide
-Jasvir Nagra
-Yuriy Khabarov <13real008@gmail.com>
-Harri Kilpiö
-Lado Lomidze
-Amir E. Aharoni
-Simon Sattes
-Jo Liss
-Guntupalli Karunakar
-Shahyar Ghobadpour
-Lukasz Lipinski
-Timo Tijhof
-Jason Moon
-Martin Frost
-Eneko Illarramendi
-EungJun Yi
-Courtland Allen
-Viktar Varvanovich
-Danny Trunk
-Pavel Stetina
-Michael Stay
-Steven Roussey
-Michael Hollis
-Lee Rowlands
-Timmy Willison
-Karl Swedberg
-Baoju Yuan
-Maciej Mroziński
-Luis Dalmolin
-Mark Aaron Shirley
-Martin Hoch
-Jiayi Yang
-Philipp Benjamin Köppchen
-Sindre Sorhus
-Bernhard Sirlinger
-Jared A. Scheel
-Rafael Xavier de Souza
-John Chen
-Robert Beuligmann
-Dale Kocian
-Mike Sherov
-Andrew Couch
-Marc-Andre Lafortune
-Nate Eagle
-David Souther
-Mathias Stenbom
-Sergey Kartashov
-Avinash R
-Ethan Romba
-Cory Gackenheimer
-Juan Pablo Kaniefsky
-Roman Salnikov
-Anika Henke
-Samuel Bovée
-Fabrício Matté
-Viktor Kojouharov
-Pawel Maruszczyk (http://hrabstwo.net)
-Pavel Selitskas
-Bjørn Johansen
-Matthieu Penant
-Dominic Barnes
-David Sullivan
-Thomas Jaggi
-Vahid Sohrabloo
-Travis Carden
-Bruno M. Custódio
-Nathanael Silverman
-Christian Wenz
-Steve Urmston
-Zaven Muradyan
-Woody Gilk
-Zbigniew Motyka
-Suhail Alkowaileet
-Toshi MARUYAMA
-David Hansen
-Brian Grinstead
-Christian Klammer
-Steven Luscher
-Gan Eng Chin
-Gabriel Schulhof
-Alexander Schmitz