-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
135 lines (113 loc) · 3.44 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;
var screen;
const path = require('path')
const url = require('url')
const windowStateKeeper = require('electron-window-state');
gm_music = require('./gm_music_lib/bin/win32-x64-53/gm_music_lib.node');
gm_music.initialize();
gm_music.openDefaultStream();
let win
/************************/
/********Database********/
const Datastore = require('./include/nedb')
let db_filename = path.join(app.getPath('userData'), 'something.db');
db = new Datastore({
filename: db_filename,
autoload: true,
compareStrings: "localeCompare",
});
/***********************/
function createWindow() {
let mainWindowState = windowStateKeeper({
defaultWidth: 800,
defaultHeight: 600,
fullScreen: false
});
var dirtyFlashHack = false; //(process.platform=='win32');
win = new BrowserWindow({
'x': dirtyFlashHack ? -4000 : mainWindowState.x,
'y': dirtyFlashHack ? -4000 : mainWindowState.y,
'width': mainWindowState.width,
'height': mainWindowState.height,
'frame': false,
'show': false,
'backgroundColor': '#FFF',
'transparent': false,
'fullscreenable': false,
'minWidth': 600,
'minHeight': 500,
});
win.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
mainWindowState.manage(win);
// win.webContents.on('dom-ready', function () {
// // if(dirtyFlashHack){ // @bug ?
// // console.log('dirtyFlashHack: true')
// // win.show();
// // win.hide();
// // if(mainWindowState.x < 0 && mainWindowState.y < 0){
// // win.setPosition(0, 0, false);
// // }
// // else{
// // win.setPosition(mainWindowState.x, mainWindowState.y, false);
// // }
// // mainWindowState.manage(win);
// // win.show();
// // }
// // else{
// // win.show();
// // }
// });
// win.webContents.openDevTools()
var mouse_in_win = false;
function checkWindowLeaveEvent() {
var old_mouse_in_win = mouse_in_win;
var bounds = win.getBounds();
var pos = screen.getCursorScreenPoint();
mouse_in_win = (
pos.x > bounds.x && pos.x < bounds.x + bounds.width &&
pos.y > bounds.y && pos.y < bounds.y + bounds.height
);
if (!mouse_in_win && old_mouse_in_win) {
win.webContents.sendInputEvent({
type: "mouseLeave",
x: 0,
y: 0
});
}
}
var checkWindowLeaveTimer = setInterval(checkWindowLeaveEvent, 50);
win.show();
win.on('closed', () => {
clearInterval(checkWindowLeaveTimer);
win = null;
})
win.on('maximize', () => {
win.webContents.send('maximize', '')
})
win.on('unmaximize', () => {
win.webContents.send('unmaximize', '')
})
}
// electron.app.on('browser-window-created',function(e,window) {
// window.setMenu(null);
// });
app.on('ready', () => {
screen = electron.screen;
createWindow();
});
app.on('window-all-closed', () => {
gm_music.closeStream();
gm_music.terminate();
app.quit()
})
app.on('activate', () => {})
const ipc = require('electron').ipcMain
ipc.on('get_win_id', function(event, arg) {
event.returnValue = win.id;
});