2026-03-28 14:57:46 +00:00
|
|
|
#./apps/zen.nix
|
2026-03-28 15:01:29 +00:00
|
|
|
{ inputs, pkgs, lib, config, ... }:
|
2026-08-31 19:15:50 +01:00
|
|
|
let
|
|
|
|
|
# Autoconfig (mozilla.cfg) runs privileged JS in the parent process at
|
|
|
|
|
# startup — the only scriptable way into chrome, since Gecko has no reload
|
|
|
|
|
# for userChrome.css and Zen exposes no command for one.
|
|
|
|
|
#
|
|
|
|
|
# So don't use userChrome.css at all for the wallpaper theme. Register
|
|
|
|
|
# <profile>/chrome/zen-theme.css as a style-sheet-service USER_SHEET here
|
|
|
|
|
# and re-register it under a cache-busting URI whenever its mtime moves —
|
|
|
|
|
# that is what makes a `theme-apply` switch land in a running Zen
|
2026-08-31 19:26:50 +01:00
|
|
|
# (settings/theming.nix writes that file on every switch).
|
|
|
|
|
#
|
2026-08-31 19:35:08 +01:00
|
|
|
# theming.nix still writes userChrome.css too, so a broken watcher costs the
|
|
|
|
|
# live update and nothing else. Whether the watcher can win at all is the
|
|
|
|
|
# open question: nsIStyleSheetService documents its user sheets as ordered
|
|
|
|
|
# BEFORE the profile's userChrome.css, which would let the startup copy
|
|
|
|
|
# outrank every sheet we register.
|
2026-08-31 19:26:50 +01:00
|
|
|
#
|
2026-08-31 19:40:57 +01:00
|
|
|
# Everything here goes through Components.classes rather than `Services`,
|
|
|
|
|
# which is not a global in this scope.
|
|
|
|
|
#
|
|
|
|
|
# None of it runs without general.config.sandbox_enabled=false below: since
|
|
|
|
|
# Firefox 62 autoconfig is sandboxed down to pref()/defaultPref(), so
|
|
|
|
|
# `Components` is undefined and the script throws on its first line — as does
|
|
|
|
|
# the catch that would have reported it.
|
2026-08-31 19:26:50 +01:00
|
|
|
#
|
|
|
|
|
# Diagnosing a silent failure: about:config -> fred.zenTheme.status holds
|
|
|
|
|
# "ok <mtime>", "missing <path>" or "error <exception>" from the last pass.
|
2026-08-31 19:15:50 +01:00
|
|
|
themeHotReload = ''
|
|
|
|
|
try {
|
2026-08-31 19:26:50 +01:00
|
|
|
const kCc = Components.classes;
|
|
|
|
|
const kCi = Components.interfaces;
|
2026-08-31 19:15:50 +01:00
|
|
|
const sss = kCc["@mozilla.org/content/style-sheet-service;1"]
|
|
|
|
|
.getService(kCi.nsIStyleSheetService);
|
2026-08-31 19:26:50 +01:00
|
|
|
const io = kCc["@mozilla.org/network/io-service;1"]
|
|
|
|
|
.getService(kCi.nsIIOService);
|
|
|
|
|
const dirs = kCc["@mozilla.org/file/directory_service;1"]
|
|
|
|
|
.getService(kCi.nsIProperties);
|
|
|
|
|
const prefs = kCc["@mozilla.org/preferences-service;1"]
|
|
|
|
|
.getService(kCi.nsIPrefBranch);
|
|
|
|
|
|
|
|
|
|
const note = (msg) => {
|
|
|
|
|
try { prefs.setStringPref("fred.zenTheme.status", msg); } catch (e) {}
|
|
|
|
|
};
|
2026-08-31 19:15:50 +01:00
|
|
|
|
|
|
|
|
let live = null;
|
|
|
|
|
|
|
|
|
|
const apply = () => {
|
2026-08-31 19:26:50 +01:00
|
|
|
try {
|
|
|
|
|
// Resolved per pass, not once: autoconfig runs early enough that
|
|
|
|
|
// ProfD is not guaranteed yet, and a throw here would kill the timer
|
|
|
|
|
// for the whole session.
|
|
|
|
|
const file = dirs.get("ProfD", kCi.nsIFile);
|
|
|
|
|
file.append("chrome");
|
|
|
|
|
file.append("zen-theme.css");
|
|
|
|
|
if (!file.exists()) { note("missing " + file.path); return; }
|
|
|
|
|
|
|
|
|
|
// install(1) stamps the copy with the current time, so mtime alone
|
|
|
|
|
// distinguishes one wallpaper's sheet from the next.
|
|
|
|
|
const stamp = String(file.lastModifiedTime);
|
|
|
|
|
if (stamp === live) return;
|
|
|
|
|
|
|
|
|
|
// A fresh query string dodges the CSS loader's per-URI cache; without
|
|
|
|
|
// it a re-register would hand back the sheet parsed at startup.
|
|
|
|
|
const base = io.newFileURI(file).spec;
|
|
|
|
|
sss.loadAndRegisterSheet(io.newURI(base + "?" + stamp), sss.USER_SHEET);
|
|
|
|
|
if (live !== null) {
|
|
|
|
|
const old = io.newURI(base + "?" + live);
|
|
|
|
|
if (sss.sheetRegistered(old, sss.USER_SHEET))
|
|
|
|
|
sss.unregisterSheet(old, sss.USER_SHEET);
|
|
|
|
|
}
|
|
|
|
|
live = stamp;
|
|
|
|
|
note("ok " + stamp);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
note("error " + e);
|
2026-08-31 19:15:50 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const timer = kCc["@mozilla.org/timer;1"].createInstance(kCi.nsITimer);
|
|
|
|
|
// The observer service holds the only strong reference that keeps the
|
|
|
|
|
// timer (and this closure) off the GC's list for the session.
|
2026-08-31 19:26:50 +01:00
|
|
|
kCc["@mozilla.org/observer-service;1"].getService(kCi.nsIObserverService)
|
|
|
|
|
.addObserver({ timer, observe() {} }, "quit-application");
|
2026-08-31 19:15:50 +01:00
|
|
|
timer.initWithCallback({ notify: apply }, 2000,
|
|
|
|
|
kCi.nsITimer.TYPE_REPEATING_SLACK);
|
|
|
|
|
apply();
|
|
|
|
|
} catch (e) {
|
2026-08-31 19:26:50 +01:00
|
|
|
Components.utils.reportError("zen-theme: " + e);
|
2026-08-31 19:15:50 +01:00
|
|
|
}
|
|
|
|
|
'';
|
|
|
|
|
in
|
2026-03-28 14:54:56 +00:00
|
|
|
{
|
2026-03-28 15:01:29 +00:00
|
|
|
config = lib.mkIf (lib.elem config.networking.hostName [ "FredOS-Gaming" "FredOS-Macbook" ]) {
|
|
|
|
|
environment.systemPackages = [
|
2026-08-31 19:15:50 +01:00
|
|
|
(inputs.zen-browser.packages.${pkgs.stdenv.hostPlatform.system}.default.override {
|
2026-08-31 19:40:57 +01:00
|
|
|
# Lands in defaults/pref/autoconfig.js, the only place this pref is
|
|
|
|
|
# read — setting it from mozilla.cfg is too late to unsandbox itself.
|
|
|
|
|
extraAutoConfig = ''pref("general.config.sandbox_enabled", false);'';
|
2026-08-31 19:15:50 +01:00
|
|
|
extraPrefs = themeHotReload;
|
|
|
|
|
})
|
2026-03-28 15:01:29 +00:00
|
|
|
];
|
|
|
|
|
};
|
2026-08-31 19:15:50 +01:00
|
|
|
}
|