From 2177f99ed6259cd49cdbc4f19ccd8ef6c28c9b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Franco?= Date: Mon, 24 Sep 2018 16:36:17 +0200 Subject: [PATCH] Update calculator search provider example (#7879) Remove unused imports and avoid creating unnecessary objects on each key press. --- .../calc@cinnamon.org/search_provider.js | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/docs/search-providers-examples/calc@cinnamon.org/search_provider.js b/docs/search-providers-examples/calc@cinnamon.org/search_provider.js index 0cbac6baa0..4e5b99e9ba 100644 --- a/docs/search-providers-examples/calc@cinnamon.org/search_provider.js +++ b/docs/search-providers-examples/calc@cinnamon.org/search_provider.js @@ -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]); } } }