Compare commits
123 Commits
v0.0.2-bet
...
v0.0.7-bet
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a535c5d89b | ||
|
|
1eeb0fad9a | ||
|
|
511b357e28 | ||
|
|
87e7501c0a | ||
|
|
9242f17cde | ||
|
|
d047119076 | ||
|
|
5118fa6ca4 | ||
|
|
424c40a99c | ||
|
|
651e202ab1 | ||
|
|
614d5ae369 | ||
|
|
f287d10ca9 | ||
|
|
a04efd0d4f | ||
|
|
153d9dc5d7 | ||
|
|
de138955b5 | ||
|
|
8d340cb76c | ||
|
|
579b283a55 | ||
|
|
3858f35559 | ||
|
|
57504ab1eb | ||
|
|
0991d0ad64 | ||
|
|
e71eed00ad | ||
|
|
be5bce68dc | ||
|
|
871beba4bf | ||
|
|
f0b757c01f | ||
|
|
f480508200 | ||
|
|
247c2b7ab9 | ||
|
|
a489a8f130 | ||
|
|
d38dcab9cc | ||
|
|
64541ad651 | ||
|
|
5b1cef93c8 | ||
|
|
8dd59720e0 | ||
|
|
ee2a23a421 | ||
|
|
7dd5407bbe | ||
|
|
b58c37842a | ||
|
|
2d2743cbb1 | ||
|
|
efccc2b091 | ||
|
|
c6c57b1e01 | ||
|
|
a8c1db6ed3 | ||
|
|
4e55f14a69 | ||
|
|
7ea778b2bf | ||
|
|
7b1242885a | ||
|
|
c149694fed | ||
|
|
5eb72ed2ce | ||
|
|
ef7c829af7 | ||
|
|
1b980f9fda | ||
|
|
f6ef83bcd9 | ||
|
|
629e4b85c1 | ||
|
|
39422860d7 | ||
|
|
ea78658bfd | ||
|
|
69e4f2a8a4 | ||
|
|
5f09d526d9 | ||
|
|
c148bd6957 | ||
|
|
e0fafe0e8d | ||
|
|
11d1840ef1 | ||
|
|
ccb0b9fda7 | ||
|
|
fcd7097d4c | ||
|
|
ab4878188b | ||
|
|
9a15cffe8f | ||
|
|
749dc572f4 | ||
|
|
d7022f4ca2 | ||
|
|
b18393273a | ||
|
|
be2fb73c7e | ||
|
|
a23231f74e | ||
|
|
f186318845 | ||
|
|
c4f66ee98c | ||
|
|
b900ec2032 | ||
|
|
435ecc6121 | ||
|
|
888cff4cda | ||
|
|
0f73d94617 | ||
|
|
be846e2aac | ||
|
|
25957c485e | ||
|
|
eb71abad80 | ||
|
|
78f54ef02b | ||
|
|
bea58a301e | ||
|
|
9c4ef7e442 | ||
|
|
bc6303f9bc | ||
|
|
84423b5ae2 | ||
|
|
1f1ce0d18e | ||
|
|
eed9aac2c6 | ||
|
|
1812ee50c3 | ||
|
|
fd6db29691 | ||
|
|
25c989c029 | ||
|
|
00c349599e | ||
|
|
c2f5ac2b9a | ||
|
|
4e0ca27dd3 | ||
|
|
eacae4774d | ||
|
|
ad21d3743f | ||
|
|
3a70af5c49 | ||
|
|
dba0eb35a7 | ||
|
|
450c585eb1 | ||
|
|
ffb6ac96dc | ||
|
|
12962a737b | ||
|
|
79eef6ca85 | ||
|
|
e86290344b | ||
|
|
8a3e647490 | ||
|
|
01480d9188 | ||
|
|
4f4bfc8f6b | ||
|
|
b097b0a359 | ||
|
|
7f619e9d9b | ||
|
|
c29a5ff9f2 | ||
|
|
6da3a3a72c | ||
|
|
bf6e95e370 | ||
|
|
3588c929bf | ||
|
|
f6ee9f9296 | ||
|
|
cb21bfe34c | ||
|
|
f4b96ff447 | ||
|
|
8374b2b5a2 | ||
|
|
a35a5ccfc3 | ||
|
|
77180f65c5 | ||
|
|
9468aa8aa9 | ||
|
|
61859eea17 | ||
|
|
1176a0c9b2 | ||
|
|
a65acbaeb3 | ||
|
|
4b9602636b | ||
|
|
dade771985 | ||
|
|
792dc2a1d4 | ||
|
|
f0b9cb2f5d | ||
|
|
4c5b1033d5 | ||
|
|
151db0d418 | ||
|
|
a08276cc58 | ||
|
|
f1e815f522 | ||
|
|
4ed993fe68 | ||
|
|
6f0a463a0d | ||
|
|
d00ada6e02 |
4
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: #muwoo
|
||||
custom: ['https://muwoo.github.io/blogs'] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
71
.github/workflows/main.yml
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
# main.yml
|
||||
|
||||
# Workflow's name
|
||||
name: Build
|
||||
|
||||
# Workflow's trigger
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
# Workflow's jobs
|
||||
jobs:
|
||||
# job's id
|
||||
release:
|
||||
# job's name
|
||||
name: build and release electron app
|
||||
|
||||
# the type of machine to run the job on
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
# create a build matrix for jobs
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-2019]
|
||||
|
||||
# create steps
|
||||
steps:
|
||||
# step1: check out repository
|
||||
- name: Check out git repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# step2: install node env
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
|
||||
- name: Install system deps
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
run: |
|
||||
sudo apt-get install libxtst-dev libpng++-dev
|
||||
sudo apt-get install --no-install-recommends -y icnsutils graphicsmagick xz-utils
|
||||
# step3: yarn
|
||||
- name: macos Yarn install
|
||||
if: ${{runner.os == 'macOS'}}
|
||||
run: |
|
||||
yarn
|
||||
yarn global add xvfb-maybe
|
||||
npm run rebuild
|
||||
|
||||
- name: windows Yarn install
|
||||
if: ${{runner.os == 'Windows'}}
|
||||
run: |
|
||||
yarn
|
||||
yarn global add xvfb-maybe
|
||||
npm run rebuild_win
|
||||
|
||||
- name: linux Yarn install
|
||||
if: ${{runner.os == 'Linux'}}
|
||||
run: |
|
||||
yarn
|
||||
yarn global add xvfb-maybe
|
||||
npm run rebuild_linux
|
||||
|
||||
- name: Build & release app
|
||||
run: |
|
||||
npm run release
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
4
.gitignore
vendored
@@ -1,8 +1,8 @@
|
||||
.DS_Store
|
||||
dist/electron/*
|
||||
dist/web/*
|
||||
build/
|
||||
!build/icons
|
||||
build/*
|
||||
!build/icons/
|
||||
node_modules/
|
||||
npm-debug.log
|
||||
npm-debug.log.*
|
||||
|
||||
5
.pnpm-debug.log
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"0 debug pnpm:scope": {
|
||||
"selected": 1
|
||||
}
|
||||
}
|
||||
44
.travis.yml
@@ -1,36 +1,40 @@
|
||||
# Commented sections below can be used to run tests on the CI server
|
||||
# https://simulatedgreg.gitbooks.io/electron-vue/content/en/testing.html#on-the-subject-of-ci-testing
|
||||
osx_image: xcode8.3
|
||||
sudo: required
|
||||
dist: trusty
|
||||
language: c
|
||||
matrix:
|
||||
include:
|
||||
- os: osx
|
||||
- os: linux
|
||||
env: CC=clang CXX=clang++ npm_config_clang=1
|
||||
compiler: clang
|
||||
- os: osx
|
||||
# - os: linux
|
||||
env: CC=clang CXX=clang++ npm_config_clang=1
|
||||
compiler: clang
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
- "$HOME/.electron"
|
||||
- "$HOME/.cache"
|
||||
- node_modules
|
||||
- "$HOME/.electron"
|
||||
- "$HOME/.cache"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- libgnome-keyring-dev
|
||||
- icnsutils
|
||||
- libgnome-keyring-dev
|
||||
- icnsutils
|
||||
before_install:
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install git-lfs; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install --no-install-recommends -y icnsutils graphicsmagick xz-utils; fi
|
||||
- mkdir -p /tmp/git-lfs && curl -L https://github.com/github/git-lfs/releases/download/v1.2.1/git-lfs-$([
|
||||
"$TRAVIS_OS_NAME" == "linux" ] && echo "linux" || echo "darwin")-amd64-1.2.1.tar.gz
|
||||
| tar -xz -C /tmp/git-lfs --strip-components 1 && /tmp/git-lfs/git-lfs pull
|
||||
install:
|
||||
- nvm install 10
|
||||
- curl -o- -L https://yarnpkg.com/install.sh | bash
|
||||
- source ~/.bashrc
|
||||
- npm install -g xvfb-maybe
|
||||
- yarn
|
||||
before_script:
|
||||
- git lfs pull
|
||||
- nvm install 8.9
|
||||
- curl -o- -L https://yarnpkg.com/install.sh | bash
|
||||
- source ~/.bashrc
|
||||
- npm install -g xvfb-maybe
|
||||
- yarn
|
||||
- cd docs
|
||||
- yarn
|
||||
script:
|
||||
- yarn run build
|
||||
- npm run release
|
||||
- sh deploy.sh
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- master
|
||||
|
||||
65
README.md
@@ -1,55 +1,65 @@
|
||||
<div align= "center">
|
||||
<img align="center" src="https://user-images.githubusercontent.com/21073039/123022701-c3848180-d408-11eb-86ec-7727f355ea96.png" />
|
||||
<img align="center" width=200 src="https://user-images.githubusercontent.com/21073039/128333805-73e086f0-5523-46a3-a096-cba80b904c46.png" />
|
||||
</div>
|
||||
|
||||
# Rubick
|
||||
|
||||
<p>
|
||||
<a href="https://github.com/clouDr-f2e/rubick/releases/tag/v0.0.1-beta">
|
||||
<img alt="release" src="https://img.shields.io/badge/release-v0.0.1-brightgreen" />
|
||||
<div align= "center">
|
||||
<h1>Rubick</h1>
|
||||
|
||||
<img alt="release" src="https://img.shields.io/github/downloads/clouDr-f2e/rubick/total" />
|
||||
<a href="https://github.com/clouDr-f2e/rubick/releases">
|
||||
<img alt="release" src="https://img.shields.io/github/package-json/v/clouDr-f2e/rubick" />
|
||||
</a>
|
||||
<a href="https://github.com/clouDr-f2e/rubick/actions">
|
||||
<img alt=building src=https://img.shields.io/github/workflow/status/clouDr-f2e/rubick/Build>
|
||||
</a>
|
||||
<a href="https://github.com/clouDr-f2e/rubick/blob/master/LICENSE">
|
||||
<img alt="npm" src="https://img.shields.io/github/license/clouDr-f2e/rubick" />
|
||||
</a>
|
||||
</p>
|
||||
<img alt="star" src="https://img.shields.io/github/stars/clouDr-f2e/rubick?style=social"></a>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
基于 electron 的工具箱,媲美 utools的开源插件,已实现 utools 大部分的 API 能力,所以可以做到无缝适配 utools 开源的插件。
|
||||
之所以做这个工具箱一方面是 utools 本身并未开源,但是公司内部的工具库又无法发布到 utools 插件中,所以为了既要享受 utools 生态又要有定制化需求,我们自己参考 utools 设计,做了 Rubick.
|
||||
|
||||
Rubick(拉比克) 是 dota 里面的英雄之一,其核心技能是插件化使用其他英雄的技能,用完即走。非常符合本工具的设计理念,所以取名 Rubick。
|
||||
基于 electron 的开源工具箱,自由集成丰富插件,打造极致的桌面端效能工具。Rubick(拉比克) 是 dota 里面的英雄之一,其核心技能是插件化使用其他英雄的技能,用完即走。非常符合本工具的设计理念,所以取名 Rubick。
|
||||
|
||||
## 安装包
|
||||
* [Rubick Mac OS V0.0.2](https://github.com/clouDr-f2e/rubick/releases/download/v0.0.2/rubick2-0.0.2.pkg)
|
||||
* [Rubick Mac OS](https://github.com/clouDr-f2e/rubick/releases)
|
||||
* [Rubick Windows](https://github.com/clouDr-f2e/rubick/releases)
|
||||
* [Rubick Linux](https://github.com/clouDr-f2e/rubick/releases)
|
||||
|
||||
## 支持能力
|
||||
- [x] 支持 uTools 90% API。可直接按照 uTools 文档开发 Rubick 插件
|
||||
- [x] 支持 uTools github 开源插件。
|
||||
- [x] 支持远程下载安装插件,支持插件开发者模式
|
||||
- [x] 支持插件分离
|
||||
- [x] 支持系统命令取色、截屏、帮助
|
||||
- [x] 支持超级面板,长按右击呼出
|
||||
- [x] 支持全局快捷键设置
|
||||
- [x] 支持搜索本地已安装 app 或 偏好设置
|
||||
- [ ] 支持 Windows
|
||||
- [ ] 支持 Linux
|
||||
- [x] macos touchBar 唤起插件
|
||||
- [x] 支持 Windows(目前是 mac 的 alpha 版本,功能尚不全,正在迁移中)
|
||||
- [x] 支持 Linux
|
||||
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## 使用文档
|
||||
|
||||
[Rubick Docs](https://cloudr-f2e.github.io/rubick/)
|
||||
|
||||
|
||||
## 使用问题
|
||||
1. 目前 `Rubick` 插件市场 server 端还没有部署,所以目前看不到插件市场的插件。
|
||||
2. 依赖于 `robotjs` dev 环境运行请在 `install` 后执行 `npm run rebuild`
|
||||
1. 依赖于 `robotjs` dev 环境运行请在 `install` 后执行 `npm run rebuild`
|
||||
2. windows 版本目前有了一个最基础的可用版,代码在 [feat-win](https://github.com/clouDr-f2e/rubick/tree/feat-win) 分支。完整版正在开发中,敬请期待
|
||||
3. linux 开发分支 cross-platform 的 iohook 开发模式下可能需要手动下载并放入node_modules, 将在未来修复
|
||||
|
||||
## 目前支持能力
|
||||
### 加载utools生态插件
|
||||
拿 `github` 上开源的 斗图 插件举例,要加载斗图插件,只需要将代码 clone下来后,复制其 `plugin.json` 进入搜索框即可使用
|
||||
|
||||
斗图:https://github.com/vst93/doutu-uToolsPlugin
|
||||
### touchBar 唤起插件
|
||||
macOS 支持 touchbar 快速唤起插件
|
||||
|
||||

|
||||
|
||||
<img src=https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/cba1eb758180433294c93b59724adefd~tplv-k3u1fbpfcp-watermark.image width=500 />
|
||||
|
||||
### 超级面板
|
||||
长按鼠标右键,即可呼起超级面板,可以根据当前鼠标选择内容,匹配对应插件能力。比如当前选择图片后长按右击,则会呼起上传图床插件:
|
||||
@@ -57,15 +67,15 @@ Rubick(拉比克) 是 dota 里面的英雄之一,其核心技能是插件化
|
||||

|
||||
|
||||
### 模板
|
||||
为了更贴合 `uTools` 的插件能力,需要实现模板功能,模板即是一个内置 UI 样式的功能插件。
|
||||
模板即是一个内置 UI 样式的功能插件。
|
||||
|
||||
<img src=https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/0b113ad547974699b9c73c28bc09b9b1~tplv-k3u1fbpfcp-watermark.image width=500 />
|
||||
|
||||
### utools 自带的系统命令
|
||||
### 系统命令
|
||||
#### 取色
|
||||
基于 `robot.js` 以及 `iohook` 实现。未使用 C++ 扩展。
|
||||
|
||||
<img src=https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/8c3e00e5f08545bcb96613689649b337~tplv-k3u1fbpfcp-watermark.image width=500 />
|
||||

|
||||
|
||||
#### 截屏
|
||||
|
||||
@@ -77,7 +87,10 @@ Rubick(拉比克) 是 dota 里面的英雄之一,其核心技能是插件化
|
||||
<img src=https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/62cc424eacac4c9eb178f0e055e87d9a~tplv-k3u1fbpfcp-watermark.image width=500 />
|
||||
|
||||
### 最后
|
||||
utools过于强大,目前还没有完全实现其所有功能,不过我们会根据需要不断更新。欢迎小伙伴一起 `pr` 或 `star`
|
||||
对本项目有兴趣或者想要交流学习的同学可以扫码加下面的微信,备注 rubick,帮助我们更好的成长:
|
||||
|
||||

|
||||
|
||||
|
||||
## License
|
||||
This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/clouDr-f2e/rubick/blob/master/LICENSE) file for details.
|
||||
|
||||
BIN
build/icons/256x256.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
build/icons/icon.icns
Normal file
BIN
build/icons/icon.ico
Normal file
|
After Width: | Height: | Size: 15 KiB |
24
deploy.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# 确保脚本抛出遇到的错误
|
||||
set -e
|
||||
|
||||
# 生成静态文件
|
||||
cd docs && npm run docs:build
|
||||
# 进入生成的文件夹
|
||||
cd docs/.vuepress/dist
|
||||
|
||||
# 如果是发布到自定义域名
|
||||
# echo 'www.example.com' > CNAME
|
||||
|
||||
git init
|
||||
git add -A
|
||||
git commit -m 'deploy'
|
||||
|
||||
# 如果发布到 https://<USERNAME>.github.io
|
||||
# git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master
|
||||
|
||||
# 如果发布到 https://<USERNAME>.github.io/<REPO>
|
||||
git push -f git@github.com:clouDr-f2e/rubick.git master:gh-pages
|
||||
|
||||
cd -
|
||||
55
docs/docs/.vuepress/config.js
Normal file
@@ -0,0 +1,55 @@
|
||||
module.exports = {
|
||||
title: 'Rubick',
|
||||
description: '你的开源桌面插件应用',
|
||||
base: '/rubick/',
|
||||
themeConfig: {
|
||||
themeColor: {
|
||||
blue: "#2196f3",
|
||||
red: "#2196f3",
|
||||
green: "#2196f3",
|
||||
orange: "#2196f3",
|
||||
},
|
||||
logo: '/images/logo.png',
|
||||
nav: [
|
||||
{ text: '使用文档', link: '/guide/' },
|
||||
{ text: '开发者', link: '/dev/' },
|
||||
],
|
||||
sidebar: [
|
||||
{
|
||||
title: '使用文档', // 必要的
|
||||
path: '/guide/', // 可选的, 标题的跳转链接,应为绝对路径且必须存在
|
||||
sidebarDepth: 1, // 可选的, 默认值是 1
|
||||
},
|
||||
{
|
||||
title: '开发者',
|
||||
path: '/dev/',
|
||||
},
|
||||
{
|
||||
title: '常见问题',
|
||||
path: '/qs/',
|
||||
},
|
||||
{
|
||||
title: 'TODO: 原理解析',
|
||||
children: [
|
||||
{
|
||||
title: '插件化实现原理',
|
||||
path: '/blogs/plugin/',
|
||||
},
|
||||
{
|
||||
title: '超级面板实现原理',
|
||||
path: '/blogs/superPannel/',
|
||||
},
|
||||
]
|
||||
},
|
||||
],
|
||||
// 假定是 GitHub. 同时也可以是一个完整的 GitLab URL
|
||||
repo: 'https://github.com/clouDr-f2e/rubick',
|
||||
// 自定义仓库链接文字。默认从 `themeConfig.repo` 中自动推断为
|
||||
// "GitHub"/"GitLab"/"Bitbucket" 其中之一,或是 "Source"。
|
||||
repoLabel: 'Github',
|
||||
// 默认是 false, 设置为 true 来启用
|
||||
editLinks: true,
|
||||
// 默认为 "Edit this page"
|
||||
editLinkText: '帮助我们改善此页面!'
|
||||
}
|
||||
}
|
||||
BIN
docs/docs/.vuepress/public/images/1.png
Normal file
|
After Width: | Height: | Size: 77 KiB |
BIN
docs/docs/.vuepress/public/images/2.gif
Normal file
|
After Width: | Height: | Size: 471 KiB |
BIN
docs/docs/.vuepress/public/images/3.gif
Normal file
|
After Width: | Height: | Size: 749 KiB |
BIN
docs/docs/.vuepress/public/images/4.gif
Normal file
|
After Width: | Height: | Size: 2.7 MiB |
BIN
docs/docs/.vuepress/public/images/5.gif
Normal file
|
After Width: | Height: | Size: 452 KiB |
BIN
docs/docs/.vuepress/public/images/6.png
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
docs/docs/.vuepress/public/images/logo.png
Normal file
|
After Width: | Height: | Size: 47 KiB |
7
docs/docs/.vuepress/styles/palette.styl
Normal file
@@ -0,0 +1,7 @@
|
||||
$accentColor = #ff4ea4//默认主题颜色
|
||||
$codeBgColor = #282c34//默认背景颜色
|
||||
|
||||
//示例修改相关样式f12找到需要修改的地方找到对应class类拿过来直接用就行了
|
||||
.sidebar-group.is-sub-group > .sidebar-heading:not(.clickable){
|
||||
opacity :1
|
||||
}
|
||||
16
docs/docs/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
home: true
|
||||
heroImage: /images/logo.png
|
||||
heroText: Rubick
|
||||
tagline: 基于 Electron 开源的插件化工具箱
|
||||
actionText: 快速上手 →
|
||||
actionLink: /guide/
|
||||
features:
|
||||
- title: 开箱即用
|
||||
details: 支持快速检索系统应用
|
||||
- title: 自由定制
|
||||
details: 支持自定义插件开发
|
||||
- title: 海量示例
|
||||
details: 新版文档 code Demo & playground 一应俱全
|
||||
footer: MIT Licensed | Copyright (c) 2021 muwoo
|
||||
---
|
||||
167
docs/docs/blogs/plugin/README.md
Normal file
@@ -0,0 +1,167 @@
|
||||
## 插件化原理
|
||||
浏览器是打开不同网页进行浏览就是一个天然的插件,我们在做 `hybird` 混合开发的时候,App 内的 H5 页面也是可以类比成一个个
|
||||
插件。微信小程序在微信环境内运行也可以看做一个插件。他们都有一个共性:**在宿主环境内运行插件页面,需要使用宿主能力时
|
||||
调用宿主提供的API来完成自身能力的增强**。
|
||||
|
||||
所以 electron 也可以看做一个移动端 APP,我们通过 `webview` 来加载 `H5` 页面,`H5` 页面调用 `electron App` 内置 API
|
||||
完成功能增强。所以这就是我们核心的原理思想。
|
||||
|
||||
## electron webview 方式
|
||||
### 1. electron 中使用 webview
|
||||
|
||||
```html
|
||||
<webview src="https://xxx.xx.com/index.html" preload="preload.js" />
|
||||
```
|
||||
|
||||
### 2. 实现 `bridge`
|
||||
```js
|
||||
// preload.js
|
||||
window.rubickBridge = {
|
||||
sayHello() {
|
||||
console.log('hello world')
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. 插件借助 `bridge` 调用 `electron` 的能力
|
||||
|
||||
```html
|
||||
<html>
|
||||
<body>
|
||||
<div>这是一个插件<div>
|
||||
</body>
|
||||
<script>
|
||||
window.rubickBridge.sayHello()
|
||||
</script>
|
||||
</html>
|
||||
```
|
||||
|
||||
### 4. 通信
|
||||
因为 `proload.js` 是 `electron` 的 `renderer` 进程的,所以如果需要使用部分 `main` 进程的能力,则需要使用通信机制:
|
||||
```js
|
||||
// main process
|
||||
ipcMain.on('msg-trigger', async (event, arg) => {
|
||||
const window = arg.winId ? BrowserWindow.fromId(arg.winId) : mainWindow
|
||||
const operators = arg.type.split('.');
|
||||
let fn = Api;
|
||||
operators.forEach((op) => {
|
||||
fn = fn[op];
|
||||
});
|
||||
const data = await fn(arg, window);
|
||||
event.sender.send(`msg-back-${arg.type}`, data);
|
||||
});
|
||||
|
||||
// renderer process
|
||||
ipcRenderer.send('msg-trigger', {
|
||||
type: 'getPath',
|
||||
name,
|
||||
});
|
||||
ipcRenderer.on(`msg-back-getPath`, (e, result) => {
|
||||
console.log(result)
|
||||
});
|
||||
```
|
||||
|
||||
## 插件加载原理
|
||||
### rubick 使用插件
|
||||
首先我们需要实现一个插件,必须要有个 `plugin.json`,这玩意就是用来告诉 `rubick` 插件的信息。
|
||||
```json
|
||||
{
|
||||
"pluginName": "helloWorld",
|
||||
"description": "我的第一个uTools插件",
|
||||
"main": "index.html",
|
||||
"version": "0.0.1",
|
||||
"logo": "logo.png",
|
||||
"features": [
|
||||
{
|
||||
"code": "hello",
|
||||
"explain": "hello world",
|
||||
"cmds":["hello", "你好"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
接下来是将写好的插件用 `rubick` 跑起来,复制 `plugin.json` 到 `rubick` 搜索框即可,所以当 `rubick` 检测到输入框内执行
|
||||
`ctrl/command + c` 时,读取剪切板内容,如果剪切板复制的是文件类型的 `plugin.json`,那么就将构造插件的 `pluginConfig` 配置文件,用于后续搜索
|
||||
时使用。
|
||||
|
||||
```js
|
||||
// 监听 input change
|
||||
// 读取剪切板内容
|
||||
const fileUrl = clipboard.read('public.file-url').replace('file://', '');
|
||||
// 复制文件
|
||||
if (fileUrl && value === 'plugin.json') {
|
||||
// 读取 plugin.json 配置
|
||||
const config = JSON.parse(fs.readFileSync(fileUrl, 'utf-8'));
|
||||
const pluginConfig = {
|
||||
...config,
|
||||
// index.html 文件位置,用于webview加载
|
||||
sourceFile: path.join(fileUrl, `../${config.main || 'index.html'}`),
|
||||
id: uuidv4(),
|
||||
type: 'dev',
|
||||
icon: 'image://' + path.join(fileUrl, `../${config.logo}`),
|
||||
subType: (() => {
|
||||
if (config.main) {
|
||||
return ''
|
||||
}
|
||||
return 'template';
|
||||
})()
|
||||
};
|
||||
}
|
||||
```
|
||||
实现效果如下:
|
||||
|
||||
|
||||

|
||||
|
||||
### rubick 内搜索插件原理
|
||||
|
||||
接下来就是进行命令搜索插件:
|
||||
|
||||
|
||||

|
||||
|
||||
实现这个功能其实也就是对之前存储的`pluginConfig`的里面的 `features` 进行遍历,找到相应的 `cmd` 后进行下拉框展示即可。
|
||||
|
||||
```js
|
||||
state.devPlugins.forEach((plugin) => {
|
||||
// dev 插件未开启
|
||||
if (plugin.type === 'dev' && !plugin.status) return;
|
||||
const feature = plugin.features;
|
||||
feature.forEach((fe) => {
|
||||
// fe.cmds: 所有插件的命令; value: 当前输入框内搜索的名称
|
||||
const cmds = searchKeyValues(fe.cmds, value);
|
||||
options = [
|
||||
...options,
|
||||
...cmds.map((cmd) => ({
|
||||
name: cmd,
|
||||
value: 'plugin',
|
||||
icon: plugin.sourceFile ? 'image://' + path.join(plugin.sourceFile, `../${plugin.logo}`) : plugin.logo,
|
||||
desc: fe.explain,
|
||||
type: plugin.type,
|
||||
click: (router) => {
|
||||
// 跳转到指定插件页面
|
||||
actions.openPlugin({ commit }, { cmd, plugin, feature: fe, router });
|
||||
}
|
||||
}))
|
||||
];
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
当点击 input 内插件时,需要跳转到插件 `webview` 加载页面:
|
||||
|
||||
```js
|
||||
// actions.openPlugin
|
||||
router.push({
|
||||
path: '/plugin',
|
||||
query: {
|
||||
...plugin,
|
||||
_modify: Date.now(),
|
||||
detail: JSON.stringify(feature)
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||

|
||||
|
||||
本页写的插件demo已上传 [github](https://github.com/clouDr-f2e/rubick-plugin-demo)
|
||||
175
docs/docs/blogs/superPannel/README.md
Normal file
@@ -0,0 +1,175 @@
|
||||
## 前言
|
||||
超级面板用于增强用户右击能力,实现快速呼起插件的能力,本次实现方式是通过 `robotjs` 以及 `iohook` 一起来完成
|
||||
|
||||
### 功能截图:
|
||||
|
||||
#### 文件夹下长按右建
|
||||
<img src=https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/9b3d6ea7a25b4b908acc471471628979~tplv-k3u1fbpfcp-watermark.image width=300 />
|
||||
|
||||
#### 选择文件后长按右键
|
||||
<img src=https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/8e220166cb464328b432f42d14ba9ab2~tplv-k3u1fbpfcp-watermark.image width=300 />
|
||||
|
||||
#### 选择文字后长按右键
|
||||
<img src=https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/f9f909d08a8441e8a506831796908ef9~tplv-k3u1fbpfcp-watermark.image width=300 />
|
||||
|
||||
## 实现原理
|
||||
|
||||
### 获取选中文案
|
||||
要实现改功能核心是要读取当前用户选中的文案或者文件,根据当前选择内容进行不同功能展示。但是核心有一个问题是如何来实现获取当前选中的内容。这个问题思考了很久很久,要想获取选中的文案,感觉唯一的办法是使用 `ctrl + c` 或者 `command + c` 来先复制到剪切板,再通过 `electron clipboard` 来获取当前剪切板内容。但是 `utools` 可不是通过先复制再长按这样的操作来实现的,而是直接选中文本或者文件长按后呼起超级面板。**所以一定要在右击长按前获取到当前选中的内容。**
|
||||
|
||||
如果要这么干,可能真的无解了,之前就因为这么想,才被无解了。正确的思路应该是先长按再获取选中的内容。别看只是掉了个个,但实现确实天壤之别:
|
||||
|
||||
1. 先获取选中内容:这就要求我们必须监听原生系统选中事件,但是 `electron` 并没有提供能力,我们也无法监听系统选择事件。
|
||||
2. 先右击,后获取内容,这样的好处在于先右击可以通过监听鼠标右击事件,相比选择事件更加容易。
|
||||
|
||||
所以思路就有了,先监听长按右击事件:
|
||||
|
||||
```js
|
||||
// macos
|
||||
const mouseEvents = require("osx-mouse");
|
||||
|
||||
const mouseTrack = mouseEvents();
|
||||
// 按下去的 time
|
||||
let down_time = 0;
|
||||
|
||||
// 是否弹起
|
||||
let isPress = false;
|
||||
|
||||
// 监听右击
|
||||
mouseTrack.on('right-down', () => {
|
||||
isPress = true;
|
||||
down_time = Date.now();
|
||||
// 长按 500ms 后触发
|
||||
setTimeout(async () => {
|
||||
if (isPress) {
|
||||
// 获取选中内容
|
||||
const copyResult = await getSelectedText();
|
||||
}, 500);
|
||||
})
|
||||
mouseTrack.on('right-up', () => {
|
||||
isPress = false;
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
接下来一步就是要去实现获取选中内容,要获取选中内容有个比较骚的操作,就是:
|
||||
|
||||
1. 通过 `clipboard` 先获取当前剪切板内容,并存下 A
|
||||
2. 通过 `robot.js` 来调用系统 `command + c` 或者 `ctrl + c`
|
||||
3. 再通过 `clipboard` 先获取当前剪切板内容,并存下 B
|
||||
4. 再将 A 写到剪切板中,返回 B
|
||||
|
||||
先存剪切板内容的目的在于我们是偷偷帮用户执行了复制动作,当读取完用户选择内容后,需要回复用户之前的剪切板内容。接下来看一下简单的实现:
|
||||
|
||||
```js
|
||||
const getSelected = () => {
|
||||
return new Promise((resolve) => {
|
||||
// 缓存之前的文案
|
||||
const lastText = clipboard.readText('clipboard');
|
||||
|
||||
const platform = process.platform;
|
||||
|
||||
// 执行复制动作
|
||||
if (platform === 'darwin') {
|
||||
robot.keyTap('c', 'command');
|
||||
} else {
|
||||
robot.keyTap('c', 'control');
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
// 读取剪切板内容
|
||||
const text = clipboard.readText('clipboard') || ''
|
||||
const fileUrl = clipboard.read('public.file-url');
|
||||
|
||||
// 恢复剪切板内容
|
||||
clipboard.writeText(lastText);
|
||||
|
||||
resolve({
|
||||
text,
|
||||
fileUrl
|
||||
})
|
||||
}, 300);
|
||||
})
|
||||
}
|
||||
```
|
||||
### 通知超级面板窗口当前选中内容
|
||||
当获取到了选中内容后,接下来就是需要创建超级面板的 `BrowserWindow`:
|
||||
```js
|
||||
const { BrowserWindow, ipcMain, app } = require("electron");
|
||||
|
||||
module.exports = () => {
|
||||
let win;
|
||||
|
||||
let init = (mainWindow) => {
|
||||
if (win === null || win === undefined) {
|
||||
createWindow();
|
||||
}
|
||||
};
|
||||
|
||||
let createWindow = () => {
|
||||
win = new BrowserWindow({
|
||||
frame: false,
|
||||
autoHideMenuBar: true,
|
||||
width: 250,
|
||||
height: 50,
|
||||
show: false,
|
||||
alwaysOnTop: true,
|
||||
webPreferences: {
|
||||
webSecurity: false,
|
||||
enableRemoteModule: true,
|
||||
backgroundThrottling: false,
|
||||
nodeIntegration: true,
|
||||
devTools: false,
|
||||
},
|
||||
});
|
||||
win.loadURL(`file://${__static}/plugins/superPanel/index.html`);
|
||||
win.once('ready-to-show', () => win.show());
|
||||
win.on("closed", () => {
|
||||
win = undefined;
|
||||
});
|
||||
};
|
||||
|
||||
let getWindow = () => win;
|
||||
|
||||
return {
|
||||
init: init,
|
||||
getWindow: getWindow,
|
||||
};
|
||||
};
|
||||
```
|
||||
然后再通知 `superPanel` 进行内容展示:
|
||||
```js
|
||||
win.webContents.send('trigger-super-panel', {
|
||||
...copyResult,
|
||||
optionPlugin: optionPlugin.plugins,
|
||||
});
|
||||
```
|
||||
|
||||
### 超级面板点击操作
|
||||
接下来要实现超级面板点击操作,这块也是比较简单的了,直接上代码好了:
|
||||
#### 1. 打开 Terminal
|
||||
|
||||
```js
|
||||
const { spawn } = require ('child_process');
|
||||
|
||||
spawn('open', [ '-a', 'Terminal', fileUrl ]);
|
||||
```
|
||||
|
||||
#### 2. 新建文件
|
||||
|
||||
```js
|
||||
remote.dialog.showSaveDialog({
|
||||
title: "请选择要保存的文件名",
|
||||
buttonLabel: "保存",
|
||||
defaultPath: fileUrl.replace('file://', ''),
|
||||
showsTagField: false,
|
||||
nameFieldLabel: '',
|
||||
}).then(result => {
|
||||
fs.writeFileSync(result.filePath, '');
|
||||
});
|
||||
```
|
||||
|
||||
#### 3. 复制路径
|
||||
```js
|
||||
clipboard.writeText(fileUrl.replace('file://', ''))
|
||||
```
|
||||
81
docs/docs/dev/README.md
Normal file
@@ -0,0 +1,81 @@
|
||||
## 开发一个最基础的插件
|
||||
一个最基础插件的目录是这样的:
|
||||
```
|
||||
rubick-plugin-demo
|
||||
|-- index.html
|
||||
|-- logo.png
|
||||
|-- plugin.json
|
||||
|-- preload.js
|
||||
```
|
||||
## 文件说明
|
||||
### plugin.json
|
||||
用于指定插件最基础的配置,一个最基础的配置信息如下:
|
||||
```json
|
||||
{
|
||||
"pluginName": "测试插件",
|
||||
"author": "muwoo",
|
||||
"description": "我的第一个 rubick 插件",
|
||||
"main": "index.html",
|
||||
"version": "0.0.2",
|
||||
"logo": "logo.png",
|
||||
"name": "rubick-plugin-demo",
|
||||
"features": [
|
||||
{
|
||||
"code": "hello",
|
||||
"explain": "这是一个测试的插件",
|
||||
"cmds":["hello", "你好"]
|
||||
}
|
||||
],
|
||||
"preload": "preload.js"
|
||||
}
|
||||
```
|
||||
核心字段说明:
|
||||
|
||||
* name 插件仓库名称,需要保持和git仓库同名,不要随意变更
|
||||
* pluginName 插件显示名称,用于展示给使用者
|
||||
* description 插件描述,描述这个插件的作用
|
||||
* main 入口文件,一般为 `index.html`
|
||||
* version 插件的版本
|
||||
* features 插件核心功能列表
|
||||
* features.code 插件某个功能的识别码,可用于区分不同的功能
|
||||
* features.cmds 输入框内搜索该 cmd 进入插件
|
||||
|
||||
### index.html
|
||||
插件的入口文件,用于展示插件的样式,一个最基础的 `html` 结构可以是这样:
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
hello Rubick
|
||||
<button id="showNotification">通知</button>
|
||||
</body>
|
||||
<script>
|
||||
document.getElementById('showNotification').addEventListener('click', () => {
|
||||
window.showNotification();
|
||||
})
|
||||
</script>
|
||||
</html>
|
||||
```
|
||||
|
||||
### preload.js
|
||||
细心的同学可能已经注意到上面的 `index.html` 使用了一个全局函数 `showNotification` 那么这个函数是在哪里定义的呢?
|
||||
答案就是在 `preload.js` 里面。我们知道 `electron` 是可以再渲染进程中执行 `node.js` 的,所以 `preload.js` 是既可以
|
||||
执行 `node.js` 以及执行 `Rubick` 提供的系统命令的位置:
|
||||
```js
|
||||
window.showNotification = function () {
|
||||
rubick.showNotification('HI, rubick')
|
||||
}
|
||||
```
|
||||
rubick 更多支持 API 能力参考:[rubick 全局API](https://github.com/clouDr-f2e/rubick/blob/master/static/preload.js#L49)
|
||||
|
||||
### logo.png
|
||||
当前插件的logo图标,建议是 200 x 200 方形图标
|
||||
|
||||
## 测试插件
|
||||
复制 `plugin.json` 文件,在 `rubick` 主窗口执行 `ctrl/command + v` 即可唤起安装插件的功能,选择`新建rubick插件`,进入插件主界面,
|
||||
开启插件后,在插件主窗口即可通过命令打开插件:
|
||||
|
||||

|
||||
|
||||
本小节所有代码:[rubcik-plugin-demo](https://github.com/clouDr-f2e/rubick-plugin-demo)
|
||||
|
||||
56
docs/docs/guide/README.md
Normal file
@@ -0,0 +1,56 @@
|
||||
## 下载 rubick
|
||||
[rubick 下载安装地址](https://github.com/clouDr-f2e/rubick/releases)
|
||||
|
||||
安装完成后打开 rubick 即可看到主搜索界面:
|
||||
|
||||

|
||||
|
||||
目前支持 windows 和 macos。linux 小伙伴正在开发中
|
||||
|
||||
## 功能说明
|
||||
接下来详细介绍 rubick 所包含和支持的功能
|
||||
|
||||
### 1. 搜索系统应用
|
||||
`macos` 下支持搜索当前电脑内所安装的所有 app 和一些偏好设置,目前可搜索路径为:
|
||||
```json
|
||||
[
|
||||
"/System/Applications",
|
||||
"/Applications",
|
||||
"/System/Library/PreferencePanes"
|
||||
]
|
||||
```
|
||||
也就是说只要当前系统软件安装到这些目录才会被检索到。支持中文搜索和拼音、拼音首字母搜索:
|
||||
|
||||

|
||||
|
||||
`Windows` 内由于安装目录太多不确定,有的在 C盘,有的在D盘,还有的在自定义其他位置,所以该功能还在设计中,如果您有好的方案也欢迎提供:[issues](https://github.com/clouDr-f2e/rubick/issues)
|
||||
|
||||
### 2. rubick 内置功能
|
||||
|
||||
`rubick` 参考了钉钉、微信等 App 的基础功能,也设计内置了 `截图`、`取色`、`锁屏` 基础功能,通过搜索框输入对应关键词呼起。
|
||||
|
||||
#### 截屏
|
||||
输入:`'截屏'` 或者 `'shortCut'` 或者 `'jp'`。
|
||||
|
||||
#### 取色
|
||||
输入:`'取色'` 或者 `'拾色'` 或者 `'Pick color'` 、`'qs'`、`'ss'`。
|
||||
|
||||
#### 锁屏
|
||||
输入:`'锁屏'` 或者 `'lock screen'` 或者 `'sp'`。
|
||||
|
||||
### 3. 使用插件
|
||||
点击搜索框右侧 rubick 图标,进入插件市场,选择所需插件,点击下载按钮即可下载,下载完成后在已安装 tab 下可以找到安装插件。
|
||||
安装完成后,输入插件呼起命令即可使用对应插件:
|
||||
|
||||

|
||||
|
||||
### 4. 右击增强
|
||||
通常我们需要使用鼠标右击来对桌面属性进行拓展,`Rubick` 支持对右击属性进行增强功能,长按鼠标右键即可呼起。如果安装的插件支持
|
||||
特殊类型的文件操作,还可以在右键中唤起插件:
|
||||
|
||||

|
||||
|
||||
### 更多功能
|
||||
如果您还需要更多功能,欢迎来这里给我们提建议:[issues](https://github.com/clouDr-f2e/rubick/issues/20)
|
||||
有价值的想法我们会加入到后期的开发当中。同时也欢迎一起加入共建。
|
||||
|
||||
BIN
docs/docs/guide/img.png
Normal file
|
After Width: | Height: | Size: 92 KiB |
99
docs/docs/qs/README.md
Normal file
@@ -0,0 +1,99 @@
|
||||
## windows 本地启动项目
|
||||
**windows 项目地址目前在 `feat-win` 分支,需要切换到 `feat-win`。**
|
||||
如果您是在 `windows` 系统下使用本项目进行启动的话,如果出现了一些跑不起的情况,下面的一些经验或许可以帮助您。
|
||||
|
||||
### 安装依赖
|
||||
项目是基于 `electron-vue` 的,所以需要本地已经安装好 `nodejs`。当 `clone` 好项目到本地的时候,需要对项目依赖
|
||||
进行手动安装:
|
||||
```bash
|
||||
$ cd rubick
|
||||
$ npm install
|
||||
```
|
||||
由于本项目依赖 [iohook](https://wilix-team.github.io/iohook/) 和 [robotjs](http://robotjs.io/)
|
||||
而这2个项目在安装时,依赖 node gyp 的编译,所以你可能会遇到一些环境问题或者网络问题。
|
||||
### iohook 安装
|
||||
首先,我们先来安装 `iohook`,按照 `iohook` 的文档所示,安装前需要先确定当前 `electron` 的版本以及 `abi` 的版本,
|
||||
现在我们使用的 `electron` 版本是 `v11.0.2` 所以只需要在 `package,json` 中加上以下配置,指定安装特点的`.node` 文件
|
||||
|
||||
```json
|
||||
{
|
||||
"iohook": {
|
||||
"targets": [
|
||||
"node-83",
|
||||
"electron-85"
|
||||
],
|
||||
"platforms": [
|
||||
"win32"
|
||||
],
|
||||
"arches": [
|
||||
"x64",
|
||||
"ia32"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
接下来执行安装操作:
|
||||
```shell
|
||||
$ npm i iohook
|
||||
```
|
||||
|
||||
如果此时一直停留在 `node install` 进度上,说明可能需要翻墙,这里就不介绍如何翻墙了。此时虽然 `.node` 文件没有下载成功,但是 `iohook` 源文件
|
||||
已经安装成功,如果因为翻墙问题导致的安装失败,我们解决好翻墙问题后,可以接着运行一下:
|
||||
|
||||
```shell
|
||||
$ npm run rebuild_win
|
||||
```
|
||||
到这里 `iohook` 应该就安装好了
|
||||
|
||||
### 安装 robotjs
|
||||
和 iohook 不同, `robotjs` 需要 `node gyp` 重新编译 `C++`。所以第一步是先安装源文件:
|
||||
```shell
|
||||
npm i robotjs@git+https://github.com/Toinane/robotjs.git
|
||||
```
|
||||
此时如果报错,大多还是因为墙的问题。不管包不报错,我们接下来都需要执行一下下面的编译操作:
|
||||
|
||||
```shell
|
||||
npm run rebuild_win
|
||||
```
|
||||
此时,可能会出现下这个错:
|
||||
|
||||
```text
|
||||
gyp ERR! find VS msvs_version not set from command line or npm config
|
||||
// ...
|
||||
```
|
||||
google 了一圈,大多数是说缺少 `visual studio`。需要安装,所以可以执行这个命令:
|
||||
|
||||
```shell
|
||||
$ npm install --global --production windows-build-tools
|
||||
```
|
||||
到这里会进入正常的安装流程,理论上会一部到底,如果你卡在了 `Successfully installed Python 2.7` 不动了
|
||||
可以去一下 `C:\Users\you username\.windows-build-tools` 找一下看看应该会有一个 `vs_BuildTools` 文件
|
||||
双击后,会出现以下弹窗:
|
||||
|
||||

|
||||
|
||||
点击启动,如果一切正常那么可以方向关掉你的命令行了,此时 vs 已经安装成功,接下来要配置一下编译工具:
|
||||
```shell
|
||||
$ npm config set python python3.9
|
||||
$ npm config set msvs_version 2017
|
||||
```
|
||||
到这里终于完事了,再执行一下 `npm run rebuild_win` 此时已经安装成功!
|
||||
|
||||
## macos
|
||||
macos 下安装就简单不少了,首先先解决翻墙的问题,然后:
|
||||
```shell
|
||||
$ npm i
|
||||
```
|
||||
|
||||
最后执行
|
||||
|
||||
```shell
|
||||
$npm run rebuild
|
||||
```
|
||||
|
||||
## 最后
|
||||
如果您在启动过程中还有其他的问题,欢迎随时给我们反馈,我们会在第一时间回复:[issues](https://github.com/clouDr-f2e/rubick/issues/20)
|
||||
|
||||
|
||||
|
||||
|
||||
24918
docs/package-lock.json
generated
Normal file
15
docs/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "rubick-docs",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"docs:dev": "vuepress dev docs",
|
||||
"docs:build": "vuepress build docs"
|
||||
},
|
||||
"author": "muwoo",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"vuepress": "^1.8.2"
|
||||
}
|
||||
}
|
||||
16387
package-lock.json
generated
54
package.json
@@ -1,26 +1,22 @@
|
||||
{
|
||||
"name": "rubick2",
|
||||
"version": "0.0.2-beta.1",
|
||||
"version": "0.0.7-beta.1",
|
||||
"author": "muwoo <2424880409@qq.com>",
|
||||
"description": "An electron-vue project",
|
||||
"license": null,
|
||||
"main": "./dist/electron/main.js",
|
||||
"scripts": {
|
||||
"release": "node .electron-vue/build.js && electron-builder --publish always",
|
||||
"build": "node .electron-vue/build.js && electron-builder",
|
||||
"build:dir": "node .electron-vue/build.js && electron-builder --dir",
|
||||
"build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
|
||||
"build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
|
||||
"dev": "node .electron-vue/dev-runner.js",
|
||||
"pack": "npm run pack:main && npm run pack:renderer",
|
||||
"pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
|
||||
"pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
|
||||
"postinstall": "",
|
||||
"rebuild": " ./node_modules/.bin/electron-rebuild"
|
||||
"rebuild": " ./node_modules/.bin/electron-rebuild",
|
||||
"rebuild_win": "npm rebuild --runtime=electron --target=11.4.10 --disturl=https://atom.io/download/atom-shell --abi=85",
|
||||
"rebuild_linux": "npm rebuild --runtime=electron --target=11.4.10 --disturl=https://atom.io/download/atom-shell --abi=85"
|
||||
},
|
||||
"build": {
|
||||
"asar": false,
|
||||
"asar": true,
|
||||
"productName": "rubick2",
|
||||
"appId": "com.example.yourapp2",
|
||||
"appId": "com.muwoo.rubick",
|
||||
"compression": "maximum",
|
||||
"directories": {
|
||||
"output": "build"
|
||||
@@ -28,9 +24,6 @@
|
||||
"files": [
|
||||
"dist/electron/**/*"
|
||||
],
|
||||
"electronDownload": {
|
||||
"mirror": "https://npm.taobao.org/mirrors/electron/"
|
||||
},
|
||||
"dmg": {
|
||||
"contents": [
|
||||
{
|
||||
@@ -48,13 +41,24 @@
|
||||
},
|
||||
"mac": {
|
||||
"icon": "build/icons/icon.icns",
|
||||
"target": "pkg"
|
||||
"target": "pkg",
|
||||
"extendInfo": {
|
||||
"LSUIElement": 1
|
||||
}
|
||||
},
|
||||
"win": {
|
||||
"icon": "build/icons/icon.ico"
|
||||
"icon": "build/icons/icon.ico",
|
||||
"target": "nsis"
|
||||
},
|
||||
"nsis": {
|
||||
"oneClick": false,
|
||||
"allowToChangeInstallationDirectory": true
|
||||
},
|
||||
"linux": {
|
||||
"icon": "build/icons"
|
||||
"icon": "build/icons/",
|
||||
"publish": [
|
||||
"github"
|
||||
]
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -63,9 +67,12 @@
|
||||
"bplist-parser": "^0.3.0",
|
||||
"download": "^8.0.0",
|
||||
"download-git-repo": "^3.0.2",
|
||||
"electron-is-dev": "^2.0.0",
|
||||
"electron-store": "^8.0.0",
|
||||
"extract-file-icon": "^0.3.2",
|
||||
"iohook": "^0.9.3",
|
||||
"is-chinese": "^1.4.2",
|
||||
"jian-pinyin": "^0.2.3",
|
||||
"keycode": "^2.2.0",
|
||||
"marked": "^2.0.7",
|
||||
"md5": "^2.3.0",
|
||||
@@ -76,9 +83,11 @@
|
||||
"query-string": "^7.0.0",
|
||||
"request": "^2.88.2",
|
||||
"request-promise": "^4.2.6",
|
||||
"robotjs": "git+ssh://git@github.com/Toinane/robotjs.git",
|
||||
"robotjs": "git+https://github.com/Toinane/robotjs.git",
|
||||
"semver": "^7.3.5",
|
||||
"shelljs": "^0.8.4",
|
||||
"sudo-prompt": "^9.2.1",
|
||||
"systeminformation": "^5.8.0",
|
||||
"unzip": "^0.1.11",
|
||||
"uuid": "^8.3.2",
|
||||
"vue": "^2.5.16",
|
||||
@@ -96,6 +105,7 @@
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-stage-0": "^6.24.1",
|
||||
"babel-register": "^6.26.0",
|
||||
"babel-runtime": "^6.26.0",
|
||||
"cfonts": "^2.1.2",
|
||||
"chalk": "^2.4.1",
|
||||
"copy-webpack-plugin": "^4.5.1",
|
||||
@@ -103,7 +113,7 @@
|
||||
"css-loader": "^0.28.11",
|
||||
"del": "^3.0.0",
|
||||
"devtron": "^1.4.0",
|
||||
"electron": "^11.0.2",
|
||||
"electron": "^11.4.10",
|
||||
"electron-builder": "22.10.5",
|
||||
"electron-debug": "^1.5.0",
|
||||
"electron-devtools-installer": "^2.2.4",
|
||||
@@ -111,7 +121,7 @@
|
||||
"file-loader": "^1.1.11",
|
||||
"html-webpack-plugin": "^3.2.0",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"less": "^4.1.1",
|
||||
"less": "^2.7.3",
|
||||
"less-loader": "^5.0.0",
|
||||
"listr": "^0.14.3",
|
||||
"mini-css-extract-plugin": "0.4.0",
|
||||
@@ -137,7 +147,9 @@
|
||||
"electron-85"
|
||||
],
|
||||
"platforms": [
|
||||
"darwin"
|
||||
"darwin",
|
||||
"win32",
|
||||
"linux"
|
||||
],
|
||||
"arches": [
|
||||
"x64",
|
||||
|
||||
11829
pnpm-lock.yaml
generated
Normal file
@@ -3,4 +3,4 @@ module.exports = () => ({
|
||||
separator: require("./separate")(),
|
||||
superPanel: require("./superPanel")(),
|
||||
main: require("./main")(),
|
||||
});
|
||||
})
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const { BrowserWindow, protocol } = require("electron");
|
||||
const { BrowserWindow, protocol } = require("electron")
|
||||
module.exports = () => {
|
||||
let win;
|
||||
let win
|
||||
|
||||
let init = (opts) => {
|
||||
createWindow(opts);
|
||||
};
|
||||
createWindow(opts)
|
||||
}
|
||||
|
||||
let createWindow = (opts) => {
|
||||
const winURL = process.env.NODE_ENV === 'development'
|
||||
@@ -14,14 +14,17 @@ module.exports = () => {
|
||||
win = new BrowserWindow({
|
||||
height: 60,
|
||||
useContentSize: true,
|
||||
resizable: true,
|
||||
width: 800,
|
||||
frame: false,
|
||||
title: '拉比克',
|
||||
show: false,
|
||||
skipTaskbar: true,
|
||||
webPreferences: {
|
||||
webSecurity: false,
|
||||
enableRemoteModule: true,
|
||||
backgroundThrottling: false,
|
||||
contextIsolation: false,
|
||||
webviewTag: true,
|
||||
nodeIntegration: true // 在网页中集成Node
|
||||
}
|
||||
@@ -30,24 +33,24 @@ module.exports = () => {
|
||||
win.loadURL(winURL)
|
||||
|
||||
protocol.interceptFileProtocol('image', (req, callback) => {
|
||||
const url = req.url.substr(8);
|
||||
callback(decodeURI(url));
|
||||
const url = req.url.substr(8)
|
||||
callback(decodeURI(url))
|
||||
}, (error) => {
|
||||
if (error) {
|
||||
console.error('Failed to register protocol');
|
||||
console.error('Failed to register protocol')
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
win.once('ready-to-show', () => win.show());
|
||||
win.once('ready-to-show', () => win.show())
|
||||
win.on("closed", () => {
|
||||
win = undefined;
|
||||
});
|
||||
};
|
||||
win = undefined
|
||||
})
|
||||
}
|
||||
|
||||
let getWindow = () => win;
|
||||
let getWindow = () => win
|
||||
|
||||
return {
|
||||
init: init,
|
||||
getWindow: getWindow,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
const { BrowserWindow, nativeImage } = require("electron");
|
||||
const { BrowserWindow, nativeImage } = require("electron")
|
||||
|
||||
module.exports = () => {
|
||||
let win;
|
||||
let win
|
||||
|
||||
let init = (x, y) => {
|
||||
if (win === null || win === undefined) {
|
||||
createWindow();
|
||||
createWindow()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
let createWindow = () => {
|
||||
win = new BrowserWindow({
|
||||
@@ -22,20 +22,21 @@ module.exports = () => {
|
||||
hasShadow: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false,
|
||||
devTools: false,
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
win.loadURL(`file://${__static}/plugins/picker/index.html`);
|
||||
win.loadURL(`file://${__static}/plugins/picker/index.html`)
|
||||
win.on("closed", () => {
|
||||
win = undefined;
|
||||
});
|
||||
};
|
||||
win = undefined
|
||||
})
|
||||
}
|
||||
|
||||
let getWindow = () => win;
|
||||
let getWindow = () => win
|
||||
|
||||
return {
|
||||
init: init,
|
||||
getWindow: getWindow,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
const { BrowserWindow } = require("electron");
|
||||
const { BrowserWindow } = require("electron")
|
||||
|
||||
module.exports = () => {
|
||||
let win;
|
||||
let win
|
||||
|
||||
let init = (opts) => {
|
||||
createWindow(opts);
|
||||
};
|
||||
createWindow(opts)
|
||||
}
|
||||
|
||||
let createWindow = (opts) => {
|
||||
const winURL = process.env.NODE_ENV === 'development'
|
||||
@@ -22,27 +22,28 @@ module.exports = () => {
|
||||
webSecurity: false,
|
||||
enableRemoteModule: true,
|
||||
backgroundThrottling: false,
|
||||
contextIsolation: false,
|
||||
webviewTag: true,
|
||||
nodeIntegration: true // 在网页中集成Node
|
||||
}
|
||||
});
|
||||
})
|
||||
process.env.NODE_ENV === 'development' ? win.loadURL(winURL) : win.loadFile(winURL, {
|
||||
hash: `#/plugin`,
|
||||
});
|
||||
})
|
||||
|
||||
win.webContents.executeJavaScript(`window.setPluginInfo(${opts})`).then(() => {
|
||||
win.show()
|
||||
});
|
||||
})
|
||||
|
||||
win.on("closed", () => {
|
||||
win = undefined;
|
||||
});
|
||||
};
|
||||
win = undefined
|
||||
})
|
||||
}
|
||||
|
||||
let getWindow = () => win;
|
||||
let getWindow = () => win
|
||||
|
||||
return {
|
||||
init: init,
|
||||
getWindow: getWindow,
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import pkg from '../../../package.json';
|
||||
const os = require('os');
|
||||
|
||||
const version = pkg.version;
|
||||
const releaseUrl = 'http://rubick-server.qa.91jkys.com/release/query';
|
||||
const releaseUrl = 'http://118.195.176.247:8080/release/query';
|
||||
|
||||
export async function autoUpdate() {
|
||||
let res;
|
||||
|
||||
@@ -9,13 +9,6 @@ export default function init(mainWindow) {
|
||||
listener.registerShortCut(mainWindow);
|
||||
listener.init(mainWindow);
|
||||
|
||||
// 设置开机启动
|
||||
const config = global.opConfig.get();
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin: config.perf.common.start,
|
||||
openAsHidden: true,
|
||||
});
|
||||
|
||||
mainWindow.once("ready-to-show", () => {
|
||||
// 非隐藏式启动需要显示主窗口
|
||||
if (!app.getLoginItemSettings().wasOpenedAsHidden) {
|
||||
|
||||
@@ -1,16 +1,68 @@
|
||||
import path from "path";
|
||||
import fs from 'fs';
|
||||
import {getlocalDataFile} from "./utils";
|
||||
import os from 'os';
|
||||
import path from "path"
|
||||
import fs from 'fs'
|
||||
import { getlocalDataFile } from "./utils"
|
||||
import os from 'os'
|
||||
|
||||
const configPath = path.join(getlocalDataFile(), './rubick-config.json');
|
||||
const configPath = path.join(getlocalDataFile(), './rubick-config.json')
|
||||
|
||||
let defaultConfig = {
|
||||
Darwin: {
|
||||
version: 3,
|
||||
perf: {
|
||||
shortCut: {
|
||||
showAndHidden: 'Option+R',
|
||||
separate: 'Ctrl+D'
|
||||
separate: 'Ctrl+D',
|
||||
quit: 'Shift+Escape'
|
||||
},
|
||||
common: {
|
||||
start: true,
|
||||
space: true,
|
||||
},
|
||||
local: {
|
||||
search: true,
|
||||
}
|
||||
},
|
||||
superPanel: {
|
||||
baiduAPI: {
|
||||
key: '',
|
||||
appid: '',
|
||||
},
|
||||
mouseDownTime: 500
|
||||
},
|
||||
global: []
|
||||
},
|
||||
Windows_NT: {
|
||||
version: 3,
|
||||
perf: {
|
||||
shortCut: {
|
||||
showAndHidden: 'Option+R',
|
||||
separate: 'Ctrl+D',
|
||||
quit: 'Shift+Escape'
|
||||
},
|
||||
common: {
|
||||
start: true,
|
||||
space: true,
|
||||
},
|
||||
local: {
|
||||
search: true,
|
||||
}
|
||||
},
|
||||
superPanel: {
|
||||
baiduAPI: {
|
||||
key: '',
|
||||
appid: '',
|
||||
},
|
||||
mouseDownTime: 500
|
||||
},
|
||||
global: []
|
||||
},
|
||||
Linux: {
|
||||
version: 3,
|
||||
perf: {
|
||||
shortCut: {
|
||||
showAndHidden: 'Option+R',
|
||||
separate: 'Ctrl+D',
|
||||
quit: 'Shift+Escape'
|
||||
},
|
||||
common: {
|
||||
start: true,
|
||||
@@ -36,22 +88,22 @@ global.opConfig = {
|
||||
const platform = os.type();
|
||||
try {
|
||||
if (!opConfig.config) {
|
||||
opConfig.config = JSON.parse(fs.readFileSync(configPath) || JSON.stringify(defaultConfig[platform]));
|
||||
opConfig.config = JSON.parse(fs.readFileSync(configPath) || JSON.stringify(defaultConfig[platform]))
|
||||
}
|
||||
// 重置
|
||||
if (!opConfig.config.perf || !opConfig.config.superPanel || !opConfig.config.global) {
|
||||
opConfig.config = defaultConfig[platform];
|
||||
fs.writeFileSync(configPath, JSON.stringify(opConfig.config));
|
||||
if (!opConfig.config.version || opConfig.config.version < defaultConfig[platform].version) {
|
||||
opConfig.config = defaultConfig[platform]
|
||||
fs.writeFileSync(configPath, JSON.stringify(opConfig.config))
|
||||
}
|
||||
return opConfig.config;
|
||||
return opConfig.config
|
||||
} catch (e) {
|
||||
opConfig.config = defaultConfig[platform]
|
||||
return opConfig.config;
|
||||
return opConfig.config
|
||||
}
|
||||
},
|
||||
set(key, value) {
|
||||
opConfig.config[key] = value;
|
||||
fs.writeFileSync(configPath, JSON.stringify(opConfig.config));
|
||||
fs.writeFileSync(configPath, JSON.stringify(opConfig.config))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
src/main/common/icons/charger.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/main/common/icons/chip.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src/main/common/icons/hard-disk-drive.png
Normal file
|
After Width: | Height: | Size: 876 B |
BIN
src/main/common/icons/internet.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
src/main/common/icons/power.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
src/main/common/icons/ram.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
@@ -1,9 +1,22 @@
|
||||
import {BrowserWindow, clipboard, globalShortcut, ipcMain, Notification, screen} from "electron";
|
||||
import {
|
||||
app,
|
||||
nativeImage,
|
||||
BrowserWindow,
|
||||
clipboard,
|
||||
globalShortcut,
|
||||
ipcMain,
|
||||
Notification,
|
||||
screen,
|
||||
TouchBar
|
||||
} from 'electron';
|
||||
import {exec, spawn} from "child_process";
|
||||
import robot from "robotjs";
|
||||
import Api from "./api";
|
||||
import ioHook from 'iohook';
|
||||
import {throttle} from './utils';
|
||||
import {throttle, commonConst} from './utils';
|
||||
import path from 'path';
|
||||
import fs from "fs";
|
||||
import mito from './monitor';
|
||||
|
||||
const browsers = require("../browsers")();
|
||||
const {picker, separator, superPanel} = browsers;
|
||||
@@ -11,6 +24,7 @@ const {picker, separator, superPanel} = browsers;
|
||||
class Listener {
|
||||
constructor() {
|
||||
this.optionPlugin = {};
|
||||
this.isWin = process.platform === 'win32';
|
||||
}
|
||||
|
||||
getSelectedContent() {
|
||||
@@ -20,8 +34,7 @@ class Listener {
|
||||
clipboard.clear();
|
||||
|
||||
// 复制选中文案
|
||||
const platform = process.platform;
|
||||
if (platform === 'darwin') {
|
||||
if (commonConst.macOS()) {
|
||||
robot.keyTap('c', 'command');
|
||||
} else {
|
||||
robot.keyTap('c', 'control');
|
||||
@@ -31,7 +44,9 @@ class Listener {
|
||||
// 延时一定时间才能从剪切板内读取到内容
|
||||
const text = clipboard.readText('clipboard') || ''
|
||||
const fileUrl = clipboard.read('public.file-url');
|
||||
|
||||
if (this.isWin) {
|
||||
// todo https://github.com/njzydark/Aragorn/blob/afe4a60972b4255dd417480ca6aca2af1fd8e637/packages/aragorn-app-main/src/uploaderManager.ts#L88
|
||||
}
|
||||
// 如果之前是文案,则回填
|
||||
clipboard.writeText(lastText);
|
||||
|
||||
@@ -49,12 +64,14 @@ class Listener {
|
||||
// 注册偏好快捷键
|
||||
globalShortcut.register(config.perf.shortCut.showAndHidden, () => {
|
||||
const {x, y} = screen.getCursorScreenPoint();
|
||||
const currentDisplay = screen.getDisplayNearestPoint({ x, y });
|
||||
const currentDisplay = screen.getDisplayNearestPoint({x, y});
|
||||
const wx = parseInt(currentDisplay.workArea.x + currentDisplay.workArea.width / 2 - 400);
|
||||
const wy = parseInt(currentDisplay.workArea.y + currentDisplay.workArea.height / 2 - 200);
|
||||
mainWindow.setVisibleOnAllWorkspaces(true);
|
||||
|
||||
mainWindow.setAlwaysOnTop(true)
|
||||
mainWindow.setVisibleOnAllWorkspaces(true, {visibleOnFullScreen: true});
|
||||
mainWindow.focus();
|
||||
mainWindow.setVisibleOnAllWorkspaces(false);
|
||||
mainWindow.setVisibleOnAllWorkspaces(false, {visibleOnFullScreen: true});
|
||||
mainWindow.setPosition(wx, wy);
|
||||
mainWindow.show();
|
||||
});
|
||||
@@ -63,6 +80,11 @@ class Listener {
|
||||
mainWindow.webContents.send('new-window');
|
||||
});
|
||||
|
||||
globalShortcut.register(config.perf.shortCut.quit, () => {
|
||||
mainWindow.webContents.send('init-rubick');
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
// 注册自定义全局快捷键
|
||||
config.global.forEach(sc => {
|
||||
if (!sc.key || !sc.value) return;
|
||||
@@ -74,11 +96,17 @@ class Listener {
|
||||
|
||||
init(mainWindow) {
|
||||
this.fn = throttle(({x, y}, picker) => {
|
||||
const img = robot.screen.capture(parseInt(x) - 5, parseInt(y) - 5, 9, 9);
|
||||
const {scaleFactor} = screen.getDisplayNearestPoint({x, y});
|
||||
const img = robot.screen.capture(
|
||||
x - parseInt(5 / scaleFactor),
|
||||
y - parseInt(5 / scaleFactor),
|
||||
10,
|
||||
10
|
||||
);
|
||||
|
||||
const colors = {}
|
||||
|
||||
for(let i = 0; i< 9; i++) {
|
||||
for (let i = 0; i < 9; i++) {
|
||||
colors[i] = {};
|
||||
for (let j = 0; j < 9; j++) {
|
||||
colors[i][j] = img.colorAt(j, i);
|
||||
@@ -87,15 +115,18 @@ class Listener {
|
||||
picker.getWindow().webContents.send("updatePicker", colors);
|
||||
}, 100);
|
||||
|
||||
this.setAutoLogin();
|
||||
this.colorPicker();
|
||||
this.initPlugin();
|
||||
this.lockScreen();
|
||||
this.separate();
|
||||
this.initCapture();
|
||||
this.initTouchBar(mainWindow);
|
||||
this.superPanel(mainWindow);
|
||||
this.reRegisterShortCut(mainWindow);
|
||||
this.changeSize(mainWindow);
|
||||
this.msgTrigger(mainWindow);
|
||||
this.windowMoveInit(mainWindow);
|
||||
}
|
||||
|
||||
colorPicker() {
|
||||
@@ -103,15 +134,16 @@ class Listener {
|
||||
ipcMain.on('start-picker', () => {
|
||||
// 开启输入侦测
|
||||
ioHook.start(false);
|
||||
ioHook.load();
|
||||
!this.isWin && ioHook.load();
|
||||
picker.init();
|
||||
|
||||
picker.getWindow().on('close', () => {
|
||||
ioHook.stop();
|
||||
ioHook.unload();
|
||||
ioHook.removeAllListeners();
|
||||
!this.isWin && ioHook.unload();
|
||||
});
|
||||
|
||||
let pos = robot.getMousePos();
|
||||
let pos = this.getPos(robot.getMousePos());
|
||||
picker
|
||||
.getWindow()
|
||||
.setPosition(parseInt(pos.x) + 10, parseInt(pos.y) + 10);
|
||||
@@ -120,7 +152,7 @@ class Listener {
|
||||
|
||||
const colors = {}
|
||||
|
||||
for(let i = 0; i< 9; i++) {
|
||||
for (let i = 0; i < 9; i++) {
|
||||
colors[i] = {};
|
||||
for (let j = 0; j < 9; j++) {
|
||||
colors[i][j] = img.colorAt(j, i);
|
||||
@@ -137,30 +169,30 @@ class Listener {
|
||||
ipcMain.on("closePicker", () => {
|
||||
this.closePicker();
|
||||
});
|
||||
});
|
||||
ioHook.on('mousemove', e => {
|
||||
let x = e.x
|
||||
let y = e.y
|
||||
if (!picker.getWindow()) return;
|
||||
picker.getWindow().setPosition(parseInt(x) + 10, parseInt(y) + 10);
|
||||
this.fn(e, picker);
|
||||
})
|
||||
|
||||
ioHook.on('mouseup', e => {
|
||||
if (e.button === 1) {
|
||||
let x = e.x
|
||||
let y = e.y
|
||||
const color = "#" + robot.getPixelColor(parseInt(x), parseInt(y));
|
||||
clipboard.writeText("#" + robot.getPixelColor(parseInt(x), parseInt(y)));
|
||||
new Notification({ title: 'Rubick 通知', body: `${color} 已保存到剪切板` }).show();
|
||||
this.closePicker();
|
||||
}
|
||||
});
|
||||
ioHook.on('mousemove', e => {
|
||||
let {x, y} = this.getPos(e);
|
||||
if (!picker.getWindow()) return;
|
||||
picker.getWindow().setPosition(parseInt(x) + 10, parseInt(y) + 10);
|
||||
this.fn(e, picker);
|
||||
})
|
||||
|
||||
ioHook.on('mouseup', e => {
|
||||
if (e.button === 3) {
|
||||
this.closePicker()
|
||||
}
|
||||
ioHook.on('mouseup', e => {
|
||||
if (e.button === 1) {
|
||||
let x = e.x
|
||||
let y = e.y
|
||||
const color = "#" + robot.getPixelColor(parseInt(x), parseInt(y));
|
||||
clipboard.writeText("#" + robot.getPixelColor(parseInt(x), parseInt(y)));
|
||||
new Notification({title: 'Rubick 通知', body: `${color} 已保存到剪切板`}).show();
|
||||
this.closePicker();
|
||||
}
|
||||
});
|
||||
|
||||
ioHook.on('mouseup', e => {
|
||||
if (e.button === 3) {
|
||||
this.closePicker()
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -171,6 +203,72 @@ class Listener {
|
||||
}
|
||||
}
|
||||
|
||||
initTouchBar(mainWindow) {
|
||||
if (!commonConst.macOS()) return;
|
||||
const {TouchBarButton, TouchBarGroup, TouchBarPopover} = TouchBar;
|
||||
let items = [];
|
||||
let system = [];
|
||||
ipcMain.on('pluginInit', (e, args) => {
|
||||
this.optionPlugin = args;
|
||||
items = args.plugins.map((item) => {
|
||||
const iconPath = path.join(item.sourceFile, '../', item.logo);
|
||||
if (!fs.existsSync(iconPath)) return false;
|
||||
const icon = nativeImage.createFromPath(iconPath).resize({width: 20, height: 20});
|
||||
|
||||
return new TouchBarButton({
|
||||
icon,
|
||||
click() {
|
||||
mainWindow.webContents.send('superPanel-openPlugin', {
|
||||
cmd: item.features[0].cmds.filter(cmd => typeof cmd === 'string')[0],
|
||||
plugin: item,
|
||||
feature: item.features[0],
|
||||
});
|
||||
}
|
||||
})
|
||||
}).filter(Boolean);
|
||||
|
||||
system = args.plugins.map((item) => {
|
||||
if (item.type === 'system') {
|
||||
return new TouchBarButton({
|
||||
icon: nativeImage.createFromDataURL(item.logo).resize({width: 20, height: 20}),
|
||||
click() {
|
||||
mainWindow.webContents.send('superPanel-openPlugin', {
|
||||
cmd: item.features[0].cmds.filter(cmd => typeof cmd === 'string')[0],
|
||||
plugin: item,
|
||||
feature: item.features[0],
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}).filter(Boolean);
|
||||
|
||||
const plugin = new TouchBarPopover({
|
||||
items: new TouchBar({
|
||||
items,
|
||||
}),
|
||||
label: '已安装插件',
|
||||
showCloseButton: true
|
||||
});
|
||||
|
||||
const monitor = new TouchBarPopover({
|
||||
items: mito.touchBar,
|
||||
label: '系统监控',
|
||||
showCloseButton: true
|
||||
});
|
||||
|
||||
const touchBar = new TouchBar({
|
||||
items: [
|
||||
plugin,
|
||||
monitor,
|
||||
...system
|
||||
]
|
||||
});
|
||||
mainWindow.setTouchBar(touchBar);
|
||||
mito.start(mainWindow);
|
||||
});
|
||||
}
|
||||
|
||||
initPlugin() {
|
||||
ipcMain.on('optionPlugin', (e, args) => {
|
||||
this.optionPlugin = args;
|
||||
@@ -191,38 +289,47 @@ class Listener {
|
||||
|
||||
superPanel(mainWindow) {
|
||||
// 长按右击呼起超级面板
|
||||
superPanel.init(mainWindow);
|
||||
ipcMain.on('right-down', async () => {
|
||||
|
||||
const copyResult = await this.getSelectedContent();
|
||||
let win = superPanel.getWindow();
|
||||
|
||||
if (win) {
|
||||
win.webContents.send('trigger-super-panel', {
|
||||
...copyResult,
|
||||
optionPlugin: this.optionPlugin.plugins,
|
||||
});
|
||||
} else {
|
||||
superPanel.init(mainWindow);
|
||||
win = superPanel.getWindow();
|
||||
|
||||
win.once('ready-to-show', () => {
|
||||
win.webContents.send('trigger-super-panel', {
|
||||
...copyResult,
|
||||
optionPlugin: this.optionPlugin.plugins,
|
||||
});
|
||||
});
|
||||
}
|
||||
const pos = robot.getMousePos();
|
||||
win.webContents.send('trigger-super-panel', {
|
||||
...copyResult,
|
||||
optionPlugin: this.optionPlugin.plugins,
|
||||
});
|
||||
const pos = this.getPos(robot.getMousePos());
|
||||
win.setPosition(parseInt(pos.x), parseInt(pos.y));
|
||||
win.setAlwaysOnTop(true);
|
||||
win.setVisibleOnAllWorkspaces(true, {visibleOnFullScreen: true});
|
||||
win.focus();
|
||||
win.setVisibleOnAllWorkspaces(false, {visibleOnFullScreen: true});
|
||||
win.show();
|
||||
});
|
||||
}
|
||||
|
||||
getPos(point) {
|
||||
return this.isWin ? screen.screenToDipPoint({x: point.x, y: point.y}) : point;
|
||||
}
|
||||
|
||||
reRegisterShortCut(mainWindow) {
|
||||
ipcMain.on('re-register', (event, arg) => {
|
||||
this.setAutoLogin();
|
||||
this.registerShortCut(mainWindow);
|
||||
});
|
||||
}
|
||||
|
||||
setAutoLogin() {
|
||||
// 设置开机启动
|
||||
const config = global.opConfig.get();
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin: config.perf.common.start,
|
||||
openAsHidden: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
changeSize(mainWindow) {
|
||||
// 修改窗口尺寸
|
||||
ipcMain.on('changeWindowSize-rubick', (event, arg) => {
|
||||
@@ -257,7 +364,42 @@ class Listener {
|
||||
|
||||
initCapture() {
|
||||
ipcMain.on('capture-screen', () => {
|
||||
spawn('/usr/sbin/screencapture', ["-c", "-i", "-r"], {detached: !0});
|
||||
if (process.platform === 'darwin') {
|
||||
spawn('/usr/sbin/screencapture', ["-c", "-i", "-r"], {detached: !0});
|
||||
}
|
||||
// todo win
|
||||
});
|
||||
}
|
||||
|
||||
windowMoveInit(win) {
|
||||
let hasInit = false;
|
||||
ipcMain.on('window-move', () => {
|
||||
let bounds = win.getBounds();
|
||||
if (!hasInit) {
|
||||
hasInit = true;
|
||||
ioHook.start(false);
|
||||
!this.isWin && ioHook.load();
|
||||
|
||||
const winPosition = win.getPosition();
|
||||
const winStartPosition = { x: winPosition[0], y: winPosition[1] };
|
||||
const mouseStartPosition = screen.getCursorScreenPoint();
|
||||
|
||||
ioHook.on('mousedrag', e => {
|
||||
const cursorPosition = screen.getCursorScreenPoint();
|
||||
const dx = winStartPosition.x + cursorPosition.x - mouseStartPosition.x;
|
||||
const dy = winStartPosition.y + cursorPosition.y - mouseStartPosition.y;
|
||||
bounds.x = parseInt(dx);
|
||||
bounds.y = parseInt(dy);
|
||||
win.setBounds(bounds);
|
||||
});
|
||||
|
||||
ioHook.on('mouseup', e => {
|
||||
hasInit = false;
|
||||
ioHook.stop();
|
||||
ioHook.removeAllListeners();
|
||||
!this.isWin && ioHook.unload();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
124
src/main/common/monitor.js
Normal file
@@ -0,0 +1,124 @@
|
||||
const {TouchBar} = require('electron')
|
||||
const path = require('path')
|
||||
const si = require('systeminformation');
|
||||
const spawn = require('child_process').spawn;
|
||||
|
||||
const {TouchBarButton, TouchBarSpacer} = TouchBar;
|
||||
|
||||
const LOAD_NORMAL = "#2ecc71";
|
||||
const LOAD_MEDIUM = "#f1c40f";
|
||||
const LOAD_HIGH = "#d35400";
|
||||
const LOAD_SEVERE = "#e74c3c";
|
||||
|
||||
const cpu = new TouchBarButton({
|
||||
label: '',
|
||||
backgroundColor: "#bdc3c7",
|
||||
icon: path.join(__dirname, 'icons/chip.png'),
|
||||
iconPosition: "left",
|
||||
click: () => {
|
||||
spawn("/System/Applications/Utilities/Activity Monitor.app/Contents/MacOS/Activity\ Monitor", []);
|
||||
}
|
||||
});
|
||||
|
||||
const memory = new TouchBarButton({
|
||||
label: '',
|
||||
backgroundColor: "#bdc3c7",
|
||||
icon: path.join(__dirname, 'icons/ram.png'),
|
||||
iconPosition: "left"
|
||||
});
|
||||
|
||||
const network = new TouchBarButton({
|
||||
label: '',
|
||||
backgroundColor: '#3498db',
|
||||
icon: path.join(__dirname, 'icons/internet.png'),
|
||||
iconPosition: "left"
|
||||
});
|
||||
|
||||
const battery = new TouchBarButton({
|
||||
label: '',
|
||||
backgroundColor: "#bdc3c7",
|
||||
icon: path.join(__dirname, 'icons/power.png'),
|
||||
iconPosition: "left"
|
||||
});
|
||||
|
||||
const updateData = () => {
|
||||
si.currentLoad(function(data) {
|
||||
if (typeof data !== 'undefined' && data){
|
||||
const load = data.currentLoad.toFixed(0)
|
||||
cpu.label = load+"%"
|
||||
if (load <= 20) cpu.backgroundColor = LOAD_NORMAL;
|
||||
else if (load > 20 && load <= 40) cpu.backgroundColor = LOAD_MEDIUM;
|
||||
else if (load > 40 && load <= 80) cpu.backgroundColor = LOAD_HIGH;
|
||||
else if (load > 80 && load <= 100) cpu.backgroundColor = LOAD_SEVERE;
|
||||
}
|
||||
})
|
||||
si.mem(function(data) {
|
||||
if (typeof data !== 'undefined' && data){
|
||||
const load = ((100* data.active ) / data.total).toFixed(0)
|
||||
memory.label = load+"%"
|
||||
if (load <= 20) memory.backgroundColor = LOAD_NORMAL;
|
||||
else if (load > 20 && load <= 40) memory.backgroundColor = LOAD_MEDIUM;
|
||||
else if (load > 40 && load <= 80) memory.backgroundColor = LOAD_HIGH;
|
||||
else if (load > 80 && load <= 100) memory.backgroundColor = LOAD_SEVERE;
|
||||
}
|
||||
|
||||
})
|
||||
si.networkStats("", function(data) {
|
||||
if (typeof data !== 'undefined' && data){
|
||||
const kbtx = (data[0].tx_sec * 0.001).toFixed(0)
|
||||
const kbrx = (data[0].rx_sec * 0.001).toFixed(0)
|
||||
const l = (kbtx+kbrx).toString().length
|
||||
|
||||
network.label = "⇡"+ (kbtx*0.001).toFixed(2)
|
||||
+" ⇣"+ (kbrx*0.001).toFixed(2) +" MB/s"
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
si.battery( function(data) {
|
||||
if (typeof data !== 'undefined' && data){
|
||||
if (data.ischarging){
|
||||
battery.icon = path.join(__dirname, 'icons/charger.png')
|
||||
}else{
|
||||
battery.icon = path.join(__dirname, 'icons/power.png')
|
||||
}
|
||||
const load = data.percent.toFixed(0)
|
||||
battery.label = load+"%"
|
||||
if (load <= 20) battery.backgroundColor = LOAD_SEVERE;
|
||||
else if (load > 20 && load <= 40) battery.backgroundColor = LOAD_HIGH;
|
||||
else if (load > 40 && load <= 80) battery.backgroundColor = LOAD_MEDIUM;
|
||||
else if (load > 80 && load <= 100) battery.backgroundColor = LOAD_NORMAL
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const touchBar = new TouchBar({
|
||||
items: [
|
||||
cpu,
|
||||
new TouchBarSpacer({size: 'small'}),
|
||||
memory,
|
||||
new TouchBarSpacer({size: 'small'}),
|
||||
network,
|
||||
new TouchBarSpacer({size: 'small'}),
|
||||
battery,
|
||||
]
|
||||
})
|
||||
|
||||
let intervalObj;
|
||||
|
||||
const start = (window) => {
|
||||
window.on('blur', () => {
|
||||
clearInterval(intervalObj);
|
||||
});
|
||||
window.on('focus', () => {
|
||||
intervalObj = setInterval(() => {
|
||||
updateData();
|
||||
}, 1000);
|
||||
});
|
||||
updateData();
|
||||
}
|
||||
|
||||
export default {
|
||||
start,
|
||||
touchBar,
|
||||
}
|
||||
@@ -53,3 +53,22 @@ export function throttle (func, wait, options) {
|
||||
};
|
||||
}
|
||||
|
||||
export const commonConst = {
|
||||
linux: function () {
|
||||
return process.platform === 'linux'
|
||||
},
|
||||
macOS () {
|
||||
return process.platform === 'darwin';
|
||||
},
|
||||
windows () {
|
||||
return process.platform === 'win32'
|
||||
},
|
||||
production: function () {
|
||||
return process.env.NODE_ENV !== 'development';
|
||||
},
|
||||
dev: function () {
|
||||
return process.env.NODE_ENV === 'development';
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,38 +1,111 @@
|
||||
import { app } from 'electron'
|
||||
import '../renderer/store'
|
||||
import init from './common/common';
|
||||
import {autoUpdate} from './common/autoUpdate';
|
||||
import createTray from './tray';
|
||||
const {main} = require("./browsers")();
|
||||
/**
|
||||
* Set `__static` path to static files in production
|
||||
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
|
||||
*/
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
import { app, globalShortcut } from 'electron'
|
||||
import init from './common/common'
|
||||
import { autoUpdate } from './common/autoUpdate'
|
||||
import createTray from './tray'
|
||||
import { commonConst } from './common/utils'
|
||||
import pkg from '../../package.json'
|
||||
import Store from 'electron-store';
|
||||
|
||||
Store.initRenderer()
|
||||
|
||||
const { main } = require("./browsers")()
|
||||
|
||||
if (commonConst.production()) {
|
||||
global.__static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\')
|
||||
}
|
||||
// to fix https://github.com/electron/electron/issues/18397
|
||||
app.allowRendererProcessReuse = false;
|
||||
app.dock.hide();
|
||||
app.allowRendererProcessReuse = false
|
||||
|
||||
function createWindow() {
|
||||
main.init();
|
||||
init(main.getWindow());
|
||||
class initApp {
|
||||
launchApp() {
|
||||
const gotTheLock = app.requestSingleInstanceLock()
|
||||
if (!gotTheLock) {
|
||||
app.quit()
|
||||
} else {
|
||||
this.beforeReady()
|
||||
this.onReady()
|
||||
this.onRunning()
|
||||
this.onQuit()
|
||||
}
|
||||
}
|
||||
|
||||
createWindow() {
|
||||
main.init()
|
||||
init(main.getWindow())
|
||||
}
|
||||
|
||||
beforeReady() {
|
||||
// 系统托盘
|
||||
if (commonConst.macOS()) {
|
||||
if (commonConst.production() && !app.isInApplicationsFolder()) {
|
||||
app.moveToApplicationsFolder()
|
||||
} else {
|
||||
app.dock.hide()
|
||||
}
|
||||
} else {
|
||||
app.disableHardwareAcceleration()
|
||||
}
|
||||
}
|
||||
|
||||
onReady() {
|
||||
const readyFunction = () => {
|
||||
this.createWindow()
|
||||
createTray(main.getWindow())
|
||||
autoUpdate()
|
||||
}
|
||||
if (!app.isReady()) {
|
||||
app.on('ready', readyFunction)
|
||||
} else {
|
||||
readyFunction()
|
||||
}
|
||||
}
|
||||
|
||||
onRunning() {
|
||||
app.on('second-instance', (event, commandLine, workingDirectory) => {
|
||||
// 当运行第二个实例时,将会聚焦到myWindow这个窗口
|
||||
const win = main.getWindow()
|
||||
if (win) {
|
||||
if (win.isMinimized()) {
|
||||
win.restore()
|
||||
}
|
||||
win.focus()
|
||||
}
|
||||
})
|
||||
app.on('activate', () => {
|
||||
if (!main.getWindow()) {
|
||||
this.createWindow()
|
||||
}
|
||||
})
|
||||
if (commonConst.windows()) {
|
||||
app.setAppUserModelId(pkg.build.appId)
|
||||
}
|
||||
}
|
||||
|
||||
onQuit() {
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('will-quit', () => {
|
||||
globalShortcut.unregisterAll()
|
||||
})
|
||||
// Exit cleanly on request from parent process in development mode.
|
||||
if (commonConst.dev()) {
|
||||
if (process.platform === 'win32') {
|
||||
process.on('message', data => {
|
||||
if (data === 'graceful-exit') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
process.on('SIGTERM', () => {
|
||||
app.quit()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
app.on('ready', () => {
|
||||
createWindow()
|
||||
createTray(main.getWindow());
|
||||
autoUpdate();
|
||||
})
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
|
||||
app.on('activate', () => {
|
||||
createWindow()
|
||||
});
|
||||
|
||||
(new initApp()).launchApp()
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
import { dialog, Menu, Tray, app, shell, ipcMain } from 'electron';
|
||||
import { dialog, Menu, Tray, app, shell } from 'electron';
|
||||
import path from 'path';
|
||||
import pkg from '../../package.json';
|
||||
import os from 'os';
|
||||
import {commonConst} from './common/utils';
|
||||
|
||||
function createTray(window) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const appIcon = new Tray(path.join(__static, './rocket.png'));
|
||||
let icon;
|
||||
if (commonConst.macOS()) {
|
||||
icon = './icon@3x.png'
|
||||
}else if (commonConst.windows()) {
|
||||
icon = parseInt(os.release()) < 10 ? './icon@2x.png' : './icon.ico';
|
||||
}else {
|
||||
icon = 'icon@2x.png'
|
||||
}
|
||||
const appIcon = new Tray(path.join(__static, icon));
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: "帮助文档", click: () => {
|
||||
|
||||
@@ -1,113 +1,120 @@
|
||||
<template>
|
||||
<a-layout id="components-layout">
|
||||
<div v-if="!searchType" class="rubick-select">
|
||||
<div class="tag-container" v-if="selected">
|
||||
<a-tag
|
||||
:key="selected.key"
|
||||
@close="closeTag"
|
||||
class="select-tag"
|
||||
color="green"
|
||||
closable
|
||||
>
|
||||
{{ selected.name }}
|
||||
</a-tag>
|
||||
</div>
|
||||
<a-input
|
||||
id="search"
|
||||
:placeholder="
|
||||
<div @mousedown="drag" >
|
||||
<a-layout id="components-layout">
|
||||
<div v-if="!searchType" class="rubick-select">
|
||||
<div class="tag-container" v-if="selected">
|
||||
<a-tag
|
||||
:key="selected.key"
|
||||
@close="closeTag"
|
||||
class="select-tag"
|
||||
color="green"
|
||||
closable
|
||||
>
|
||||
{{ selected.name }}
|
||||
</a-tag>
|
||||
</div>
|
||||
<a-input
|
||||
id="search"
|
||||
:placeholder="
|
||||
subPlaceHolder && selected && selected.key === 'plugin-container'
|
||||
? subPlaceHolder
|
||||
: 'Hi, Rubick'
|
||||
"
|
||||
class="main-input"
|
||||
@change="(e) => search({ value: e.target.value })"
|
||||
:value="searchValue"
|
||||
:maxLength="selected && selected.key !== 'plugin-container' ? 0 : 1000"
|
||||
@keydown.down="(e) => changeCurrent(1)"
|
||||
@keydown.up="() => changeCurrent(-1)"
|
||||
@keypress.enter="
|
||||
class="main-input"
|
||||
@change="(e) => search({ value: e.target.value })"
|
||||
@keydown.ctrl.86="shouldPaste"
|
||||
:value="searchValue"
|
||||
:maxLength="selected && selected.key !== 'plugin-container' ? 0 : 1000"
|
||||
@keydown.down="(e) => changeCurrent(1)"
|
||||
@keydown.up="() => changeCurrent(-1)"
|
||||
@keypress.enter="
|
||||
(e) => targetSearch({ value: e.target.value, type: 'enter' })
|
||||
"
|
||||
@keypress.space="
|
||||
@keypress.space="
|
||||
(e) => targetSearch({ value: e.target.value, type: 'space' })
|
||||
"
|
||||
>
|
||||
<div @click="goMenu" class="suffix-tool" slot="suffix">
|
||||
<a-icon
|
||||
v-show="selected && selected.key === 'plugin-container'"
|
||||
class="icon-more"
|
||||
type="more"
|
||||
/>
|
||||
<img
|
||||
class="icon-tool"
|
||||
v-if="selected && selected.icon"
|
||||
:src="selected.icon"
|
||||
/>
|
||||
<div v-else class="rubick-logo">
|
||||
<img src="./assets/logo.png" />
|
||||
</div>
|
||||
</div>
|
||||
</a-input>
|
||||
<div class="options" v-show="showOptions">
|
||||
<a-list item-layout="horizontal" :data-source="options">
|
||||
<a-list-item
|
||||
@click="() => item.click($router)"
|
||||
:class="currentSelect === index ? 'active op-item' : 'op-item'"
|
||||
slot="renderItem"
|
||||
slot-scope="item, index"
|
||||
>
|
||||
<a-list-item-meta :description="item.desc">
|
||||
<span slot="title" v-html="renderTitle(item.name)"></span>
|
||||
<a-avatar
|
||||
slot="avatar"
|
||||
style="border-radius: 0"
|
||||
:src="item.icon"
|
||||
>
|
||||
<div @click="goMenu" class="suffix-tool" slot="suffix">
|
||||
<a-icon
|
||||
v-show="selected && selected.key === 'plugin-container'"
|
||||
class="icon-more"
|
||||
type="more"
|
||||
/>
|
||||
<div v-if="selected && selected.icon" style="position: relative">
|
||||
<a-spin v-show="pluginLoading" class="loading">
|
||||
<a-icon slot="indicator" type="loading" style="font-size: 42px" spin />
|
||||
</a-spin>
|
||||
<img
|
||||
class="icon-tool"
|
||||
:src="selected.icon"
|
||||
/>
|
||||
</a-list-item-meta>
|
||||
<a-tag v-show="item.type === 'dev'">开发者</a-tag>
|
||||
<a-tag v-show="item.type === 'system'">系统</a-tag>
|
||||
</a-list-item>
|
||||
</a-list>
|
||||
</div>
|
||||
<div v-else class="rubick-logo">
|
||||
<img src="./assets/imgs/logo.png" />
|
||||
</div>
|
||||
</div>
|
||||
</a-input>
|
||||
<div class="options" v-show="showOptions">
|
||||
<a-list item-layout="horizontal" :data-source="options">
|
||||
<a-list-item
|
||||
@click="() => item.click($router)"
|
||||
:class="currentSelect === index ? 'active op-item' : 'op-item'"
|
||||
slot="renderItem"
|
||||
slot-scope="item, index"
|
||||
>
|
||||
<a-list-item-meta :description="item.desc">
|
||||
<span slot="title" v-html="renderTitle(item.name)"></span>
|
||||
<a-avatar
|
||||
slot="avatar"
|
||||
style="border-radius: 0"
|
||||
:src="item.icon"
|
||||
/>
|
||||
</a-list-item-meta>
|
||||
<a-tag v-show="item.type === 'dev'">开发者</a-tag>
|
||||
<a-tag v-show="item.type === 'system'">系统</a-tag>
|
||||
</a-list-item>
|
||||
</a-list>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="rubick-select-subMenu" v-else>
|
||||
<div>
|
||||
<img
|
||||
class="icon-tool-sub"
|
||||
v-if="pluginInfo.icon"
|
||||
:src="pluginInfo.icon"
|
||||
/>
|
||||
<a-input
|
||||
:placeholder="subPlaceHolder"
|
||||
class="sub-input"
|
||||
@change="
|
||||
<div class="rubick-select-subMenu" v-else>
|
||||
<div>
|
||||
<img
|
||||
class="icon-tool-sub"
|
||||
v-if="pluginInfo.icon"
|
||||
:src="pluginInfo.icon"
|
||||
/>
|
||||
<a-input
|
||||
:placeholder="subPlaceHolder"
|
||||
class="sub-input"
|
||||
@change="
|
||||
(e) =>
|
||||
search({
|
||||
value: e.target.value,
|
||||
searchType: pluginInfo.searchType,
|
||||
})
|
||||
"
|
||||
:value="searchValue"
|
||||
@keypress.enter="
|
||||
:value="searchValue"
|
||||
@keypress.enter="
|
||||
(e) => targetSearch({ value: e.target.value, type: 'enter' })
|
||||
"
|
||||
@keypress.space="
|
||||
@keypress.space="
|
||||
(e) => targetSearch({ value: e.target.value, type: 'space' })
|
||||
"
|
||||
></a-input>
|
||||
</div>
|
||||
></a-input>
|
||||
</div>
|
||||
|
||||
<div class="icon-container">
|
||||
<a-icon class="icon" type="info-circle" />
|
||||
<a-icon class="icon" @click="goMenu('separate')" type="setting" />
|
||||
<div class="icon-container">
|
||||
<a-icon class="icon" type="info-circle" />
|
||||
<a-icon class="icon" @click="goMenu('separate')" type="setting" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<router-view></router-view>
|
||||
</a-layout>
|
||||
<router-view></router-view>
|
||||
</a-layout>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import { mapActions, mapMutations, mapState } from "vuex";
|
||||
import { ipcRenderer, remote } from "electron";
|
||||
import { ipcRenderer, remote, clipboard } from "electron";
|
||||
import {
|
||||
getWindowHeight,
|
||||
debounce,
|
||||
@@ -161,7 +168,18 @@ export default {
|
||||
feature.forEach((fe) => {
|
||||
const cmd = searchKeyValues(fe.cmds, args)[0];
|
||||
const systemPlugin = fileLists.filter(
|
||||
(plugin) => plugin.name.indexOf(args) >= 0
|
||||
(plugin) => {
|
||||
let has = false;
|
||||
plugin.keyWords.some(keyWord => {
|
||||
if (keyWord.toLocaleUpperCase().indexOf(args.toLocaleUpperCase()) >= 0) {
|
||||
has = keyWord;
|
||||
plugin.name = keyWord;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return has;
|
||||
}
|
||||
)[0];
|
||||
if (cmd) {
|
||||
config = {
|
||||
@@ -191,6 +209,18 @@ export default {
|
||||
methods: {
|
||||
...mapActions("main", ["onSearch", "showMainUI", "openPlugin"]),
|
||||
...mapMutations("main", ["commonUpdate"]),
|
||||
shouldPaste(e) {
|
||||
let filePath = '';
|
||||
if (process.platform === 'win32') {
|
||||
const rawFilePath = clipboard.read('FileNameW');
|
||||
filePath = rawFilePath.replace(new RegExp(String.fromCharCode(0), 'g'), '');
|
||||
if (filePath.indexOf('plugin.json') >= 0) {
|
||||
this.search({
|
||||
filePath,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
search(v) {
|
||||
if (!this.searchFn) {
|
||||
this.searchFn = debounce(this.onSearch, 200);
|
||||
@@ -309,6 +339,9 @@ export default {
|
||||
this.showMainUI();
|
||||
this.changePath({ key: "market" });
|
||||
},
|
||||
drag() {
|
||||
ipcRenderer.send('window-move');
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState("main", [
|
||||
@@ -320,6 +353,7 @@ export default {
|
||||
"searchValue",
|
||||
"subPlaceHolder",
|
||||
"pluginInfo",
|
||||
"pluginLoading",
|
||||
]),
|
||||
showOptions() {
|
||||
// 有选项值,且不在显示主页
|
||||
@@ -358,13 +392,13 @@ export default {
|
||||
.rubick-logo {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background: #314659;
|
||||
background: #574778;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 100%;
|
||||
img {
|
||||
width: 28px;
|
||||
width: 32px;
|
||||
}
|
||||
}
|
||||
.tag-container {
|
||||
@@ -444,5 +478,10 @@ export default {
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
}
|
||||
.loading {
|
||||
position:absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
10
src/renderer/assets/ant-reset.less
Normal file
@@ -0,0 +1,10 @@
|
||||
@import '~ant-design-vue/dist/antd.less'; // 引入官方提供的 less 样式入口文件
|
||||
|
||||
@primary-color: #ff4ea4; // 全局主色
|
||||
@link-color: #ff4ea4; // 链接色
|
||||
@error-color: #ff4ea4; // 错误色
|
||||
.ant-tag-green {
|
||||
color: #ff4ea4;
|
||||
background: rgba(255, 159, 180, 0.3);
|
||||
border-color: #ff9fb4;
|
||||
}
|
||||
@@ -22,7 +22,7 @@ const SYSTEM_PLUGINS = [
|
||||
{
|
||||
code: 'pick',
|
||||
explain: 'rubick 帮助文档',
|
||||
cmds: ['取色', '拾色', 'Pick color']
|
||||
cmds: ['取色', '拾色', 'Pick color', 'qs', 'ss']
|
||||
}
|
||||
],
|
||||
tag: 'rubick-color'
|
||||
@@ -34,7 +34,7 @@ const SYSTEM_PLUGINS = [
|
||||
{
|
||||
code: 'shortCut',
|
||||
explain: 'rubick 屏幕截取',
|
||||
cmds: ['截屏', 'shortCut']
|
||||
cmds: ['截屏', 'shortCut', 'jp']
|
||||
}
|
||||
],
|
||||
tag: 'rubick-screen-short-cut'
|
||||
@@ -46,13 +46,13 @@ const SYSTEM_PLUGINS = [
|
||||
{
|
||||
code: 'lock',
|
||||
explain: '锁屏',
|
||||
cmds: ['锁屏', 'lock screen']
|
||||
cmds: ['锁屏', 'lock screen', 'sp']
|
||||
}
|
||||
],
|
||||
tag: 'rubick-lock'
|
||||
}
|
||||
];
|
||||
|
||||
const APP_FINDER_PATH = ['/System/Applications', '/Applications', '/System/Library/PreferencePanes'];
|
||||
const APP_FINDER_PATH = process.platform === 'darwin' ? ['/System/Applications', '/Applications', '/System/Library/PreferencePanes'] : [];
|
||||
|
||||
export { WINDOW_MAX_HEIGHT, WINDOW_MIN_HEIGHT, PRE_ITEM_HEIGHT, SYSTEM_PLUGINS, APP_FINDER_PATH };
|
||||
|
||||
120
src/renderer/assets/common/darwin-app.js
Normal file
@@ -0,0 +1,120 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import {nativeImage} from "electron";
|
||||
import translate from "./translate";
|
||||
import {APP_FINDER_PATH} from "./constans";
|
||||
import iconvLite from "iconv-lite";
|
||||
import bpList from "bplist-parser";
|
||||
|
||||
const fileLists = [];
|
||||
|
||||
const isZhRegex = /[\u4e00-\u9fa5]/;
|
||||
const getDisplayNameRegex = /\"(?:CFBundleDisplayName)\"\s\=\s\"(.*)\"/;
|
||||
|
||||
async function getAppZhName(rootPath, appName) {
|
||||
try {
|
||||
const ERROR_RESULT = '';
|
||||
const systemPath = path.join(rootPath, `${appName}/Contents/Resources/zh_CN.lproj/InfoPlist.strings`);
|
||||
const customizePath = path.join(rootPath, `${appName}/Contents/Resources/zh-Hans.lproj/InfoPlist.strings`);
|
||||
let appInfoPath = '';
|
||||
|
||||
if (fs.existsSync(systemPath)) {
|
||||
appInfoPath = systemPath;
|
||||
} else if (fs.existsSync(customizePath)) {
|
||||
appInfoPath = customizePath;
|
||||
} else {
|
||||
return ERROR_RESULT;
|
||||
}
|
||||
let appZhName = '';
|
||||
if (rootPath == '/Applications') {
|
||||
const container = iconvLite.decode(fs.readFileSync(appInfoPath), 'utf-16');
|
||||
if (container) {
|
||||
const res = container.match(getDisplayNameRegex);
|
||||
appZhName = res && res[1];
|
||||
} else {
|
||||
return ERROR_RESULT;
|
||||
}
|
||||
} else {
|
||||
const [{ CFBundleDisplayName = '', CFBundleName = '' }] = await bpList.parseFile(appInfoPath);
|
||||
appZhName = CFBundleDisplayName || CFBundleName;
|
||||
}
|
||||
|
||||
return appZhName;
|
||||
} catch (error) {
|
||||
return ERROR_RESULT;
|
||||
}
|
||||
}
|
||||
|
||||
function getDarwinAppList () {
|
||||
APP_FINDER_PATH.forEach((searchPath, index) => {
|
||||
fs.readdir(searchPath, async (err, files) => {
|
||||
try {
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const appName = files[i];
|
||||
const extname = path.extname(appName);
|
||||
const appSubStr = appName.split(extname)[0];
|
||||
if ((extname === '.app' || extname === '.prefPane') >= 0) {
|
||||
try {
|
||||
const path1 = path.join(searchPath, `${appName}/Contents/Resources/App.icns`);
|
||||
const path2 = path.join(searchPath, `${appName}/Contents/Resources/AppIcon.icns`);
|
||||
const path3 = path.join(searchPath, `${appName}/Contents/Resources/${appSubStr}.icns`);
|
||||
const path4 = path.join(searchPath, `${appName}/Contents/Resources/${appSubStr.replace(' ', '')}.icns`);
|
||||
let iconPath = path1;
|
||||
if (fs.existsSync(path1)) {
|
||||
iconPath = path1;
|
||||
} else if (fs.existsSync(path2)) {
|
||||
iconPath = path2;
|
||||
} else if (fs.existsSync(path3)) {
|
||||
iconPath = path3;
|
||||
} else if (fs.existsSync(path4)) {
|
||||
iconPath = path4;
|
||||
} else {
|
||||
// 性能最低的方式
|
||||
const resourceList = fs.readdirSync(path.join(searchPath, `${appName}/Contents/Resources`));
|
||||
const iconName = resourceList.filter((file) => path.extname(file) === '.icns')[0];
|
||||
iconPath = path.join(searchPath, `${appName}/Contents/Resources/${iconName}`);
|
||||
}
|
||||
const img = await nativeImage.createThumbnailFromPath(iconPath, { width: 64, height: 64 });
|
||||
|
||||
const appZhName = await getAppZhName(searchPath, appName);
|
||||
|
||||
const fileOptions = {
|
||||
value: 'plugin',
|
||||
icon: img.toDataURL(),
|
||||
desc: path.join(searchPath, appName),
|
||||
type: 'app',
|
||||
action: `open ${path.join(searchPath, appName).replace(' ', '\\ ')}`,
|
||||
keyWords: [appSubStr]
|
||||
};
|
||||
|
||||
if (appZhName && isZhRegex.test(appZhName)) {
|
||||
const py = translate(appZhName);
|
||||
const pinyinArr = py.split(',');
|
||||
const firstLatter = pinyinArr.map(py => py[0]);
|
||||
// 拼音
|
||||
fileOptions.keyWords.push(pinyinArr.join(''));
|
||||
// 缩写
|
||||
fileOptions.keyWords.push(firstLatter.join(''));
|
||||
// 中文
|
||||
fileOptions.keyWords.push(appZhName);
|
||||
}
|
||||
|
||||
fileLists.push({
|
||||
...fileOptions,
|
||||
name: appSubStr,
|
||||
names: JSON.parse(JSON.stringify(fileOptions.keyWords)),
|
||||
});
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export const getApp = {
|
||||
init: getDarwinAppList,
|
||||
fileLists,
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import {shell, ipcRenderer} from 'electron';
|
||||
export default {
|
||||
'rubick-help': {
|
||||
help() {
|
||||
shell.openExternal('https://u.tools/docs/guide/about-uTools.html')
|
||||
shell.openExternal('https://cloudr-f2e.github.io/rubick/')
|
||||
}
|
||||
},
|
||||
'rubick-color': {
|
||||
|
||||
37
src/renderer/assets/common/translate.js
Normal file
@@ -0,0 +1,37 @@
|
||||
let key = '吖哎安肮凹八挀扳邦勹陂奔伻皀边灬憋汃冫癶峬嚓偲参仓撡冊嵾噌叉犲辿伥抄车抻阷吃充抽出膗巛刅吹旾踔呲从凑粗汆镩蹿崔邨搓咑呆丹当刀恴揼灯仾嗲敁刁爹丁丟东吺剢耑叾吨多妸奀鞥仒发帆匚飞分丰覅仏垺夫旮侅干冈皋戈给根更工勾估瓜乖关光归丨呙妎咍兯夯茠诃黒拫亨乊叿齁乎花怀欢巟灰昏吙丌加戋江艽阶巾坕冂丩凥姢噘军咔开刊忼尻匼肎劥空廤扝夸蒯宽匡亏坤扩垃来兰啷捞仂雷塄唎俩嫾簗蹽咧厸伶溜咯龙娄噜驴孪掠抡捋嘸妈埋颟牤猫庅呅椚掹踎宀喵乜民名谬摸哞某母拏腉囡囔孬疒娞嫩莻妮拈娘鸟捏脌宁妞农羺奴女疟奻硸噢妑拍眅乓抛呸喷匉丕片剽氕姘乒钋剖仆七掐千呛悄切亲靑宆丘区峑炔夋亽呥穣荛惹人扔日戎厹嶿堧桵闰挼仨毢三桒掻色杀筛山伤弰奢申升尸収书刷衰闩双谁妁厶忪凁苏狻夊孙唆他囼坍汤仐忑膯剔天旫怗厅囲偷凸湍推吞乇屲歪乛尣危塭翁挝乌夕呷仙乡灱些忄兴凶休戌吅疶坃丫咽央幺倻膶一乚应哟佣优扜囦曰蒀帀災兂牂傮啫贼怎曽吒夈沾张佋蜇贞凧之中州朱抓拽专妆隹宒卓仔孖宗邹租劗厜尊昨'.split('');
|
||||
let pinyin = 'AAiAnAngAoBaBaiBanBangBaoBeiBenBengBiBianBiaoBieBinBingBoBuCaCaiCanCangCaoCeCenCengChaChaiChanChangChaoCheChenChengChiChongChouChuChuaiChuanChuangChuiChunChuoCiCongCouCuCuanChuanCuanCuiCunCuoDaDaiDanDangDaoDeDenDengDiDiaDianDiaoDieDingDiuDongDouDuDuanDuiDunDuoEEnEngErFaFanFangFeiFenFengFiaoFoFouFuGaGaiGanGangGaoGeGeiGenGengGongGouGuGuaGuaiGuanGuangGuiGunGuoHaHaiHanHangHaoHeHeiHenHengHoHongHouHuHuaHuaiHuanHuangHuiHunHuoJiJiaJianJiangJiaoJieJinJingJiongJiuJuJuanJueJunKaKaiKanKangKaoKeKenKengKongKouKuKuaKuaiKuanKuangKuiKunKuoLaLaiLanLangLaoLeLeiLengLiLiaLianLiangLiaoLieLinLingLiuLoLongLouLuLvLuanLveLunLuoMMaMaiManMangMaoMeMeiMenMengMiMianMiaoMieMinMingMiuMoMouMeiMuNaNaiNanNangNaoNeNeiNenNNiNianNiangNiaoNieNinNingNiuNongNouNuNvNveNuanNuoOuPaPaiPanPangPaoPeiPenPengPiPianPiaoPiePinPingPoPouPuQiQiaQianQiangQiaoQieQinQingQiongQiuQuQuanQueQunRaRanRangRaoReRenRengRiRongRouRuRuanRuiRunRuoSaSaiSanSangSaoSeShaShaiShanShangShaoSheShenShengShiShouShuShuaShuaiShuanShuangShuiShuoSiSongSouSuSuanSuiSunSuoTaTaiTanTangTaoTeTengTiTianTiaoTieTingTongTouTuTuanTuiTunTuoWaWaiWanWangWeiWenWengWoWuXiXiaXianXiangXiaoXieXinXingXiongXiuXuXuanXueXunYaYanYangYaoYeYenYiYinYingYoYongYouYuYuanYueYunZaZaiZanZangZaoZeZeiZenZengZhaZhaiZhanZhangZhaoZheZhenZhengZhiZhongZhouZhuZhuaZhuaiZhuanZhuangZhuiZhunZhuoZaiZiZongZouZuZuanZuiZunZuo'.split(/(?=[A-Z])/g);
|
||||
let cache = {};
|
||||
let keyLen = key.length - 1;
|
||||
let creg = /[\u4e00-\u9fa5]/;
|
||||
let translate = word => {
|
||||
if (word.length > 1) {
|
||||
let ret = '';
|
||||
for (let i = 0; i < word.length; i++) {
|
||||
ret += translate(word[i]);
|
||||
if (i < word.length - 1) {
|
||||
ret += ',';
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!creg.test(word)) {
|
||||
return word;
|
||||
}
|
||||
|
||||
if (cache.hasOwnProperty(word)) {
|
||||
return cache[word];
|
||||
}
|
||||
let begin = 0;
|
||||
let end = keyLen;
|
||||
while (begin <= end) {
|
||||
let middle = Math.floor((begin + end) / 2);
|
||||
if (word.localeCompare(key[middle], 'zh-CN') < 0) {
|
||||
end = middle - 1;
|
||||
} else {
|
||||
begin = middle + 1;
|
||||
}
|
||||
}
|
||||
return (cache[word] = (pinyin[end] || '').toLowerCase());
|
||||
};
|
||||
export default translate;
|
||||
@@ -1,17 +1,19 @@
|
||||
import { WINDOW_MAX_HEIGHT, WINDOW_MIN_HEIGHT, PRE_ITEM_HEIGHT, SYSTEM_PLUGINS } from './constans';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import process from 'child_process';
|
||||
import Store from 'electron-store';
|
||||
import downloadFile from 'download';
|
||||
import { nativeImage, ipcRenderer } from 'electron';
|
||||
import { APP_FINDER_PATH } from './constans';
|
||||
import { ipcRenderer } from 'electron';
|
||||
import { getlocalDataFile } from '../../../main/common/utils';
|
||||
import iconvLite from 'iconv-lite';
|
||||
import bpList from 'bplist-parser';
|
||||
import shell from 'shelljs';
|
||||
|
||||
const getApp = process.platform === 'win32' ? require('./win-app').getApp : require('./darwin-app').getApp;
|
||||
|
||||
const store = new Store();
|
||||
|
||||
getApp.init();
|
||||
const fileLists = getApp.fileLists;
|
||||
|
||||
function getWindowHeight(searchList) {
|
||||
if (!searchList) return WINDOW_MAX_HEIGHT;
|
||||
if (!searchList.length) return WINDOW_MIN_HEIGHT;
|
||||
@@ -48,7 +50,7 @@ async function downloadZip(downloadRepoUrl, name) {
|
||||
const temp_dest = `${plugin_path}/${name}`;
|
||||
// 下载模板
|
||||
if (await existOrNot(temp_dest)) {
|
||||
await process.execSync(`rm -rf ${temp_dest}`);
|
||||
shell.rm('-rf', temp_dest);
|
||||
}
|
||||
|
||||
await downloadFile(downloadRepoUrl, plugin_path, { extract: true });
|
||||
@@ -128,7 +130,10 @@ function mergePlugins(plugins) {
|
||||
return hasOption;
|
||||
})
|
||||
});
|
||||
|
||||
ipcRenderer &&
|
||||
ipcRenderer.send('pluginInit', {
|
||||
plugins: target
|
||||
});
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -153,103 +158,6 @@ function find(p, target = 'plugin.json') {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
const fileLists = [];
|
||||
// 默认搜索目录
|
||||
const isZhRegex = /[\u4e00-\u9fa5]/;
|
||||
const getDisplayNameRegex = /\"(?:CFBundleDisplayName)\"\s\=\s\"(.*)\"/;
|
||||
|
||||
async function getAppZhName(rootPath, appName) {
|
||||
try {
|
||||
const ERROR_RESULT = '';
|
||||
const systemPath = path.join(rootPath, `${appName}/Contents/Resources/zh_CN.lproj/InfoPlist.strings`);
|
||||
const customizePath = path.join(rootPath, `${appName}/Contents/Resources/zh-Hans.lproj/InfoPlist.strings`);
|
||||
let appInfoPath = '';
|
||||
|
||||
if (fs.existsSync(systemPath)) {
|
||||
appInfoPath = systemPath;
|
||||
} else if (fs.existsSync(customizePath)) {
|
||||
appInfoPath = customizePath;
|
||||
} else {
|
||||
return ERROR_RESULT;
|
||||
}
|
||||
let appZhName = '';
|
||||
if (rootPath == '/Applications') {
|
||||
const container = iconvLite.decode(fs.readFileSync(appInfoPath), 'utf-16');
|
||||
if (container) {
|
||||
const res = container.match(getDisplayNameRegex);
|
||||
appZhName = res && res[1];
|
||||
} else {
|
||||
return ERROR_RESULT;
|
||||
}
|
||||
} else {
|
||||
const [{ CFBundleDisplayName = '', CFBundleName = '' }] = await bpList.parseFile(appInfoPath);
|
||||
appZhName = CFBundleDisplayName || CFBundleName;
|
||||
}
|
||||
|
||||
return appZhName;
|
||||
} catch (error) {
|
||||
return ERROR_RESULT;
|
||||
}
|
||||
}
|
||||
APP_FINDER_PATH.forEach((searchPath, index) => {
|
||||
fs.readdir(searchPath, async (err, files) => {
|
||||
try {
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const appName = files[i];
|
||||
const extname = path.extname(appName);
|
||||
const appSubStr = appName.split(extname)[0];
|
||||
if ((extname === '.app' || extname === '.prefPane') >= 0) {
|
||||
try {
|
||||
const path1 = path.join(searchPath, `${appName}/Contents/Resources/App.icns`);
|
||||
const path2 = path.join(searchPath, `${appName}/Contents/Resources/AppIcon.icns`);
|
||||
const path3 = path.join(searchPath, `${appName}/Contents/Resources/${appSubStr}.icns`);
|
||||
const path4 = path.join(searchPath, `${appName}/Contents/Resources/${appSubStr.replace(' ', '')}.icns`);
|
||||
let iconPath = path1;
|
||||
if (fs.existsSync(path1)) {
|
||||
iconPath = path1;
|
||||
} else if (fs.existsSync(path2)) {
|
||||
iconPath = path2;
|
||||
} else if (fs.existsSync(path3)) {
|
||||
iconPath = path3;
|
||||
} else if (fs.existsSync(path4)) {
|
||||
iconPath = path4;
|
||||
} else {
|
||||
// 性能最低的方式
|
||||
const resourceList = fs.readdirSync(path.join(searchPath, `${appName}/Contents/Resources`));
|
||||
const iconName = resourceList.filter((file) => path.extname(file) === '.icns')[0];
|
||||
iconPath = path.join(searchPath, `${appName}/Contents/Resources/${iconName}`);
|
||||
}
|
||||
const img = await nativeImage.createThumbnailFromPath(iconPath, { width: 64, height: 64 });
|
||||
|
||||
const appZhName = await getAppZhName(searchPath, appName);
|
||||
|
||||
const fileOptions = {
|
||||
value: 'plugin',
|
||||
icon: img.toDataURL(),
|
||||
desc: path.join(searchPath, appName),
|
||||
type: 'app',
|
||||
action: `open ${path.join(searchPath, appName).replace(' ', '\\ ')}`,
|
||||
keyWords: [appSubStr]
|
||||
};
|
||||
|
||||
if (appZhName && isZhRegex.test(appZhName)) {
|
||||
// pinyinArr = [['pin'], ['yin']]
|
||||
fileOptions.keyWords.push(appZhName);
|
||||
}
|
||||
|
||||
fileLists.push({
|
||||
...fileOptions,
|
||||
name: appSubStr,
|
||||
names: JSON.parse(JSON.stringify(fileOptions.keyWords)),
|
||||
});
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function debounce(fn, delay) {
|
||||
let timer;
|
||||
|
||||
93
src/renderer/assets/common/win-app.js
Normal file
@@ -0,0 +1,93 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import os from 'os';
|
||||
import translate from './translate';
|
||||
import {shell} from 'electron';
|
||||
const fileIcon = require('extract-file-icon');
|
||||
const filePath = path.resolve('C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs');
|
||||
|
||||
const fileLists = [];
|
||||
const isZhRegex = /[\u4e00-\u9fa5]/;
|
||||
|
||||
const icondir = path.join(os.tmpdir(), 'ProcessIcon');
|
||||
const exists = fs.existsSync(icondir);
|
||||
if (!exists) { fs.mkdirSync(icondir) }
|
||||
|
||||
const getico = app =>{
|
||||
try {
|
||||
const buffer = fileIcon(app.desc, 32);
|
||||
const iconpath = path.join(icondir, `${app.name}.png`);
|
||||
|
||||
fs.exists(iconpath, exists => {
|
||||
if (!exists) {
|
||||
fs.writeFile(iconpath, buffer, 'base64', () => {});
|
||||
}
|
||||
});
|
||||
|
||||
} catch(e) {
|
||||
console.log(e, app.desc);
|
||||
}
|
||||
}
|
||||
|
||||
function fileDisplay(filePath){
|
||||
//根据文件路径读取文件,返回文件列表
|
||||
fs.readdir(filePath,function(err,files){
|
||||
if(err){
|
||||
console.warn(err)
|
||||
}else{
|
||||
files.forEach(function(filename){
|
||||
const filedir = path.join(filePath, filename);
|
||||
fs.stat(filedir,function(eror,stats){
|
||||
if(eror){
|
||||
console.warn('获取文件stats失败');
|
||||
} else {
|
||||
const isFile = stats.isFile(); // 是文件
|
||||
const isDir = stats.isDirectory(); // 是文件夹
|
||||
if(isFile){
|
||||
const appName = filename.split('.')[0];
|
||||
const keyWords = [appName];
|
||||
const appDetail = shell.readShortcutLink(filedir);
|
||||
if (!appDetail.target) return;
|
||||
|
||||
if (isZhRegex.test(appName)) {
|
||||
const py = translate(appName);
|
||||
const pinyinArr = py.split(',');
|
||||
const zh_firstLatter = pinyinArr.map(py => py[0]);
|
||||
// 拼音
|
||||
keyWords.push(pinyinArr.join(''));
|
||||
// 缩写
|
||||
keyWords.push(zh_firstLatter.join(''));
|
||||
} else {
|
||||
const firstLatter = appName.split(' ').map(name => name[0]).join('');
|
||||
keyWords.push(firstLatter);
|
||||
}
|
||||
|
||||
const icon = path.join(os.tmpdir(), 'ProcessIcon', `${encodeURIComponent(appName)}.png`);
|
||||
|
||||
const appInfo = {
|
||||
value: 'plugin',
|
||||
desc: appDetail.target,
|
||||
type: 'app',
|
||||
icon,
|
||||
action: `start "dummyclient" "${appDetail.target}"`,
|
||||
keyWords: keyWords,
|
||||
name: appName,
|
||||
names: JSON.parse(JSON.stringify(keyWords)),
|
||||
}
|
||||
fileLists.push(appInfo);
|
||||
getico(appInfo);
|
||||
}
|
||||
if(isDir) {
|
||||
fileDisplay(filedir); // 递归,如果是文件夹,就继续遍历该文件夹下面的文件
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const getApp = {
|
||||
init: () => fileDisplay(filePath),
|
||||
fileLists
|
||||
}
|
||||
BIN
src/renderer/assets/imgs/logo.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
@@ -7,7 +7,7 @@ import router from './router'
|
||||
import store from './store'
|
||||
import Antd from 'ant-design-vue';
|
||||
|
||||
import 'ant-design-vue/dist/antd.css';
|
||||
import './assets/ant-reset.less';
|
||||
|
||||
const opConfig = remote.getGlobal('opConfig');
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<template>
|
||||
<div>
|
||||
<webview v-if="!pluginInfo.subType" id="webview" :src="path" :preload="preload"></webview>
|
||||
<webview
|
||||
v-if="!pluginInfo.subType"
|
||||
id="webview"
|
||||
:src="path"
|
||||
:preload="preload"
|
||||
></webview>
|
||||
<div v-else>
|
||||
<webview id="webview" :src="templatePath" :preload="preload"></webview>
|
||||
</div>
|
||||
@@ -29,6 +34,14 @@ export default {
|
||||
this.webview.addEventListener('dom-ready', () => {
|
||||
this.webview.send('onPluginReady', this.pluginInfo);
|
||||
this.webview.send('onPluginEnter', this.pluginInfo);
|
||||
this.commonUpdate({
|
||||
pluginLoading: true,
|
||||
});
|
||||
});
|
||||
this.webview.addEventListener('did-finish-load', () => {
|
||||
this.commonUpdate({
|
||||
pluginLoading: false,
|
||||
});
|
||||
});
|
||||
this.setSubPlaceHolder('Hi, Rubick');
|
||||
this.webview.addEventListener('ipc-message', (event) => {
|
||||
@@ -83,10 +96,6 @@ export default {
|
||||
methods: {
|
||||
...mapMutations('main', ['setSubPlaceHolder', 'commonUpdate']),
|
||||
},
|
||||
beforeRouteUpdate() {
|
||||
this.path = `File://${this.pluginInfo.sourceFile}`;
|
||||
this.webview.send('onPluginEnter', this.pluginInfo);
|
||||
},
|
||||
beforeDestroy() {
|
||||
const webview = document.querySelector('webview');
|
||||
webview && webview.send('onPluginOut', this.pluginInfo)
|
||||
@@ -97,10 +106,13 @@ export default {
|
||||
return (this.devPlugins.filter(plugin => plugin.name === this.pluginInfo.name)[0] || {}).features
|
||||
},
|
||||
path() {
|
||||
this.$nextTick(() => {
|
||||
this.webview && this.webview.send('onPluginEnter', this.pluginInfo);
|
||||
});
|
||||
return `File://${this.pluginInfo.sourceFile}`
|
||||
},
|
||||
templatePath() {
|
||||
return `File://${path.join(__static, './plugins/tpl/index.html')}?code=${JSON.parse(this.pluginInfo.detail).code}&targetFile=${encodeURIComponent(this.pluginInfo.sourceFile)}&preloadPath=${this.pluginInfo.preload}`;
|
||||
return `File://${path.join(__static, './plugins/tpl/index.html')}?code=${this.pluginInfo.detail.code}&targetFile=${encodeURIComponent(this.pluginInfo.sourceFile)}&preloadPath=${this.pluginInfo.preload}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,6 @@ export default {
|
||||
|
||||
<style lang="less">
|
||||
.main-input {
|
||||
-webkit-app-region: drag;
|
||||
height: 60px !important;
|
||||
flex: 1;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div class="market">
|
||||
<a-carousel arrows>
|
||||
<a-carousel v-if="bannerList && !!bannerList.length" arrows>
|
||||
<div
|
||||
slot="prevArrow"
|
||||
slot-scope="props"
|
||||
@@ -13,10 +13,10 @@
|
||||
<a-icon type="right-circle" />
|
||||
</div>
|
||||
<div v-for="banner in bannerList">
|
||||
<img width="100%" :src="banner.src" />
|
||||
<img @click="jumpTo(banner.link)" width="100%" :src="banner.src" />
|
||||
</div>
|
||||
</a-carousel>
|
||||
<a-divider></a-divider>
|
||||
<a-divider v-if="bannerList && !!bannerList.length"></a-divider>
|
||||
<h2>插件</h2>
|
||||
<a-list item-layout="horizontal" style="width: 100%" :grid="{ gutter: 16, column: 2 }" :data-source="pluginList">
|
||||
<a-list-item slot="renderItem" slot-scope="item, index">
|
||||
@@ -73,6 +73,7 @@
|
||||
import api from '../../../assets/api';
|
||||
import {mapActions, mapState} from 'vuex';
|
||||
import marked from "marked";
|
||||
import {shell} from "electron";
|
||||
const rendererMD = new marked.Renderer();
|
||||
|
||||
export default {
|
||||
@@ -114,6 +115,11 @@ export default {
|
||||
this.currentSelect = item;
|
||||
this.currentSelect.index = index;
|
||||
},
|
||||
jumpTo(link) {
|
||||
if (link) {
|
||||
shell.openExternal(link)
|
||||
}
|
||||
},
|
||||
...mapActions('main', ['downloadPlugin'])
|
||||
},
|
||||
computed: {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<div class="settings-detail">
|
||||
<div v-if="currentSelect[0] === 0">
|
||||
<div class="setting-item">
|
||||
<div class="title">快捷键</div>
|
||||
<div class="title">快捷键(需要使用 option/ctrl/shift/command 键修饰)</div>
|
||||
<div class="settings-item-li">
|
||||
<div class="label">显示/隐藏快捷键</div>
|
||||
<div class="value" tabIndex=-1 @keydown="(e) => changeShortCut(e, 'showAndHidden')">{{ config.perf.shortCut.showAndHidden }}</div>
|
||||
@@ -24,6 +24,10 @@
|
||||
<div class="label">插件分离快捷键</div>
|
||||
<div class="value" tabIndex=-1 @keydown="(e) => changeShortCut(e, 'separate')">{{ config.perf.shortCut.separate }}</div>
|
||||
</div>
|
||||
<div class="settings-item-li">
|
||||
<div class="label">返回主界面</div>
|
||||
<div class="value" tabIndex=-1 @keydown="(e) => changeShortCut(e, 'quit')">{{ config.perf.shortCut.quit }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="title">通用</div>
|
||||
@@ -55,7 +59,6 @@
|
||||
<div class="title">长按以下设置的毫秒响应</div>
|
||||
<a-slider :step="100" v-model:value="config.superPanel.mouseDownTime" :min="200" :max="1000" />
|
||||
</div>
|
||||
<img width="100%" src="https://static.91jkys.com/upload/202107/02/fa4a5c614234409fb32ddda70cb900aa.jpg" />
|
||||
</div>
|
||||
<div v-if="currentSelect[0] === 2">
|
||||
<a-collapse>
|
||||
|
||||
@@ -22,9 +22,9 @@ const state = {
|
||||
searchValue: '',
|
||||
devPlugins: mergePlugins(sysFile.getUserPlugins() || []),
|
||||
subPlaceHolder: '',
|
||||
pluginLoading: true,
|
||||
pluginInfo: (() => {
|
||||
try {
|
||||
console.log(window.pluginInfo);
|
||||
return window.pluginInfo || {};
|
||||
} catch (e) {}
|
||||
})()
|
||||
@@ -107,10 +107,10 @@ const actions = {
|
||||
commit('commonUpdate', { searchValue: value });
|
||||
return;
|
||||
}
|
||||
const fileUrl = clipboard.read('public.file-url').replace('file://', '');
|
||||
const fileUrl = paylpad.filePath || clipboard.read('public.file-url').replace('file://', '');
|
||||
commit('commonUpdate', { searchValue: value });
|
||||
// 复制文件
|
||||
if (fileUrl && value === 'plugin.json') {
|
||||
if (paylpad.filePath || (fileUrl && value === 'plugin.json')) {
|
||||
const config = JSON.parse(fs.readFileSync(fileUrl, 'utf-8'));
|
||||
|
||||
const pluginConfig = {
|
||||
@@ -132,7 +132,6 @@ const actions = {
|
||||
name: 'plugin.json'
|
||||
},
|
||||
searchValue: '',
|
||||
devPlugins: [pluginConfig, ...state.devPlugins],
|
||||
options: [
|
||||
{
|
||||
name: '新建rubick开发插件',
|
||||
@@ -142,6 +141,7 @@ const actions = {
|
||||
click: (router) => {
|
||||
commit('commonUpdate', {
|
||||
showMain: true,
|
||||
devPlugins: [pluginConfig, ...state.devPlugins],
|
||||
selected: {
|
||||
key: 'plugin',
|
||||
name: '新建rubick开发插件'
|
||||
|
||||
BIN
static/icon.ico
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
static/icon@2x.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
static/icon@3x.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 15 KiB |
@@ -40,8 +40,8 @@
|
||||
background: #314659;
|
||||
}
|
||||
.top .img img {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
}
|
||||
.top .text {
|
||||
color: #999;
|
||||
|
||||
@@ -4,6 +4,7 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
const { spawn } = require ('child_process');
|
||||
const mineType = require("mime-types");
|
||||
const {extend} = require('../../utils');
|
||||
|
||||
new Vue({
|
||||
el: '#app',
|
||||
@@ -116,7 +117,8 @@ new Vue({
|
||||
this.targetOptions = this.options.common;
|
||||
} else {
|
||||
// 有文件选择
|
||||
this.targetOptions = JSON.parse(JSON.stringify(this.options.selected));
|
||||
this.targetOptions = [];
|
||||
extend(this.targetOptions, this.options.selected, true);
|
||||
// 检测上传
|
||||
(this.selectData.optionPlugin || []).forEach(plugin => {
|
||||
plugin.features.forEach(fe => {
|
||||
@@ -181,6 +183,8 @@ new Vue({
|
||||
...JSON.parse(res),
|
||||
src: msg,
|
||||
});
|
||||
}).catch(() => {
|
||||
this.$set(this.selectData, 'translate', null);
|
||||
}).finally(() => {
|
||||
this.loading = false;
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const {getData, getlocalDataFile, saveData} = require("./utils");
|
||||
|
||||
const axios = require('axios');
|
||||
const marked = require("marked");
|
||||
const rendererMD = new marked.Renderer();
|
||||
const path = require('path');
|
||||
@@ -22,7 +22,7 @@ function getQueryVariable(variable) {
|
||||
if (location.href.indexOf('targetFile') > -1) {
|
||||
filePath = decodeURIComponent(getQueryVariable('targetFile'));
|
||||
} else {
|
||||
filePath = location.pathname.replace('file://', '');
|
||||
filePath = process.platform === 'win32' ? location.pathname.split(':')[1] : location.pathname.replace('file://', '');
|
||||
}
|
||||
const {ipcRenderer, nativeImage, clipboard, remote, shell} = require('electron');
|
||||
|
||||
@@ -46,7 +46,7 @@ function convertImgToBase64(url, callback, outputFormat){
|
||||
img.src = url;
|
||||
}
|
||||
|
||||
window.utools = window.rubick = {
|
||||
window.rubick = {
|
||||
// 事件
|
||||
onPluginEnter(cb) {
|
||||
ipcRenderer.on('onPluginEnter', (e, message) => {
|
||||
@@ -240,78 +240,6 @@ window.utools = window.rubick = {
|
||||
removeFeature(code) {
|
||||
ipcRenderer.sendToHost('removeFeature', {code});
|
||||
},
|
||||
ubrowser: {
|
||||
winId: '',
|
||||
async goto(md, opts) {
|
||||
const objExp = new RegExp(/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/);
|
||||
let winId;
|
||||
let win;
|
||||
win = new BrowserWindow({
|
||||
show: false,
|
||||
title: typeof opts === 'object' ? '' : opts,
|
||||
webPreferences: {
|
||||
webSecurity: false,
|
||||
enableRemoteModule: true,
|
||||
backgroundThrottling: false,
|
||||
webviewTag: true,
|
||||
nodeIntegration: true // 在网页中集成Node
|
||||
}
|
||||
});
|
||||
if(objExp.test(md) && md.indexOf('http') === 0) {
|
||||
await win.loadURL(md);
|
||||
winId = win.id;
|
||||
} else {
|
||||
marked.setOptions({
|
||||
renderer: rendererMD,
|
||||
gfm: true,
|
||||
tables: true,
|
||||
breaks: false,
|
||||
pedantic: false,
|
||||
sanitize: false,
|
||||
smartLists: true,
|
||||
smartypants: false
|
||||
});
|
||||
const htmlContent = marked(md);
|
||||
win.loadURL('data:text/html;charset=UTF-8,' + encodeURIComponent(htmlContent))
|
||||
win.once('ready-to-show', () => win.show());
|
||||
winId = win.id;
|
||||
}
|
||||
return {
|
||||
value(selector, value) {
|
||||
ipcRenderer.send('msg-trigger', {
|
||||
type: 'ubrowser.value',
|
||||
winId,
|
||||
selector, value
|
||||
});
|
||||
return new Promise(resolve => {
|
||||
ipcRenderer.once(`msg-back-ubrowser.value`, (e, result) => {
|
||||
resolve(this)
|
||||
});
|
||||
})
|
||||
},
|
||||
click(selector) {
|
||||
ipcRenderer.send('msg-trigger', {
|
||||
type: 'ubrowser.click',
|
||||
winId,
|
||||
selector,
|
||||
});
|
||||
return new Promise(resolve => {
|
||||
ipcRenderer.once(`msg-back-ubrowser.click`, (e, result) => {
|
||||
resolve(this)
|
||||
});
|
||||
})
|
||||
},
|
||||
run(options) {
|
||||
ipcRenderer.send('msg-trigger', {
|
||||
type: 'ubrowser.run',
|
||||
winId,
|
||||
...options
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
// 系统
|
||||
shellOpenExternal(url) {
|
||||
shell.openExternal(url);
|
||||
@@ -324,6 +252,18 @@ window.utools = window.rubick = {
|
||||
isWindows() {
|
||||
return os.type() === 'Windows_NT';
|
||||
},
|
||||
|
||||
shellOpenPath(path) {
|
||||
shell.openPath(path)
|
||||
},
|
||||
|
||||
request(config = {}) {
|
||||
return axios.create({
|
||||
timeout: 10000,
|
||||
withCredentials: true,
|
||||
...config,
|
||||
});
|
||||
}
|
||||
}
|
||||
const preloadPath = getQueryVariable('preloadPath') || './preload.js';
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 873 B After Width: | Height: | Size: 1.4 KiB |
@@ -20,8 +20,31 @@ function getData(path, defaultValue) {
|
||||
}
|
||||
}
|
||||
|
||||
const isArray = Array.isArray ||
|
||||
function(object){ return object instanceof Array }
|
||||
|
||||
function isPlainObject(obj) {
|
||||
return isObject(obj) && Object.getPrototypeOf(obj) == Object.prototype
|
||||
}
|
||||
|
||||
function isObject(obj) { return typeof obj == "object" }
|
||||
|
||||
|
||||
function extend(target, source, deep) {
|
||||
for (let key in source)
|
||||
if (deep && (isPlainObject(source[key]) || isArray(source[key]))) {
|
||||
if (isPlainObject(source[key]) && !isPlainObject(target[key]))
|
||||
target[key] = {}
|
||||
if (isArray(source[key]) && !isArray(target[key]))
|
||||
target[key] = []
|
||||
extend(target[key], source[key], deep)
|
||||
}
|
||||
else if (source[key] !== undefined) target[key] = source[key]
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getlocalDataFile,
|
||||
saveData,
|
||||
getData
|
||||
getData,
|
||||
extend
|
||||
}
|
||||
|
||||