This repository was archived by the owner on Sep 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
122 lines (99 loc) · 2.56 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
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
const { app, BrowserWindow, Menu, ipcMain, crashReporter, shell } = require('electron');
const { autoUpdater } = require('electron-updater');
const __DEV__ = require('electron-is-dev');
const log = require('electron-log');
const path = require('path');
const menu = require('./menu');
const config = require('./config');
const fs = require('fs');
const notificationIndicator = '●';
require('electron-debug')();
if (!__DEV__ && process.platform !== 'linux') {
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'info';
autoUpdater.checkForUpdates();
}
let isQuitting = false;
let mainWindow;
let page;
const isRunning = app.makeSingleInstance(() => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.show();
}
});
if (isRunning) {
app.quit();
}
function updateBadgeInfo(title) {
if (process.platform !== 'darwin' && process.platform !== 'linux') return;
if (title.startsWith(notificationIndicator)) {
app.dock.setBadge(notificationIndicator);
} else {
app.dock.setBadge('');
}
}
function createMainWindow() {
const win = new BrowserWindow({
title: app.getName(),
width: 1000,
height: 600,
show: false,
icon: path.join(__dirname, 'build', 'icon.icns'),
minWidth: 800,
minHeight: 600,
vibrancy: 'light',
titleBarStyle: 'hidden-inset',
maximizable: false,
fullscreenable: false,
webPreferences: {
nodeIntegration: false,
preload: path.join(__dirname, 'browser.js'),
plugins: true
}
});
win.setSheetOffset(41);
win.loadURL('https://app.asana.com/');
win.on('close', (e) => {
if (!isQuitting) {
e.preventDefault();
if (process.platform === 'darwin') {
app.hide();
} else {
win.hide();
}
}
});
win.on('page-title-updated', (e, title) => {
e.preventDefault();
updateBadgeInfo(title);
});
return win;
}
ipcMain.on('set-vibrancy', () => {
if (config.get('vibrancy')) {
mainWindow.setVibrancy('light');
} else {
mainWindow.setVibrancy(null);
}
});
ipcMain.on('update-menu', () => {
Menu.setApplicationMenu(menu.slice(1));
})
app.on('activate', () => mainWindow.show());
app.on('before-quit', () => isQuitting = true);
app.on('ready', () => {
mainWindow = createMainWindow();
page = mainWindow.webContents;
// Open new browser window on external open
page.on('new-window', (event, url) => {
event.preventDefault();
shell.openExternal(url);
});
// Set the menu application menu
Menu.setApplicationMenu(menu);
page.on('dom-ready', function() {
page.insertCSS(fs.readFileSync(path.join(__dirname, 'browser.css'), 'utf8'));
mainWindow.show();
});
});