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"), icon: path.join(__dirname, "..", "assets", "icon.png"),
"preload-window": true, "preload-window": true,
"always-on-top": true, "always-on-top": true,
"window-position": "topCenter",
width: 700, width: 700,
height: baseHeight height: baseHeight
}); });
@ -42,7 +43,8 @@ bar.on("ready", () => {
bar.on("after-show", () => { bar.on("after-show", () => {
bar.window.setAlwaysOnTop(true); bar.window.setAlwaysOnTop(true);
bar.window.focusOnWebView(); bar.window.setResizable(false);
bar.window.focus();
bar.window.webContents.send("focusSearch"); bar.window.webContents.send("focusSearch");
}) })
@ -61,7 +63,11 @@ ipcMain.on("resize", (event, newSize) => {
/* Temporary workaround until maxogden/menubar#125 is resolved */ /* Temporary workaround until maxogden/menubar#125 is resolved */
bar.window.setSize(bar.getOption("width"), bar.getOption("height")); bar.window.setSize(bar.getOption("width"), bar.getOption("height"));
}) });
ipcMain.on("closeSearch", (event) => {
bar.hideWindow();
});
Promise.try(() => { Promise.try(() => {
return mkdirpAsync(appDirectories.userData()); return mkdirpAsync(appDirectories.userData());

@ -8,6 +8,7 @@ app
script. script.
const Promise = require("bluebird"); const Promise = require("bluebird");
const {ipcRenderer} = require("electron");
const rfr = require("rfr"); const rfr = require("rfr");
const search = rfr("lib/search/constructor-io")("CD06z4gVeqSXRiDL2ZNK"); 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 /* 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. */ * the lastQuery is still the same as when we initially made the request. */
if (lastQuery === query) { if (lastQuery === query) {
this.results = results.packages.map((pkg) => { this.results = results.packages;
return {
name: pkg.value,
description: pkg.data.description
}
});
this.update(); this.update();
} }
}); });
});
searchBox.on("cancel", () => {
ipcRenderer.send("closeSearch");
}) })
}); });

@ -19,16 +19,17 @@ search-box
case "Escape": case "Escape":
this.trigger("cancel"); this.trigger("cancel");
break; 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} .description {result.description}
script. script.
let lastResults;
Object.assign(this, { Object.assign(this, {
currentSelection: 0, currentSelection: 0,
moveSelectionDown: function() { moveSelectionDown: function() {
@ -22,7 +24,10 @@ search-results
this.on("update", () => { this.on("update", () => {
/* Reset the cursor/selection state... */ /* Reset the cursor/selection state... */
this.currentSelection = 0; if (lastResults !== opts.results) {
lastResults = opts.results;
this.currentSelection = 0;
}
}); });
style(scoped, type="scss"). style(scoped, type="scss").

@ -19,15 +19,34 @@ module.exports = function(autocompleteKey) {
return `https://ac.cnstrc.com/autocomplete/${encodeURIComponent(query)}?${createQueryString(query, options)}`; 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 Promise.try(() => {
return bhttp.get(createUrl(query, options)); if (query.trim() !== "") {
}).then((response) => { return Promise.try(() => {
if (response.statusCode === 200) { return bhttp.get(createUrl(query, options));
return response.body; }).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 { } else {
throw new Error(`Non-200 status code encountered: ${response.statusCode}`) return {
packages: [],
suggestions: []
}
} }
}); })
} }
} }
Loading…
Cancel
Save