feat: 支持截屏,下载方式调整

This commit is contained in:
muwoo
2021-06-22 15:35:46 +08:00
parent 1e77613565
commit e3838738db
27 changed files with 1519 additions and 12 deletions

View File

@@ -0,0 +1,102 @@
const { BrowserWindow, ipcMain, globalShortcut } = require("electron");
const os = require('os')
const path = require('path')
module.exports = () => {
let captureWins = []
let init = () => {
if (captureWins.length) {
return
}
createWindow();
};
let createWindow = () => {
const { screen } = require('electron');
let displays = screen.getAllDisplays();
captureWins = displays.map((display) => {
let captureWin = new BrowserWindow({
// window 使用 fullscreen, mac 设置为 undefined, 不可为 false
fullscreen: os.platform() === 'win32' || undefined,
width: display.bounds.width,
height: display.bounds.height,
x: display.bounds.x,
y: display.bounds.y,
transparent: true,
frame: false,
movable: false,
resizable: false,
enableLargerThanScreen: true,
hasShadow: false,
show: false,
webPreferences: {
enableRemoteModule: true,
nodeIntegration: true,
webSecurity: false,
// devTools: false,
}
})
captureWin.setAlwaysOnTop(true, 'screen-saver')
captureWin.setVisibleOnAllWorkspaces(true)
captureWin.setFullScreenable(false)
captureWin.loadFile(`${__static}/plugins/capture/index.html`);
let { x, y } = screen.getCursorScreenPoint()
if (x >= display.bounds.x && x <= display.bounds.x + display.bounds.width && y >= display.bounds.y && y <= display.bounds.y + display.bounds.height) {
captureWin.focus()
} else {
captureWin.blur()
}
captureWin.once('ready-to-show', () => captureWin.show());
return captureWin
});
};
let getWindow = () => captureWins;
let useCapture = () => {
globalShortcut.register('Esc', () => {
if (captureWins) {
captureWins.forEach(win => win.close())
captureWins = []
}
});
globalShortcut.register('CmdOrCtrl+Shift+S', init)
ipcMain.on('capture-screen', (e, { type = 'start', screenId, winId, x, y } = {}) => {
if (type === 'start') {
init()
} else if (type === 'complete') {
if (captureWins) {
captureWins.forEach(win => win.close())
captureWins = []
}
// nothing
} else if (type === 'select') {
captureWins.forEach(win => win.webContents.send('capture-screen', { type: 'select', screenId }))
} else if (type === 'getAllDisplays') {
const { screen } = require('electron');
let displays = screen.getAllDisplays();
const currentScreen = displays.filter(d => d.bounds.x === x && d.bounds.y === y)[0];
e.sender.send('getAllDisplays', {
screen: {
scaleFactor: currentScreen.scaleFactor,
id: currentScreen.id,
bounds: currentScreen.bounds,
},
winId,
});
}
});
}
return {
init: init,
getWindow: getWindow,
useCapture,
};
};

View File

@@ -1,4 +1,5 @@
module.exports = () => ({
picker: require("./picker")(),
separator: require("./separate")(),
capture: require("./capture")(),
});

View File

