feat: 优化

This commit is contained in:
范胜发
2022-03-11 17:22:33 +08:00
parent 9bae8badbd
commit acf83137e1
24 changed files with 453 additions and 193 deletions

35
main.js
View File

@ -1,35 +1,37 @@
const { app, BrowserWindow, ipcMain } = require('electron');
const path = require('path');
const url = require('url');
const { install: storeInstall } = require('./store/index');
let win = null;
ipcMain.on('size-change', (event, flag) => {
win.setOpacity(0);
const [x, y] = win.getPosition();
if (flag) {
win.setSize(500, 300, true);
win.setPosition(x, y - 300 + 75, true);
win.setBounds({
x,
y: y - 300 + 75,
width: 500,
height: 300,
});
} else {
win.setSize(120, 75, true);
win.setPosition(x, y + 300 - 75, true);
win.setBounds({
x,
y: y + 300 - 75,
width: 120,
height: 75,
});
}
setTimeout(() => {
win.setOpacity(1);
}, 300);
});
ipcMain.on('pos-change', (event, { x, y }) => {
win.setPosition(x, y, true);
});
const { getTodo, setTodo } = require('./store');
ipcMain.handle('get-todo', () => {
console.log(getTodo());
return getTodo();
});
ipcMain.on('set-todo', (e, value) => {
setTodo(value);
});
function createWindow() {
win = new BrowserWindow({
width: 120,
@ -39,7 +41,7 @@ function createWindow() {
frame: false,
transparent: true,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
preload: path.join(__dirname, 'preload/preload.js'),
},
});
@ -57,5 +59,6 @@ function createWindow() {
}
app.whenReady().then(() => {
storeInstall();
createWindow();
});