Skip to content

Commit

Permalink
release 1.0.3
Browse files Browse the repository at this point in the history
feat:增加将app添加到UTools搜索列表中的功能
feat:增加图标横排功能
feat:增加刷新数据功能
fix:修复在Windows下分类错误的问题
fix:适配夜间模式
deps:调整element plus为按需引入,降低插件大小
  • Loading branch information
AnkioTomas authored Dec 23, 2022
2 parents d5f70bf + 1eb9b1e commit 597ce82
Show file tree
Hide file tree
Showing 12 changed files with 1,479 additions and 932 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"@vitejs/plugin-vue": "^3.1.0",
"electron": "^21.0.1",
"utools-api-types": "^3.0.0",
"unplugin-auto-import": "^0.12.1",
"unplugin-vue-components": "^0.22.12",
"vite": "^3.1.0"
}
}
2 changes: 1 addition & 1 deletion public/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"code": "quickstart",
"explain": "极速启动",
"cmds": ["极速启动","quick","q"],
"cmds": ["极速启动","quick","q","js"],
"icon": "logo.png"
},
{
Expand Down
98 changes: 71 additions & 27 deletions public/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,42 @@ const path=require('path');
const os = require("os");
const {shell} = require("electron");
const {exec} = require("child_process");
var travel = function (dir,depth,callback){
if(depth>1)return;//大于二级目录不处理
fs.readdirSync(dir).forEach((file)=>{
if(file.startsWith("."))return;
const travel = function (dir, depth, callback) {
if (depth > 1) return;//大于二级目录不处理
fs.readdirSync(dir).forEach((file) => {
if (file.startsWith(".")) return;
let pathname = path.join(dir, file);
const category = dir.substring(dir.lastIndexOf("/") + 1);
const split = utools.isWindows()?'\\':"/";
const category = dir.substring(dir.lastIndexOf(split) + 1);
const name = utils.replaceSuffix(file);
const stats = fs.lstatSync(pathname);
if(stats.isDirectory()&& !pathname.endsWith(".app")){
travel(pathname,depth+1,callback)
}else{
const images = ['png', 'jpg', 'jpeg', 'bmp', 'ico', 'gif', 'svg'];
if (stats.isDirectory() && !pathname.endsWith(".app")) {
travel(pathname, depth + 1, callback)
} else {
const images = ['png', 'jpg', 'jpeg', 'bmp', 'ico', 'gif', 'svg'];
for (let i = 0; i < images.length; i++) {
if(file.endsWith("."+images[i])){
if (file.endsWith("." + images[i])) {
return//图片就不处理
}
}
if(os.type() === "Darwin"){
if (os.type() === "Darwin") {
//判断mac替身
if(!stats.isDirectory()&&utils.isMacLink(pathname)){pathname = utils.getMacLink(pathname);}
}else if(os.type() === "Windows_NT"){
if(utils.isWindowsLink(pathname))pathname = utils.getWindowsLink(pathname);
}else{
if(utils.isLinuxLink(pathname))pathname = utils.getLinuxLink(pathname);
if (!stats.isDirectory() && utils.isMacLink(pathname)) {
pathname = utils.getMacLink(pathname);
}
} else if (os.type() === "Windows_NT") {
if (utils.isWindowsLink(pathname)) pathname = utils.getWindowsLink(pathname);
} else {
if (utils.isLinuxLink(pathname)) pathname = utils.getLinuxLink(pathname);
}
if(stats.isSymbolicLink()){
if (stats.isSymbolicLink()) {
pathname = fs.readlinkSync(pathname);
}
callback(category,name,pathname)
callback(category, name, pathname)
}
})
}

window.transferDirs = function (dir){
};
const transferDirs = function (dir){
var list = {};
travel(dir,0,function (category,name,link) {
let data = ['png', 'jpg', 'jpeg', 'bmp', 'ico', 'gif', 'svg'];
Expand All @@ -62,14 +64,58 @@ window.transferDirs = function (dir){
list[category] = [];
}
list[category].push(json);
//console.log(list)
});
return list;
}
window.selectDir=function () {
const result = utools.showOpenDialog({
filters: [],
properties: ['openDirectory']
})
if(result===undefined)return null;
return result[0];
}
window.addApps=function (path){
//删除存储的数据
const quickList = utools.db.get("quick_list");
if(quickList!==null){
const json = JSON.parse(quickList.data);
for (const jsonKey in json) {
for (const jsonKeyElement of json[jsonKey]) {
utools.db.remove(jsonKeyElement.link);
utools.removeFeature("quick_link:"+jsonKeyElement.link);
}
}
}
utools.db.remove("quick_list")
const quick_list = transferDirs(path)
utools.db.put({
//存储的时候自动排序
_id:"quick_list",data:JSON.stringify(quick_list)
});
let global_setting = {style:"",location:"left",dir:"",icon:"icon",utools:true};
const setting = utools.db.get("setting");
if(setting!==null)
global_setting = JSON.parse(setting.data);
if(global_setting.utools){
for (const sortName in quick_list) {
for (const listItem of quick_list[sortName]) {
utools.setFeature({
code: "quick_link:"+listItem.link,
explain: sortName,
platform:['darwin' , 'win32' , 'linux'],
icon: utools.db.get(listItem.link).data,
cmds: [listItem.name]
});
}}
}




}
window.openLink=function (link) {
window.utools.hideMainWindow()
utools.shellOpenPath(link)
window.utools.outPlugin()
}
var utils = {
isMacLink(path) {
let read;
Expand Down Expand Up @@ -193,5 +239,3 @@ var utils = {


}


36 changes: 27 additions & 9 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup>
import MainPage from './components/MainPage.vue'
import EmptyPage from './components/EmptyPage.vue'
import {ref} from "vue";
import SearchPage from "./components/SearchPage.vue";
import SettingPage from "./components/SettingPage.vue";
import {ElMessage} from "element-plus";
import 'element-plus/es/components/message/style/css'
let index = ref(0)
function setIndex(i) {
Expand All @@ -13,10 +13,9 @@ function setIndex(i) {
let textData = ref("");
utools.onPluginEnter(({code, type, payload, optional}) => {
console.log('用户进入插件应用', code, type, payload,optional)
if(code==="quicksearch"){
if(code.startsWith("quick_link:")){
openLink(code.replace("quick_link:",""));
}else if(code==="quicksearch"){
setIndex(2);
}else if(code==="quicksetting"){
setIndex(3);
Expand All @@ -27,16 +26,35 @@ utools.onPluginEnter(({code, type, payload, optional}) => {
utools.removeSubInput();
utools.setSubInput(({ text }) => {
textData.value = text;
if(index.value!==2)setIndex(2)
}, '请输入搜索内容进行检索')
if(text === "~"){
setIndex(3);
return;
}
if(text === "!"||text === ""){
let d = utools.db.get("setting")
if(d!==null){
ElMessage('正在刷新数据')
addApps(JSON.parse(d.data).dir);
setIndex(0);
ElMessage({
message: '数据刷新成功',
type: 'success',
});
return;
}
}
if(index.value!==2)setIndex(2);
}, '输入"~"进入设置。输入"!"刷新数据。输入其他内容进行搜索。')
})
</script>

<template>
<MainPage v-if="index===0" @setIndex="setIndex" />
<EmptyPage v-else-if="index===1" @setIndex="setIndex" />
<SearchPage v-else-if="index===2" @setIndex="setIndex" :text="textData"/>
<SettingPage v-else-if="index===3" @setIndex="setIndex"/>
</template>
Expand Down
56 changes: 0 additions & 56 deletions src/components/EmptyPage.vue

This file was deleted.

51 changes: 47 additions & 4 deletions src/components/Icon.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="icon-main" @click="click">
<div :class="icon_cls" @click="click">
<img :src="icon" alt="" />
<span>{{name}}</span>
</div>
Expand All @@ -9,11 +9,12 @@
const props = defineProps({
link:String,
name:String
name:String,
icon_item:String
});
let icon = utools.db.get(props.link).data;
let icon_cls = "icon-main "+props.icon_item;
function click() {
utools.shellOpenPath(props.link)
}
Expand All @@ -30,6 +31,16 @@ function click() {
cursor: pointer;
position: relative;
}
.icon-main.list{
height: 50px;
padding: 16px;
display: block;
cursor: pointer;
position: relative;
width: calc(100% - 50px);
text-align: left;
}
.icon-main>img{
width: 50px;
height: 50px;
Expand All @@ -52,9 +63,41 @@ function click() {
white-space: nowrap;
width: 50px;
display: block;
}
.icon-main.list > span{
display: inline-block;
font-size: 22px;
vertical-align:middle;
width: calc(100% - 100px);
text-align: left;
}
.icon-main.list > img{
margin-right: 20px;
}
.icon-main.list{
border-radius: 8px;
}
.icon-main.list:nth-child(odd){
background: #fcfcfc;
}
.icon-main.list:nth-child(even){
}
.icon-main:hover {
border-radius: 8px;
background-color: #f5f5f5
background-color: #f5f5f5!important;
}
@media (prefers-color-scheme: dark) {
.icon-main.list > span{
color: #d7d7d7!important;
}
.icon-main.list:nth-child(odd){
background: #222;
}
.icon-main:hover {
background-color: #444!important;
}
}
</style>
Loading

0 comments on commit 597ce82

Please sign in to comment.