From 546e438943ca1930b25037788aa8c59cc0a552cc Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Mon, 27 Jan 2025 21:45:17 +0000 Subject: [PATCH] Allow background actions to be scoped by platform --- core/modules/background-actions.js | 28 +++++++++++++------ .../wiki/SampleBackgroundAction Dark Mode.tid | 3 +- .../background-actions/AutoCompilePalette.tid | 4 ++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/core/modules/background-actions.js b/core/modules/background-actions.js index 95b4a611e..bfeb03338 100644 --- a/core/modules/background-actions.js +++ b/core/modules/background-actions.js @@ -90,15 +90,27 @@ function BackgroundActionTracker(options) { fnProcess: function(changes) { if(self.hasChanged) { self.hasChanged = false; - self.wiki.invokeActionString( - self.actions, - null, - { - title: self.title - },{ - parentWidget: $tw.rootWidget + console.log("Processing background action",self.title); + var tiddler = self.wiki.getTiddler(self.title), + doActions = true; + if(tiddler && tiddler.fields.platforms) { + doActions = false; + var platforms = $tw.utils.parseStringArray(tiddler.fields.platforms); + if(($tw.browser && platforms.indexOf("browser") !== -1) || ($tw.node && platforms.indexOf("node") !== -1)) { + doActions = true; } - ); + } + if(doActions) { + self.wiki.invokeActionString( + self.actions, + null, + { + title: self.title + },{ + parentWidget: $tw.rootWidget + } + ); + } } } }); diff --git a/core/wiki/SampleBackgroundAction Dark Mode.tid b/core/wiki/SampleBackgroundAction Dark Mode.tid index 47bd44734..34c41c5ce 100644 --- a/core/wiki/SampleBackgroundAction Dark Mode.tid +++ b/core/wiki/SampleBackgroundAction Dark Mode.tid @@ -1,5 +1,6 @@ title: SampleBackgroundAction: Dark Mode -tags: $:/tags/BackgroundAction $:/tags/StartupAction +tags: $:/tags/BackgroundAction $:/tags/StartupAction/Browser +platforms: browser track-filter: [{$:/info/browser/darkmode}] <%if [{$:/info/browser/darkmode}match[no]] %> diff --git a/core/wiki/background-actions/AutoCompilePalette.tid b/core/wiki/background-actions/AutoCompilePalette.tid index 112ae9135..21b9bdfd5 100644 --- a/core/wiki/background-actions/AutoCompilePalette.tid +++ b/core/wiki/background-actions/AutoCompilePalette.tid @@ -1,6 +1,8 @@ title: $:/core/background-actions/AutoCompilePalette tags: $:/tags/BackgroundAction $:/tags/StartupAction -track-filter: [[$:/palette]] +[changecount[]] +platforms: browser +track-filter: [[$:/palette]] +[changecount[]] \import [subfilter{$:/core/config/GlobalImportFilter}] +<$action-log $message="AutoCompilePalette" darkmode={{$:/info/browser/darkmode}} palette={{$:/palette}}/> <>