'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, 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.focusOnWebView(); bar.window.webContents.send("focusSearch"); }) //bar.showWindow(); }); 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")); }) Promise.try(() => { return mkdirpAsync(appDirectories.userData()); }).then(() => { return rfr("lib/db/json-db")(path.join(appDirectories.userData(), "db.json")); }).then((db) => { let metadataCache = db.collection("metadataCache"); const getPackageMetadata = rfr("lib/package/fetch-metadata")({ CacheError: errors.CacheError, get: function(packageName) { try { return metadataCache.findOne({name: packageName}); } catch (err) { // FIXME throw new errors.CacheError("Not in cache"); } }, set: function(packageName, metadata) { return metadataCache.upsertBy("name", metadata); } }); });