-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
110 lines (92 loc) · 2.47 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const fs = require('fs');
const path = require('path');
const { app, BrowserWindow, globalShortcut, ipcMain, clipboard } = require('electron');
const { URL, RESOURCES_PATH } = require('./modules/constants')
const Store = require('electron-store');
if(require('electron-squirrel-startup')) return app.quit();
const store = new Store();
if(!store.get('length')) {
store.set('length', 0);
}
let window = null;
let focused = true;
let init = () => {
window = new BrowserWindow({
width: 1300,
height: 820,
frame: false,
show: false,
transparent: true,
icon: './src/assets/icons/win/icon.ico',
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
});
window.loadURL(URL)
.then(() => {
window.show();
})
.catch(e => {
throw e;
})
window.on('closed', () => {
window = null;
});
window.on('blur', () => {
focused = false;
});
window.on('focus', () => {
focused = true;
});
};
ipcMain.on('paste', event => {
const text = clipboard.readText();
const image = clipboard.readImage()?.toPNG();
fs.readdir(RESOURCES_PATH, (error, dir) => {
const cc = dir.length;
const tp = path.join(RESOURCES_PATH, `${ cc }.txt`);
const ip = path.join(RESOURCES_PATH, `${ cc + 1 }.png`);
if(text) {
fs.writeFile(tp, text, { encoding: 'utf-8' }, () => {
event.sender.send('new', {
path: tp,
editing: true
});
});
} else if(image) {
fs.writeFile(ip, image, () => {
event.sender.send('new', {
path: ip,
editing: false
});
});
}
})
});
ipcMain.on('close', () => {
if(!!window) {
window.close();
}
});
app.whenReady().then(() => {
globalShortcut.register('CommandOrControl+M', () => {
if(!window) {
init();
} else if(focused) {
window.close();
} else {
window.focus();
}
});
init();
});
app.on('activate', () => {
if(window === null) {
init();
}
});
app.on('window-all-closed', e => {
e.preventDefault();
});
require('./modules/cards')(window);