forked from trazyn/weweChat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (71 loc) · 2.32 KB
/
index.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
import fs from 'fs';
import { app, BrowserWindow, ipcMain, shell } from 'electron';
import windowStateKeeper from 'electron-window-state';
import notifier from 'node-notifier';
let mainWindow;
let userData = app.getPath('userData');
let imagesCacheDir = `${userData}/images`;
let voicesCacheDir = `${userData}/voices`;
[imagesCacheDir, voicesCacheDir].map(e => {
if (!fs.existsSync(e)) {
fs.mkdirSync(e);
}
});
const createMainWindow = () => {
var mainWindowState = windowStateKeeper({
defaultWidth: 1024,
defaultHeight: 600
});
mainWindow = new BrowserWindow({
x: mainWindowState.x,
y: mainWindowState.y,
vibrancy: 'medium-light',
transparent: true,
titleBarStyle: 'hidden-inset',
backgroundColor: 'none',
resizable: false,
webPreferences: {
scrollBounce: true
}
});
mainWindow.setSize(350, 460);
mainWindow.loadURL(`file://${__dirname}/src/index.html`);
mainWindow.webContents.on('did-finish-load', () => {
mainWindow.show();
mainWindow.focus();
});
mainWindow.webContents.on('new-window', (event, url) => {
event.preventDefault();
shell.openExternal(url);
});
mainWindow.on('closed', () => {
mainWindow = null;
app.quit();
});
ipcMain.once('logined', event => {
mainWindow.setResizable(true);
mainWindow.setSize(mainWindowState.width, mainWindowState.height);
mainWindowState.manage(mainWindow);
});
ipcMain.on('receive-message', (event, data) => {
var { icon, title, message } = data;
var filename = `${imagesCacheDir}/notifier-icon.png`;
fs.writeFileSync(filename, icon.replace(/^data:image\/png;base64,/, ''), 'base64');
notifier.notify({
title,
sound: 'Blow',
contentImage: filename,
message,
});
});
ipcMain.on('open-image', async(event, dataset, data) => {
var filename = `${imagesCacheDir}/img_${dataset.id}`;
fs.writeFileSync(filename, data.replace(/^data:image\/png;base64,/, ''), 'base64');
shell.openItem(filename);
});
ipcMain.on('open-map', (event, map) => {
event.preventDefault();
shell.openExternal(map);
});
};
app.on('ready', createMainWindow);