Skip to content

Commit

Permalink
Update calculator search provider example (#7879)
Browse files Browse the repository at this point in the history
Remove unused imports and avoid creating unnecessary objects
on each key press.
  • Loading branch information
germanfr authored and clefebvre committed Sep 24, 2018
1 parent e4f5d67 commit b888e56
Showing 1 changed file with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
const Mainloop = imports.mainloop;
const Gio = imports.gi.Gio;
const St = imports.gi.St;
const Util = imports.misc.util;
const Cinnamon = imports.gi.Cinnamon;

function perform_search(pattern){
push_results(pattern);
}

function push_results(results){
var default_icon_app = Cinnamon.AppSystem.get_default().lookup_app("gcalctool.desktop");
var pattern = results
var results_array = new Array();

//First Regex tests for numbers and operators, second makes sure it does not end with an operator as that is not a valid operation
if ((/^[0-9.+*/()-]+$/.test(pattern)) && !(/[.+*/(-]+$/.test(pattern))) {
/* Test for numbers and operators and make sure it does not end with
an operator, as that is not a valid operation */
if (/^[0-9.+*/()-]+[0-9\)]$/.test(pattern)) {
let solution = 0;
try {
solution = eval(pattern);
}catch(err){}

let awns = (Math.round(solution * 10000) / 10000).toString();
if (!(awns == pattern)) {
results_array.push({
if (awns != pattern) {
let default_icon_app = Cinnamon.AppSystem.get_default().lookup_app("galculator.desktop");
let result = {
id: awns,
label: _("Solution: " + awns),
label: _("Solution: %s").format(awns),
icon_app: default_icon_app
});
send_results(results_array);
};
send_results([result]);
}
}
}
Expand Down

0 comments on commit b888e56

Please sign in to comment.