1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-07-05 19:42:51 +00:00

Allow background actions to be scoped by platform

This commit is contained in:
Jeremy Ruston 2025-01-27 21:45:17 +00:00
parent efcd23993e
commit 546e438943
3 changed files with 25 additions and 10 deletions

View File

@ -90,6 +90,17 @@ function BackgroundActionTracker(options) {
fnProcess: function(changes) { fnProcess: function(changes) {
if(self.hasChanged) { if(self.hasChanged) {
self.hasChanged = false; self.hasChanged = false;
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.wiki.invokeActionString(
self.actions, self.actions,
null, null,
@ -101,6 +112,7 @@ function BackgroundActionTracker(options) {
); );
} }
} }
}
}); });
} }

View File

@ -1,5 +1,6 @@
title: SampleBackgroundAction: Dark Mode title: SampleBackgroundAction: Dark Mode
tags: $:/tags/BackgroundAction $:/tags/StartupAction tags: $:/tags/BackgroundAction $:/tags/StartupAction/Browser
platforms: browser
track-filter: [{$:/info/browser/darkmode}] track-filter: [{$:/info/browser/darkmode}]
<%if [{$:/info/browser/darkmode}match[no]] %> <%if [{$:/info/browser/darkmode}match[no]] %>

View File

@ -1,6 +1,8 @@
title: $:/core/background-actions/AutoCompilePalette title: $:/core/background-actions/AutoCompilePalette
tags: $:/tags/BackgroundAction $:/tags/StartupAction tags: $:/tags/BackgroundAction $:/tags/StartupAction
platforms: browser
track-filter: [[$:/palette]] +[changecount[]] track-filter: [[$:/palette]] +[changecount[]]
\import [subfilter{$:/core/config/GlobalImportFilter}] \import [subfilter{$:/core/config/GlobalImportFilter}]
<$action-log $message="AutoCompilePalette" darkmode={{$:/info/browser/darkmode}} palette={{$:/palette}}/>
<<actions-recompile-current-palette>> <<actions-recompile-current-palette>>