1
0
Fork 1
mirror of https://github.com/zen-browser/desktop.git synced 2025-07-08 00:10:00 +02:00

feat: Mark stylesheets as changed when updating mods, b=no-bug, c=mods

This commit is contained in:
mr. m 2025-07-01 13:28:34 +02:00
parent 4f049111b1
commit 27b03a7675
No known key found for this signature in database
GPG key ID: 928E01ED4C97749F
4 changed files with 34 additions and 6 deletions

View file

@ -0,0 +1,13 @@
diff --git a/layout/base/nsStyleSheetService.h b/layout/base/nsStyleSheetService.h
index 8c49b338bf8e6830874ace9a08e8c0713167ee58..115bf09314970fd2fe79793e9cf8e0c40eb0459b 100644
--- a/layout/base/nsStyleSheetService.h
+++ b/layout/base/nsStyleSheetService.h
@@ -50,6 +50,8 @@ class nsStyleSheetService final : public nsIStyleSheetService,
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
+ void ZenMarkStylesAsChanged();
+
static nsStyleSheetService* GetInstance();
static nsStyleSheetService* gInstance;

View file

@ -42,10 +42,8 @@
await this.#rebuildModsStylesheet();
}
#getStylesheetURIForMod(mod) {
return Services.io.newFileURI(
new FileUtils.File(PathUtils.join(this.getModFolder(mod.id), 'chrome.css'))
);
#getStylesheetPathForMod(mod) {
return PathUtils.join(this.getModFolder(mod.id), 'chrome.css');
}
async #readStylesheet() {
@ -223,7 +221,7 @@
const mods = [];
for (let mod of modList) {
mod._chromeURL = this.#getStylesheetURIForMod(mod).spec;
mod._filePath = this.#getStylesheetPathForMod(mod);
mods.push(mod);
}
@ -244,7 +242,8 @@
content += `/* Readme: ${mod.readme} */\n`;
}
content += `@import url("${mod._chromeURL}");\n`;
const chromeContent = await IOUtils.readUTF8(mod._filePath);
content += chromeContent;
}
content += this.#kZenStylesheetModFooter;

View file

@ -8,6 +8,8 @@
#include "nsCOMPtr.h"
#include "nsIFile.h"
#include "nsStyleSheetService.h"
#include "mozilla/css/SheetParsingMode.h"
#include "mozilla/GlobalStyleSheetCache.h"
@ -82,6 +84,9 @@ nsresult ZenStyleSheetCache::RebuildModsStylesheets(const nsACString& aContents)
}
ErrorResult aRv;
sheet->ReparseSheet(aContents, aRv);
if (auto sss = nsStyleSheetService::GetInstance()) {
sss->ZenMarkStylesAsChanged();
}
return aRv.StealNSResult();
}

View file

@ -51,3 +51,14 @@ auto nsZenModsBackend::RebuildModsStyles(const nsACString& aContents) -> nsresul
}
} // namespace: zen
auto nsStyleSheetService::ZenMarkStylesAsChanged() -> void {
for (auto& presShell : mPresShells) {
if (presShell) {
if (auto doc = presShell->GetDocument(); doc && doc->IsInChromeDocShell()) {
// Notify the document that styles have changed.
doc->ApplicableStylesChanged();
}
}
}
}