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,