-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
94 lines (80 loc) · 2.23 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
const { app, BrowserWindow, Tray, Menu, MenuItem } = require('electron');
const process = require('process');
const path = require('path');
const Store = require('./store.js');
console.log(process.argv);
let win, tray;
let winHidden = 0;
let appIconLoc = app.getAppPath() + "/ntfy.png";
const store = new Store({
configName: 'prefs',
defaults: {
instanceURL: "https://ntfy.sh/app"
}
});
const prompt = require("custom-electron-prompt");
Menu.setApplicationMenu(Menu.buildFromTemplate([
{
label: 'Options',
submenu: [
{
label: "Set ntfy instance URL",
click: function() {
prompt({
title: "ntfy-electron",
label: 'ntfy instance URL:',
value: store.get("instanceURL"),
inputAttrs: {
type: 'url'
},
type: 'input'
})
.then((response) => {
if((response !== null)) {
store.set("instanceURL", response);
win.loadURL(response);
}
})
.catch(console.error);
}
}
]
}
]));
function ready() {
win = new BrowserWindow({
width: 1280,
height: 720,
icon: appIconLoc,
title: "ntfy-electron"
});
win.loadURL(store.get("instanceURL"));
win.on('closed', () => {
win = null;
});
win.webContents.on('new-window', (event, url) => {
event.preventDefault();
win.loadURL(url);
});
tray = new Tray(appIconLoc);
tray.setToolTip("ntfy-electron | click to hide/show main window");
tray.on("click", function() {
if(winHidden) {
winHidden = 0;
win.show();
} else {
winHidden = 1;
win.hide();
}
});
win.on("page-title-updated", (event) => {
event.preventDefault();
});
for(i = 0; i < process.argv.length; i++) {
if(process.argv[i] == "--hidden") {
winHidden = 1;
win.hide();
}
}
}
app.on('ready', ready);