Tasks Query That Looks at Line Before List OR fs.readFileSync equivalent that works on mobile

Hi all,

I’ve been working on a custom filter for Obsidian Tasks that allows me to filter based on whether a tag is present on the line before the start of the checklist that the task is located on. The intention behind this is to be able to write a tag like #task-list then underneath the tag add a bunch of list items, and they will all be picked up by the tasks query.

I have been able to accomplish this on desktop, however it use “path” and “fs” inside of the adapter API, which aren’t supported on mobile. Does anyone know of a way I can accomplish this on mobile, or of a way that I can synchronously read a file’s content on mobile? (Note: must be synchronous because the Tasks plugin executes synchronously so we cannot use “await”).

Here is my current filter. Note that I have formatted it to be easier to read here.

filter by function {
	const basePath = app.vault.adapter.basePath
	let fullPath = app.vault.adapter.path.join(basePath, task.file.path)
	let fileContent = app.vault.adapter.fs.readFileSync(fullPath, {
		encoding: "utf-8",
	})
	let previousLineNumber = task.taskLocation.sectionStart - 1
	let startLine = fileContent.split("\n")[previousLineNumber]
	console.log(startLine)
	{
		if (startLine !== undefined && startLine.includes("#task-list")) {
			return true
		}
	}
	return false
}

Thanks!

DCA
(David Carli Arnold)