Simple uTools new folder plugin development

Original link: https://fugary.com/?p=389

Introduction to uTools

The official website is as follows:

uTools = your tools (your toolset)

uTools is a minimalist, plug-in modern desktop software, which can create a handy tool collection by freely selecting a rich set of plug-ins.

This search box can be quickly called out by the shortcut key (default alt + space ). You can paste text, pictures, screenshots, files, folders, etc. into the input box. Plugins that can handle this content are already ready. The unified design style and operation method help you get results efficiently.

Official website address: https://u.tools/

uTools plugin development

uTools supports the use of javascript to develop plug-ins, itself is based on electron development, and uses the combination of nodejs and web pages to achieve the effect of desktop applications

Development documentation address: https://u.tools/docs/developer/welcome.html#plugin-json

Create a new plugin project

Plugin requires files

  1. plugin.json
  2. logo.png
  3. index.html (if the plugin needs to use the UI interface)
  4. preload.js (if you need to access nodejs , etc., this file needs to be transferred)

Write plugin.json

Recently, when I managed files on the Windows10 system, I found that the Windows10 system did not select some files or folders and then create a new folder and move the selected files into this function. It seems that I can only create a new folder and then manually move it into it.

Just learning to develop uTools plug-in, write a plug-in to achieve this small function.

plugin.json write

 { "main": "index.html", "logo": "logo.png", "preload": "preload.js", "features": [ { "code": "新建文件夹", "explain": "选中文件或文件夹并自动移动或复制到一个新建文件夹中,也可以指定已经存在的文件夹", "cmds": [ "新建文件夹", "New Folder", "新建目录", "New Directory", { "type": "files", "label": "新建文件夹", "fileType": "file, directory", "minLength": 1 } ] } ] }

features following is the configuration function, currently there is a new folder function.

The following cmds are more important and are used to enter some commands in uTools to invoke the plugin.

There is this paragraph that can be triggered through the super panel of uTools . After selecting a file or folder, use the configured shortcut key (I configured the middle mouse button) to trigger:

 { "type": "files", "label": "新建文件夹", "fileType": "file, directory", "minLength": 1 }

image-20220730153516198

write preload.js

preload.js can use some functions of electron , but uTools seems to block a lot of API , but the basic API of nodejs are supported. This preload.js is supported by the electron environment, and some nodejs -related operations are exposed through this preload.js . , you can access nodejs functions on web pages, and only in this way can you access local files, etc.

 const fs = require('fs'); const path = require('path'); const electron = require('electron') window.electron = electron; window.moveOrCopyFile = function (files, dir, copy) { // 如果不是绝对路径,根据文件转换成绝对路径dir = dir.trim(); if (!path.isAbsolute(dir)) { dir = path.join(path.resolve(files[0].path, '..'), dir); } files.forEach(file => { if (file.isDirectory) { const subFileNames = fs.readdirSync(file.path); const subFiles = subFileNames.map(subFileName => { const subPath = path.join(file.path, subFileName); const stat = fs.statSync(subPath); return { name: subFileName, path: subPath, isDirectory: stat.isDirectory(), isFile: stat.isFile() } }) this.moveOrCopyFile(subFiles, path.join(dir, file.name), copy); } else { if (copy) { this.customCopyFile(file.path, path.join(dir, file.name)); } else { this.customMoveFile(file.path, path.join(dir, file.name)); } } }); } window.customMoveFile = function (fromPath, toPath) { fs.mkdirSync(path.resolve(toPath, '..'), { recursive: true }); try { fs.renameSync(fromPath, toPath); } catch (e) { utools.showNotification('不支持跨盘移动文件,请使用复制方式'); throw e; } } window.customCopyFile = function (fromPath, toPath) { fs.mkdirSync(path.resolve(toPath, '..'), { recursive: true }); fs.copyFileSync(fromPath, toPath); } window.checkDragFile = function (file) { const stat = fs.statSync(file.path); file.isDirectory = stat.isDirectory(); file.isFile = stat.isFile(); }

Writing Pages and Responses

The Web interface is developed using vuejs3 and bootstrap styles.

Full code GitHub address: https://github.com/fugary/utools-file-to-folder

After the development is completed, it needs to be tested in uTools .

Use of plugins in uTools

First install the developer tool of uTools , which is also a plug-in of uTools , which is needed for later development, testing, packaging, and publishing.

New plugin

After installing the [ uTools Developer Tools], you can create a new plug-in.

image-20220730154108952

After creating a new plugin, you can select plugin.json in the locally developed project directory, so that it is associated.

image-20220730154234204

It is recommended to tick the [Hidden background is completely exit] for local testing. It is more convenient to modify the hidden interface and it will automatically take effect without re-running.

After clicking [Start Run], it is equivalent to installing the plug-in.

running result

After starting the operation, you can see the actual effect. I locally configured the middle mouse button to trigger the super panel.

image-20220730154617535

In Windows Explorer, select some files, use the middle mouse button to trigger the super panel, select [New Folder], a pop-up interface, enter the folder name, click Move to a new folder (or copy to a new folder), Function complete.

image-20220730154722043

Packaging plugins

On the uTools developer tools page, click Package to package it into a UPX file.

image-20220730155007257

Publish plugin

Under uTools developer tools, click Publish, you need to fill in some audit information, and you need some screenshots.

Selected files or folders are automatically moved or copied to a new folder, or an existing folder can be specified

Click Submit for review and wait for the review. I don’t know if such a simple plugin can be reviewed.

image-20220730155910569

Development is complete.

Plug-in download and installation

Because the review has no results, it can be downloaded and used on GitHub:

GitHub download address: https://github.com/fugary/utools-file-to-folder/releases

Download the latest UPX file

After downloading, drag it into the uTools software

image-20220730163148210

Because there is no official review, it can only be installed manually, and some security issues will be prompted.

This article is reprinted from: https://fugary.com/?p=389
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment

Your email address will not be published.