-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.js
executable file
·156 lines (119 loc) · 2.84 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
'use strict';
// Require Electron modules
const app = require('electron').app;
const shell = require('electron').shell;
const ipc = require('electron').ipcMain;
const BrowserWindow = require('electron').BrowserWindow;
const Menu = require('electron').Menu;
// Require Node modules
const path = require('path');
const fs = require('fs');
// Require local modules
const storage = require('./storage');
// Get URL of ActiveCollab installation
const acURL = storage.get('acURL') || 'https://my.activecollab.com/';
// Require download component
require('electron-dl')();
let locale;
let mainWindow;
let isQuitting = false;
// Function for creating the main window
function createMainWindow()
{
// Open window with default size or last window state
const lastWindowState = storage.get('lastWindowState') || {width: 1024, height: 768};
// Check if window was opened fullscreen
const isFullscreen = storage.get('isFullscreen') || false;
// Create new browser window
const win = new BrowserWindow(
{
title: app.getName(),
show: false,
x: lastWindowState.x,
y: lastWindowState.y,
width: lastWindowState.width,
height: lastWindowState.height,
icon: process.platform === 'linux' && path.join(__dirname, 'media', 'Icon.png'),
minWidth: 800,
minHeight: 600,
titleBarStyle: 'default',
webPreferences:
{
nodeIntegration: false,
preload: path.join(__dirname, 'browser.js'),
webSecurity: true,
plugins: false
}
});
// Window close callback
win.on('close', function(e)
{
if (process.platform == 'darwin' && !isQuitting)
{
e.preventDefault();
win.hide();
}
else
{
app.quit();
}
});
win.loadURL(acURL);
win.setFullScreen(isFullscreen);
return win;
}
// App ready callback
app.on('ready', function()
{
locale = app.getLocale();
mainWindow = createMainWindow();
const page = mainWindow.webContents;
// Set application menu based on locale
switch (locale)
{
case 'de': // German
Menu.setApplicationMenu(require('./menus/de'));
break;
default: // Defaults to English
Menu.setApplicationMenu(require('./menus/en'));
}
// Document ready callback
page.on('dom-ready', function()
{
mainWindow.show();
});
// New window callback
page.on('new-window', function(e, url)
{
e.preventDefault();
if (/(app|my)\.activecollab\.com/.test(url))
{
// Internal links
mainWindow.loadURL(url);
}
else
{
// External link
shell.openExternal(url);
}
});
});
// App activate callback
app.on('activate', function()
{
mainWindow.show();
});
// App before quit callback
app.on('before-quit', function()
{
isQuitting = true;
if (!mainWindow.isFullScreen())
{
storage.set('lastWindowState', mainWindow.getBounds());
storage.set('isFullscreen', false);
}
else
{
storage.set('isFullscreen', true);
}
});