You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.9 KiB
JavaScript

'use strict';
const Promise = require("bluebird");
const path = require("path");
const menubar = require("menubar");
const appDirectory = require("appdirectory");
const xtend = require("xtend");
const mkdirpAsync = Promise.promisify(require("mkdirp"));
const fileUrl = require("file-url");
const rfr = require("rfr");
const {app, globalShortcut, ipcMain} = require("electron");
const errors = rfr("lib/util/errors");
const executeFunction = rfr("lib/electron/execute-function");
let appDirectories = new appDirectory("npmbar");
let cacheExpiry = 300;
let baseHeight = 58;
console.log("Creating menubar...")
let bar = menubar({
index: fileUrl(path.join(__dirname, "views", "index.html")),
icon: path.join(__dirname, "..", "assets", "icon.png"),
"preload-window": true,
"always-on-top": true,
"window-position": "topCenter",
width: 700,
height: baseHeight
});
bar.on("ready", () => {
//bar.window.toggleDevTools();
globalShortcut.register("F8", () => {
if (bar.window.isVisible()) {
bar.hideWindow();
} else {
bar.showWindow();
}
});
bar.on("after-show", () => {
bar.window.setAlwaysOnTop(true);
bar.window.setResizable(false);
bar.window.focus();
bar.window.webContents.send("focusSearch");
})
//bar.showWindow();
});
bar.on("request-quit", () => {
app.quit();
});
ipcMain.on("resize", (event, newSize) => {
if (newSize.width != null) {
bar.setOption("width", newSize.width);
}
if (newSize.height != null) {
bar.setOption("height", newSize.height);
}
/* Temporary workaround until maxogden/menubar#125 is resolved */
bar.window.setSize(bar.getOption("width"), bar.getOption("height"));
});
ipcMain.on("closeSearch", (event) => {
bar.hideWindow();
});
Promise.try(() => {
return mkdirpAsync(appDirectories.userData());
}).then(() => {
return rfr("lib/db/json-db")(path.join(appDirectories.userData(), "db.json"));
}).then((db) => {
});