Skip to content

Commit

Permalink
Merge pull request #210 in EXTENSIONS/safari-app-extension from featu…
Browse files Browse the repository at this point in the history
…re/233-1 to master

* commit '44822b828867af49e4e7141d701ddf2a48d5cdf7':
  fix rules count
  fix rules count
  #233 performance
  #233 background windows focus
  • Loading branch information
Mizzick committed Oct 10, 2019
2 parents 8057f97 + 44822b8 commit 3dc3ef3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
6 changes: 5 additions & 1 deletion ElectronMainApp/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,17 @@ app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
} else {
log.info('Hiding application window');
app.dock.hide();
}
});

app.on('browser-window-created', () => {
if (process.platform === 'darwin') {
app.dock.show();
if (!mainWindow) {
log.info('Opening application window');
app.dock.show();
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ module.exports = (function () {
let overlimit = false;

for (let group of grouped) {
let json = emptyBlockerJSON;
let json = JSON.stringify(emptyBlockerJSON);

const rulesTexts = group.rules.map(x => x.ruleText);
const result = await jsonFromRules(rulesTexts, false);
if (result && result.converted) {
json = JSON.parse(result.converted);
json = result.converted;
if (result.overLimit) {
overlimit = true;
}
Expand All @@ -63,12 +63,12 @@ module.exports = (function () {
setSafariContentBlocker(rulesGroupsBundles[group.key], json, info);
}

const advancedBlocking = await setAdvancedBlocking(rules.map(x => x.ruleText));
const advancedBlockingRulesCount = await setAdvancedBlocking(rules.map(x => x.ruleText));

listeners.notifyListeners(events.CONTENT_BLOCKER_UPDATED, {
rulesCount: rules.length,
rulesOverLimit: overlimit,
advancedBlockingRulesCount: advancedBlocking.length
advancedBlockingRulesCount: advancedBlockingRulesCount
});

});
Expand All @@ -90,16 +90,16 @@ module.exports = (function () {
/**
* Activates advanced blocking json
*
* @param rules
* @return {Array}
* @param rules array of rules
* @return {int} rules count
*/
const setAdvancedBlocking = async (rules) => {
const result = await jsonFromRules(rules, true);
const advancedBlocking = result ? JSON.parse(result.advancedBlocking) : [];
const advancedBlocking = result ? result.advancedBlocking : "[]";

setSafariContentBlocker(rulesGroupsBundles["advancedBlocking"], advancedBlocking);

return advancedBlocking;
return result ? result.advancedBlockingConvertedCount : 0;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion ElectronMainApp/src/main/app/libs/JSConverter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* AdGuard -> Safari Content Blocker converter
* Version 4.2.0
* Version 4.2.1
* License: https://github.com/AdguardTeam/SafariContentBlockerConverterCompiler/blob/master/LICENSE
*/

Expand Down Expand Up @@ -4265,6 +4265,7 @@ var jsonFromFilters = (function () {
adguard.console.info('Advanced Blocking length: ' + advancedBlocker.length);

result.advancedBlocking = JSON.stringify(advancedBlocker, null, "\t");
result.advancedBlockingConvertedCount = advancedBlocker.length;
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion ElectronMainApp/src/main/toolbar-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module.exports = (() => {
// Subscribe to application events
listeners.addListener(function (event, info) {
if (event === events.CONTENT_BLOCKER_UPDATE_REQUIRED) {
setContentBlockingJson(info.bundleId, JSON.stringify(info.json), info.info);
setContentBlockingJson(info.bundleId, info.json, info.info);
} else if (event === events.UPDATE_USER_FILTER_RULES) {
applicationApi.getUserFilterRules((rules) => {
setUserFilter(rules);
Expand Down

0 comments on commit 3dc3ef3

Please sign in to comment.