@@ -45,10 +45,6 @@ export default function init(mainWindow) {
});
ipcMain.on('init-shortcut', (event) => {
globalShortcut.register('Esc', () => {
mainWindow.show();
event.sender.send('init-rubick');
});
globalShortcut.register('ctrl+d', () => {
event.sender.send('new-window');
});

View File

@@ -2,6 +2,7 @@ import { app, BrowserWindow, protocol } from 'electron'
import '../renderer/store'
import init from './common/common';
import createTray from './tray';
const {capture} = require("./browsers")();
/**
* Set `__static` path to static files in production
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-static-assets.html
@@ -19,6 +20,7 @@ function createWindow () {
/**
* Initial window options
*/
capture.useCapture()
mainWindow = new BrowserWindow({
height: 60,
useContentSize: true,

View File

@@ -1,4 +1,4 @@
export default {
development: 'http://localhost:7001',
development: 'http://rubick-server.qa.91jkys.com',
production: 'http://rubick-server.qa.91jkys.com',
};

View File

@@ -5,7 +5,7 @@ const PRE_ITEM_HEIGHT = 60;
const SYSTEM_PLUGINS = [
{
"pluginName": "rubick 帮助文档",
"logo": "logo.png",
"logo": "https://static.91jkys.com/activity/img/4eb6f2848b064f569c28fdf8495d5ec7.png",
"features": [
{
"code": "help",
@@ -17,7 +17,7 @@ const SYSTEM_PLUGINS = [
},
{
"pluginName": "屏幕颜色拾取",
"logo": "logo.png",
"logo": "https://static.91jkys.com/activity/img/6a1b4b8a17da45d680ea30b53a91aca8.png",
"features": [
{
"code": "pick",
@@ -26,6 +26,18 @@ const SYSTEM_PLUGINS = [
},
],
"tag": 'rubick-color',
},
{
"pluginName": "截屏",
"logo": "https://static.91jkys.com/activity/img/b34d30b426f24eb2b77bf434b8493495.png",
"features": [
{
"code": "shortCut",
"explain": "rubick 屏幕截取",
"cmds": [ "截屏", "shortCut" ]
},
],
"tag": 'rubick-screen-short-cut',
}
]

View File

@@ -9,5 +9,10 @@ export default {
pick() {
ipcRenderer.send('start-picker')
}
},
'rubick-screen-short-cut': {
shortCut() {
ipcRenderer.send('capture-screen', {type: 'start'})
}
}
}

View File

@@ -4,6 +4,7 @@ import path from 'path';
import fs from 'fs';
import process from 'child_process';
import Store from 'electron-store';
import downloadFile from 'download';
const store = new Store();
@@ -44,6 +45,21 @@ function mkdirFolder(name) {
});
}
async function downloadZip(downloadRepoUrl, name) {
const plugin_path = path.join(__static, './plugins');
const targetUrl = downloadRepoUrl ? downloadRepoUrl : `https://github.com/clouDr-f2e/${name}/archive/refs/heads/master.zip`;
if (!(await existOrNot(plugin_path))) {
await mkdirFolder(plugin_path);
}
// 基础模版所在目录,如果是初始化,则是模板名称,否则是项目名称
const temp_dest = `${plugin_path}/${name}-master`;
// 下载模板
if (await existOrNot(temp_dest)) {
await process.execSync(`rm -rf ${temp_dest}`);
}
await downloadFile(targetUrl, `${__static}/plugins`,{extract: true})
}
function downloadFunc(downloadRepoUrl, name) {
const targetGit = downloadRepoUrl ? downloadRepoUrl : `github:clouDr-f2e/${name}`;
const plugin_path = path.join(__static, './plugins');
@@ -82,7 +98,6 @@ const sysFile = {
},
getUserPlugins() {
try {
console.log(store.get('user-plugins').devPlugins)
return store.get('user-plugins').devPlugins;
} catch (e) {
return []
@@ -92,6 +107,7 @@ const sysFile = {
store.delete('user-plugins');
}
}
sysFile.removeAllPlugins()
function mergePlugins(plugins) {
return [
@@ -137,4 +153,5 @@ export {
sysFile,
mergePlugins,
find,
downloadZip,
}

View File

@@ -7,6 +7,7 @@ import {
sysFile,
mergePlugins,
find,
downloadZip,
} from '../../assets/common/utils';
import systemMethod from '../../assets/common/system';
import fs from "fs";
@@ -179,7 +180,7 @@ const actions = {
...cmds.map((cmd) => ({
name: cmd,
value: 'plugin',
icon: 'image://' + path.join(plugin.sourceFile, `../${plugin.logo}`),
icon: plugin.sourceFile ? 'image://' + path.join(plugin.sourceFile, `../${plugin.logo}`) : plugin.logo,
desc: fe.explain,
type: plugin.type,
click: (router) => {
@@ -199,8 +200,8 @@ const actions = {
});
},
async downloadPlugin({commit}, payload) {
await downloadFunc(payload.gitUrl, payload.name);
const fileUrl = find(path.join(__static, `plugins/${payload.name}`));
await downloadZip(payload.gitUrl, payload.name);
const fileUrl = find(path.join(__static, `plugins/${payload.name}-master`));
// 复制文件
const config = JSON.parse(fs.readFileSync(`${fileUrl}/plugin.json`, 'utf-8'));
const pluginConfig = {
@@ -221,7 +222,7 @@ const actions = {
icon: 'image://' + path.join(plugin.sourceFile, `../${plugin.logo}`),
},
searchValue: '',
showMain: true,
showMain: true
});
ipcRenderer.send('changeWindowSize-rubick', {
height: getWindowHeight(),