This repository has been archived by the owner on Nov 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.js
134 lines (127 loc) · 3.27 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
const { app, Tray, Menu, BrowserWindow, shell, ipcMain } = require("electron");
const path = require("path");
const Store = require("electron-store");
const platformInfo = require("electron-platform");
const JIRAService = require("./service");
const iconPath = platformInfo.isWin32
? path.join(__dirname, "build", "icon.ico")
: path.join(__dirname, "build", "icons", "32x32.png");
const store = new Store({
defaults: {
hostname: "",
password: "",
username: "",
first_time: true
}
});
const service = new JIRAService(store.store);
let appTray = null;
let win = null;
let configureWindow = null;
const validateConfiguration = (type, value) => {
if (type === "hostname") {
}
};
const configureHelper = () => {
if (configureWindow) {
configureWindow.focus();
return;
}
configureWindow = new BrowserWindow({
width: 400,
height: 250,
title: "Configure the JIRA Helper",
resizable: false,
movable: true,
minimizable: false,
maximizable: false,
autoHideMenuBar: true,
webPreferences: {
devTools: false
},
alwaysOnTop: false,
frame: true
});
configureWindow.loadURL(
"file://" + path.join(__dirname, "public", "configure.html")
);
configureWindow.webContents.on("did-finish-load", () => {
configureWindow.webContents.send("fill-values", store.store);
});
ipcMain.on("updated-values", (event, arg) => {
console.log("Configuration updated. Refreshing list");
store.set("first_time", false);
store.set(arg);
service.opts = store.store;
event.returnValue = true;
getAllIssues();
});
configureWindow.on("closed", () => {
configureWindow = null;
});
};
const commonMenu = [
{
label: "Configure",
click: configureHelper
},
{
label: "Refresh",
click: getAllIssues
},
{
role: "quit"
}
];
function getAllIssues() {
appTray.setToolTip("Loading your issues...");
appTray.setContextMenu(Menu.buildFromTemplate(commonMenu));
service
.fetchMyJIRAIssues()
.then((issues = []) =>
issues.map(({ summary, key, transitions = [] }) => ({
label: `[${key}] ${summary}`,
submenu: [
...transitions.map(({ name, id }) => ({
label: `Mark as '${name}'`,
click: () => service.doTransition(key, id).then(getAllIssues)
})),
{ type: "separator" },
{
label: "Open in browser",
click: () => {
shell.openExternal(
`https://${store.get("hostname")}/browse/${key}`
);
}
}
]
}))
)
.then(issuesMenu => [...issuesMenu, { type: "separator" }, ...commonMenu])
.then(Menu.buildFromTemplate)
.then(contextMenu => appTray.setContextMenu(contextMenu))
.then(() => {
console.info("Loaded issues succesfully.");
appTray.setToolTip("Right-click to view your issues.");
})
.catch(error => {
console.error(error.message);
appTray.setToolTip("Error loading issues.");
});
}
app.on("ready", function() {
win = new BrowserWindow({
autoHideMenuBar: true,
webPreferences: {
devTools: false
},
show: false
});
appTray = new Tray(iconPath);
if (store.get("first_time")) {
configureHelper();
} else {
getAllIssues();
}
});