-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 1319,5450,1285 - FilterEngine and Updater JS api separation
Moved Updater class to dedicated header and source files. Created apiUpdater.js with a separate API for Updater component. Updated unit tests. Signed-off-by: Krystian Zlomek [email protected]
- Loading branch information
Krystian Zlomek
committed
Oct 9, 2018
1 parent
9fb9625
commit 0a3f088
Showing
14 changed files
with
539 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* This file is part of Adblock Plus <https://adblockplus.org/>, | ||
* Copyright (C) 2006-present eyeo GmbH | ||
* | ||
* Adblock Plus is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as | ||
* published by the Free Software Foundation. | ||
* | ||
* Adblock Plus is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef ADBLOCK_PLUS_UPDATER_H | ||
#define ADBLOCK_PLUS_UPDATER_H | ||
|
||
#include <functional> | ||
#include <string> | ||
#include <AdblockPlus/JsEngine.h> | ||
#include <AdblockPlus/JsValue.h> | ||
|
||
namespace AdblockPlus | ||
{ | ||
/** | ||
* Component of libadblockplus responsible for Update checks for the application. | ||
*/ | ||
class Updater | ||
{ | ||
public: | ||
/** | ||
* Callback type invoked when an update becomes available. | ||
* The parameter is the download URL of the update. | ||
*/ | ||
typedef std::function<void(const std::string&)> UpdateAvailableCallback; | ||
|
||
/** | ||
* Callback type invoked when a manually triggered update check finishes. | ||
* The parameter is an optional error message. | ||
*/ | ||
typedef std::function<void(const std::string&)> UpdateCheckDoneCallback; | ||
|
||
/** | ||
* Sets the callback invoked when an application update becomes available. | ||
* @param callback Callback to invoke. | ||
*/ | ||
void SetUpdateAvailableCallback(const UpdateAvailableCallback& callback); | ||
|
||
/** | ||
* Removes the callback invoked when an application update becomes | ||
* available. | ||
*/ | ||
void RemoveUpdateAvailableCallback(); | ||
|
||
/** | ||
* Callback type for evaluating JS expression. | ||
* The parameter is the JS file name containing the expression. | ||
*/ | ||
typedef std::function<void(const std::string&)> EvaluateCallback; | ||
|
||
/** | ||
* Forces an immediate update check. | ||
* `Updater` will automatically check for updates in regular intervals, | ||
* so applications should only call this when the user triggers an update | ||
* check manually. | ||
* @param callback Optional callback to invoke when the update check is | ||
* finished. The string parameter will be empty when the update check | ||
* succeeded, or contain an error message if it failed. | ||
* Note that the callback will be invoked whether updates are | ||
* available or not - to react to updates being available, use | ||
* `Updater::SetUpdateAvailableCallback()`. | ||
*/ | ||
void ForceUpdateCheck(const UpdateCheckDoneCallback& callback = UpdateCheckDoneCallback()); | ||
|
||
/** | ||
* Retrieves a preference value. | ||
* @param pref Preference name. | ||
* @return Preference value, or `null` if it doesn't exist. | ||
*/ | ||
JsValue GetPref(const std::string& pref) const; | ||
|
||
/** | ||
* Sets a preference value. | ||
* @param pref Preference name. | ||
* @param value New value of the preference. | ||
*/ | ||
void SetPref(const std::string& pref, const JsValue& value); | ||
|
||
explicit Updater(const JsEnginePtr& jsEngine, const EvaluateCallback& callback); | ||
|
||
private: | ||
JsEnginePtr jsEngine; | ||
int updateCheckId; | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* This file is part of Adblock Plus <https://adblockplus.org/>, | ||
* Copyright (C) 2006-present eyeo GmbH | ||
* | ||
* Adblock Plus is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 3 as | ||
* published by the Free Software Foundation. | ||
* | ||
* Adblock Plus is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
"use strict"; | ||
|
||
let API_UPDATER = (() => | ||
{ | ||
const {Prefs} = require("prefs"); | ||
const {checkForUpdates} = require("updater"); | ||
|
||
return { | ||
getPref(pref) | ||
{ | ||
return Prefs[pref]; | ||
}, | ||
|
||
setPref(pref, value) | ||
{ | ||
Prefs[pref] = value; | ||
}, | ||
|
||
forceUpdateCheck(eventName) | ||
{ | ||
checkForUpdates(eventName ? _triggerEvent.bind(null, eventName) : null); | ||
} | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.