Change bar position to topCenter, fix Constructor.io search on empty query, let ESC close the search bar, fix result selection

master
Sven Slootweg 8 years ago
parent 7a3f25c261
commit a6bf21c501

@ -26,6 +26,7 @@ let bar = menubar({
icon: path.join(__dirname, "..", "assets", "icon.png"),
"preload-window": true,
"always-on-top": true,
"window-position": "topCenter",
width: 700,
height: baseHeight
});
@ -42,7 +43,8 @@ bar.on("ready", () => {
bar.on("after-show", () => {
bar.window.setAlwaysOnTop(true);
bar.window.focusOnWebView();
bar.window.setResizable(false);
bar.window.focus();
bar.window.webContents.send("focusSearch");
})
@ -61,7 +63,11 @@ ipcMain.on("resize", (event, newSize) => {
/* 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());

@ -8,6 +8,7 @@ app
script.
const Promise = require("bluebird");
const {ipcRenderer} = require("electron");
const rfr = require("rfr");
const search = rfr("lib/search/constructor-io")("CD06z4gVeqSXRiDL2ZNK");
@ -37,15 +38,14 @@ app
/* Sometimes, search results may come back out of order. Here we check whether
* the lastQuery is still the same as when we initially made the request. */
if (lastQuery === query) {
this.results = results.packages.map((pkg) => {
return {
name: pkg.value,
description: pkg.data.description
}
});
this.results = results.packages;
this.update();
}
});
});
searchBox.on("cancel", () => {
ipcRenderer.send("closeSearch");
})
});

@ -19,16 +19,17 @@ search-box
case "Escape":
this.trigger("cancel");
break;
default:
let searchInput = this.root.querySelector(".search");
if (searchInput.value !== lastKnownQuery) {
lastKnownQuery = searchInput.value;
this.trigger("queryChanged", searchInput.value);
}
return true;
break;
}
let searchInput = this.root.querySelector(".search");
if (searchInput.value !== lastKnownQuery) {
lastKnownQuery = searchInput.value;
this.trigger("queryChanged", searchInput.value);
}
return true;
}
})

@ -4,6 +4,8 @@ search-results
.description {result.description}
script.
let lastResults;
Object.assign(this, {
currentSelection: 0,
moveSelectionDown: function() {
@ -22,7 +24,10 @@ search-results
this.on("update", () => {
/* Reset the cursor/selection state... */
this.currentSelection = 0;
if (lastResults !== opts.results) {
lastResults = opts.results;
this.currentSelection = 0;
}
});
style(scoped, type="scss").

@ -19,15 +19,34 @@ module.exports = function(autocompleteKey) {
return `https://ac.cnstrc.com/autocomplete/${encodeURIComponent(query)}?${createQueryString(query, options)}`;
}
return function doSearch(query, options) {
return function doSearch(query, options = {}) {
return Promise.try(() => {
return bhttp.get(createUrl(query, options));
}).then((response) => {
if (response.statusCode === 200) {
return response.body;
if (query.trim() !== "") {
return Promise.try(() => {
return bhttp.get(createUrl(query, options));
}).then((response) => {
if (response.statusCode === 200) {
console.log(response.body);
return {
packages: response.body.sections.packages.map((pkg) => {
return {
name: pkg.value,
description: pkg.data.description
}
}),
suggestions: response.body.sections.standard
};
} else {
throw new Error(`Non-200 status code encountered: ${response.statusCode}`)
}
});
} else {
throw new Error(`Non-200 status code encountered: ${response.statusCode}`)
return {
packages: [],
suggestions: []
}
}
});
})
}
}
Loading…
Cancel
Save