Skip to content

Commit

Permalink
feat(#747): remove new file menu options (#85)
Browse files Browse the repository at this point in the history
- add: remove/restore menu options according to navigation to swarm storage

Co-authored-by: Take one <rontrevor@hotmail.com>
  • Loading branch information
retrevor and Take one authored Nov 20, 2024
1 parent 1f2eb02 commit bf8b476
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function boot(IBootContext $context): void {
});
$dispatcher->addListener(LoadAdditionalScriptsEvent::class, function () {
Util::addScript(AppConstants::APP_NAME, 'nextcloud-swarm-plugin-fileactions');
Util::addInitScript(AppConstants::APP_NAME, 'nextcloud-swarm-plugin-newfilemenu');
});

$this->getAuthMechanisms();
Expand Down
2 changes: 1 addition & 1 deletion lib/Sabre/PropfindPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function propFind(PropFind $propFind, INode $node) {
$filename = $node->getFileInfo()->getinternalPath();
$mountpoint = $node->getFileInfo()->getMountPoint()->getStorageId();

if (!str_starts_with($mountpoint, "ethswarm") || $filename === "") {
if (!str_starts_with($mountpoint, "ethswarm")) {
return "";
}
$class = $this->EthswarmService;
Expand Down
83 changes: 83 additions & 0 deletions src/newfilemenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* @copyright Copyright (c) 2024, MetaProvide Holding EKF
*
* @author Ron Trevor <ecoron@proton.me> @author
*
* @license GNU AGPL version 3 or any later version
*
* This program 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 <http://www.gnu.org/licenses/>.
*
*/
import { subscribe } from '@nextcloud/event-bus';
import { getNewFileMenuEntries, removeNewFileMenuEntry, registerDavProperty } from '@nextcloud/files';

registerDavProperty("nc:ethswarm-node");

// //////////////////////////////////////////////////
// Common functions for manipulating New file menu entries.
let previousPathIsSwarm = false;
let originalMenu = [];
const removalMenuEntries = [];
console.log('Hejbit-files-new-menu:previousPathIsSwarm=' + previousPathIsSwarm + ";originalMenu=" + originalMenu.length);

/** Store the Swarm-specific menu entries */
function storeNewFileMenu() {
if (!originalMenu || !originalMenu.length) {
originalMenu = getNewFileMenuEntries();
console.log("Load getNewFileMenuEntries()=" + originalMenu.length);
}
// Store the Swarm-specfic file menu entries
if (!removalMenuEntries || !removalMenuEntries.length) {
originalMenu.forEach(function remove(fileMenuEntry) {
if (fileMenuEntry.id !== 'newFolder') {
removalMenuEntries.push(fileMenuEntry);
}
});
}
};
// //////////////////////////////////////////////////

// Listeners to detect changes in listing.
subscribe('files:list:updated', (data) => {
if (typeof(data.folder) === 'undefined') {
// Not a valid response so ignore.
return;
}

let currentPathIsSwarm = false;
if (data.folder?.attributes["ethswarm-node"]){
currentPathIsSwarm = true;
}

console.log('Hejbit-files-new-menu:list:updated=previousPathIsSwarm=' + previousPathIsSwarm + ";currentPathIsSwarm=" + currentPathIsSwarm + ";originalMenu=" + originalMenu.length);
// First condition checks for 1st navigation in Swarm storage
// 2nd condition is for direct navigation by URL
if ((currentPathIsSwarm && !previousPathIsSwarm) || (currentPathIsSwarm && previousPathIsSwarm)) {
// Remove unwanted entries
storeNewFileMenu();
console.log('Removing ' + removalMenuEntries.length + ' menu entries from ' + originalMenu.length + ' menus.');
removalMenuEntries.forEach(function (removeMenuEntry) {
removeNewFileMenuEntry(removeMenuEntry);
});
} else if (!currentPathIsSwarm && !previousPathIsSwarm) {
console.log("Default entry - store settings");
// Store a copy of the current file menu entries
storeNewFileMenu();
}
else {
originalMenu = getNewFileMenuEntries();
console.log("Reload originalMenu=" + originalMenu.length);
}
previousPathIsSwarm = currentPathIsSwarm;
});
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ const path = require('path');
const webpackConfig = require('@nextcloud/webpack-vue-config')

webpackConfig.entry['fileactions'] = path.join(__dirname, 'src', 'fileactions.js');

webpackConfig.entry['newfilemenu'] = path.join(__dirname, 'src', 'newfilemenu.js');
module.exports = webpackConfig

0 comments on commit bf8b476

Please sign in to comment.