From 8dc90acfaba507cb5f70426cf234d2b892c33d87 Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Sat, 16 Nov 2024 03:34:54 +0300 Subject: [PATCH] Neovim: Silence this annoying piece of software. --- home/config/nvim/default.nix | 1 - home/config/nvim/module/config/Notify.nix | 18 - home/program/firefox/default.nix | 4 +- overlay/Nvim.nix | 13 + package/darkreader/default.nix | 7 +- package/default.nix | 2 +- patch/darkreader/Policy.patch | 443 ++++++++++++++++++++++ patch/nvim/PressEnter.patch | 32 ++ 8 files changed, 493 insertions(+), 27 deletions(-) delete mode 100644 home/config/nvim/module/config/Notify.nix create mode 100644 overlay/Nvim.nix create mode 100644 patch/darkreader/Policy.patch create mode 100644 patch/nvim/PressEnter.patch diff --git a/home/config/nvim/default.nix b/home/config/nvim/default.nix index 9d643322..4cfe77e0 100644 --- a/home/config/nvim/default.nix +++ b/home/config/nvim/default.nix @@ -50,7 +50,6 @@ in { ./module/config/Search.nix ./module/config/Tab.nix ./module/config/Highlight.nix - ./module/config/Notify.nix ./module/plugin/Filetree.nix ./module/plugin/Gruvbox.nix ./module/plugin/Bufferline.nix diff --git a/home/config/nvim/module/config/Notify.nix b/home/config/nvim/module/config/Notify.nix deleted file mode 100644 index 5a387406..00000000 --- a/home/config/nvim/module/config/Notify.nix +++ /dev/null @@ -1,18 +0,0 @@ -{ ... }: { - text = '' - -- Disable error messages popup. - -- Instead print them and write to system journal. - bequiet = function(msg, log_level, opts) - print(string.sub(tostring(msg), 1, vim.v.echospace)) - - local log = io.popen("systemd-cat -t nvim", "w") - log:write(tostring(msg)) - log:close() - end - - vim.notify = bequiet - vim.api.nvim_out_write = bequiet - vim.api.nvim_err_write = bequiet - vim.api.nvim_err_writeln = bequiet - ''; -} diff --git a/home/program/firefox/default.nix b/home/program/firefox/default.nix index dff41cc3..dc7a5c51 100644 --- a/home/program/firefox/default.nix +++ b/home/program/firefox/default.nix @@ -4,7 +4,7 @@ pkgs, pkgsUnstable, ... -}: let +} @args: let bookmarks = [ (mkBookmark "Dashboard" "https://home.voronind.com") (mkBookmark "Watch" "https://watch.voronind.com") @@ -41,7 +41,7 @@ extensions = [ # TODO: Use this after https://github.com/darkreader/darkreader/pull/12920 gets merged. # (mkExtension "addon@darkreader.org" "https://addons.mozilla.org/firefox/downloads/latest/darkreader/latest.xpi") - (mkExtension "addon@darkreader.org" "file://${pkgs.callPackage { }}/latest.xpi") + (mkExtension "addon@darkreader.org" "file://${pkgs.callPackage args}/latest.xpi") (mkExtension "cliget@zaidabdulla.com" "https://addons.mozilla.org/firefox/downloads/latest/cliget/latest.xpi") (mkExtension "foxyproxy@eric.h.jung" "https://addons.mozilla.org/firefox/downloads/latest/foxyproxy-standard/latest.xpi") (mkExtension "uBlock0@raymondhill.net" "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi") diff --git a/overlay/Nvim.nix b/overlay/Nvim.nix new file mode 100644 index 00000000..3c7dfed5 --- /dev/null +++ b/overlay/Nvim.nix @@ -0,0 +1,13 @@ +{ + __findFile, + ... +}: { + # SEE: https://github.com/neovim/neovim/issues/22478 + nixpkgs.overlays = [(final: prev: { + neovim-unwrapped = prev.neovim-unwrapped.overrideAttrs (old: { + patches = (old.patches or [ ]) ++ [ + + ]; + }); + })]; +} diff --git a/package/darkreader/default.nix b/package/darkreader/default.nix index 073dc712..076cb089 100644 --- a/package/darkreader/default.nix +++ b/package/darkreader/default.nix @@ -1,7 +1,7 @@ { + __findFile, buildNpmPackage, fetchFromGitHub, - fetchpatch, ... }: buildNpmPackage rec { version = "4.9.96"; @@ -14,10 +14,7 @@ rev = "v${version}"; }; patches = [ - (fetchpatch { - url = "https://github.com/darkreader/darkreader/compare/v${version}...voronind-com:darkreader:main.diff"; - hash = "sha256-OqS6aY7PHHZvj7a0x1RI+1IpZxYXsqSia2ZeVM3XRZk="; - }) + ]; installPhase = '' mkdir -p $out diff --git a/package/default.nix b/package/default.nix index 0adb9540..fab4855f 100644 --- a/package/default.nix +++ b/package/default.nix @@ -143,7 +143,7 @@ anilibria-winmaclinux # Anime! appimage-run # Tool to run .AppImage files in NixOS. blanket # Sounds generator. - calibre # Book library manager. + # calibre # Book library manager. cbonsai # Draw trees. cmatrix # CLI Screensavers. cowsay # Cow quotes. diff --git a/patch/darkreader/Policy.patch b/patch/darkreader/Policy.patch new file mode 100644 index 00000000..10929459 --- /dev/null +++ b/patch/darkreader/Policy.patch @@ -0,0 +1,443 @@ +diff --git a/src/background/user-storage.ts b/src/background/user-storage.ts +index b582fb52e45f..344d21c2988f 100644 +--- a/src/background/user-storage.ts ++++ b/src/background/user-storage.ts +@@ -2,7 +2,7 @@ import {DEFAULT_SETTINGS, DEFAULT_THEME} from '../defaults'; + import {debounce} from '../utils/debounce'; + import {isURLMatched} from '../utils/url'; + import type {UserSettings} from '../definitions'; +-import {readSyncStorage, readLocalStorage, writeSyncStorage, writeLocalStorage, removeSyncStorage, removeLocalStorage} from './utils/extension-api'; ++import {readManagedStorage, readSyncStorage, readLocalStorage, writeSyncStorage, writeLocalStorage, removeSyncStorage, removeLocalStorage} from './utils/extension-api'; + import {logWarn} from './utils/log'; + import {PromiseBarrier} from '../utils/promise-barrier'; + import {validateSettings} from '../utils/validation'; +@@ -82,7 +82,11 @@ export default class UserStorage { + } + UserStorage.loadBarrier = new PromiseBarrier(); + +- let local = await readLocalStorage(DEFAULT_SETTINGS); ++ const managed = await readManagedStorage(DEFAULT_SETTINGS); ++ const {errors: managedCfgErrors} = validateSettings(managed); ++ managedCfgErrors.forEach((err) => logWarn(err)); ++ ++ let local = await readLocalStorage(managed); + + if (local.schemeVersion < 2) { + const sync = await readSyncStorage({schemeVersion: 0}); +@@ -102,7 +106,7 @@ export default class UserStorage { + await writeSyncStorage({schemeVersion: 2, ...syncTransformed}); + await removeSyncStorage(Object.keys(deprecatedDefaults)); + +- local = await readLocalStorage(DEFAULT_SETTINGS); ++ local = await readLocalStorage(managed); + } + } + +@@ -115,17 +119,17 @@ export default class UserStorage { + UserStorage.migrateAutomationSettings(local); + UserStorage.fillDefaults(local); + UserStorage.loadBarrier.resolve(local); +- return local; ++ return managed; + } + +- const $sync = await readSyncStorage(DEFAULT_SETTINGS); ++ const $sync = await readSyncStorage(managed); + if (!$sync) { + logWarn('Sync settings are missing'); + local.syncSettings = false; + UserStorage.set({syncSettings: false}); + UserStorage.saveSyncSetting(false); + UserStorage.loadBarrier.resolve(local); +- return local; ++ return managed; + } + + const {errors: syncCfgErrors} = validateSettings($sync); +@@ -135,7 +139,7 @@ export default class UserStorage { + UserStorage.fillDefaults($sync); + + UserStorage.loadBarrier.resolve($sync); +- return $sync; ++ return managed; + } + + static async saveSettings(): Promise { +@@ -227,4 +231,4 @@ export default class UserStorage { + + UserStorage.settings = updatedSettings; + } +-} ++} +\ No newline at end of file +diff --git a/src/background/utils/extension-api.ts b/src/background/utils/extension-api.ts +index ee54807b1f31..70a3cf24a39c 100644 +--- a/src/background/utils/extension-api.ts ++++ b/src/background/utils/extension-api.ts +@@ -97,6 +97,19 @@ export async function readLocalStorage(defaults: + }); + } + ++export async function readManagedStorage(defaults: T): Promise { ++ return new Promise((resolve) => { ++ chrome.storage.managed.get(defaults, (managed: T) => { ++ if (chrome.runtime.lastError) { ++ console.error(chrome.runtime.lastError.message); ++ resolve(defaults); ++ return; ++ } ++ resolve(managed); ++ }); ++ }); ++} ++ + function prepareSyncStorage(values: T): {[key: string]: any} { + for (const key in values) { + const value = values[key]; +diff --git a/src/managed-storage.json b/src/managed-storage.json +new file mode 100644 +index 000000000000..55065e4ff842 +--- /dev/null ++++ b/src/managed-storage.json +@@ -0,0 +1,298 @@ ++{ ++ ++ "$schema": "http://json-schema.org/draft-07/schema#", ++ "type": "object", ++ "properties": { ++ "schemeVersion": { ++ "type": "integer" ++ }, ++ "enabled": { ++ "type": "boolean" ++ }, ++ "fetchNews": { ++ "type": "boolean" ++ }, ++ "theme": { ++ "$ref": "Theme" ++ }, ++ "presets": { ++ "type": "array", ++ "items": { ++ "$ref": "ThemePreset" ++ } ++ }, ++ "customThemes": { ++ "type": "array", ++ "items": { ++ "$ref": "CustomSiteConfig" ++ } ++ }, ++ "enabledByDefault": { ++ "type": "boolean" ++ }, ++ "enabledFor": { ++ "type": "array", ++ "items": { ++ "type": "string", ++ "minLength": 1 ++ } ++ }, ++ "disabledFor": { ++ "type": "array", ++ "items": { ++ "type": "string", ++ "minLength": 1 ++ } ++ }, ++ "changeBrowserTheme": { ++ "type": "boolean" ++ }, ++ "syncSettings": { ++ "type": "boolean" ++ }, ++ "syncSitesFixes": { ++ "type": "boolean" ++ }, ++ "automation": { ++ "$ref": "Automation" ++ }, ++ "time": { ++ "$ref": "TimeSettings" ++ }, ++ "location": { ++ "$ref": "LocationSettings" ++ }, ++ "previewNewDesign": { ++ "type": "boolean" ++ }, ++ "enableForPDF": { ++ "type": "boolean" ++ }, ++ "enableForProtectedPages": { ++ "type": "boolean" ++ }, ++ "enableContextMenus": { ++ "type": "boolean" ++ }, ++ "detectDarkTheme": { ++ "type": "boolean" ++ }, ++ // Chrome's JSON schema format is weird and doesn't support `definitions` property and thus `#/definitions` references ++ // https://datatracker.ietf.org/doc/html/draft-zyp-json-schema-03 ++ // This "property" mimics it ++ "definitions": { ++ "type": "object", ++ "properties": { ++ "Theme": { ++ "id": "Theme", ++ "type": "object", ++ "properties": { ++ "mode": { ++ "$ref": "FilterMode" ++ }, ++ "brightness": { ++ "type": "integer", ++ "minimum": 0, ++ "maximum": 200 ++ }, ++ "contrast": { ++ "type": "integer", ++ "minimum": 0, ++ "maximum": 200 ++ }, ++ "grayscale": { ++ "type": "integer", ++ "minimum": 0, ++ "maximum": 100 ++ }, ++ "sepia": { ++ "type": "integer", ++ "minimum": 0, ++ "maximum": 100 ++ }, ++ "useFont": { ++ "type": "boolean" ++ }, ++ "fontFamily": { ++ "type": "string", ++ "minLength": 1 ++ }, ++ "textStroke": { ++ "type": "number" ++ }, ++ "engine": { ++ "type": "string", ++ "enum": [ ++ "cssFilter", ++ "svgFilter", ++ "staticTheme", ++ "dynamicTheme" ++ ] ++ }, ++ "stylesheet": { ++ "type": "string" ++ }, ++ "darkSchemeBackgroundColor": { ++ "$ref": "HexColor" ++ }, ++ "darkSchemeTextColor": { ++ "$ref": "HexColor" ++ }, ++ "lightSchemeBackgroundColor": { ++ "$ref": "HexColor" ++ }, ++ "lightSchemeTextColor": { ++ "$ref": "HexColor" ++ }, ++ "scrollbarColor": { ++ "$ref": "HexColorOrAuto" ++ }, ++ "selectionColor": { ++ "$ref": "HexColorOrAuto" ++ }, ++ "styleSystemControls": { ++ "type": "boolean" ++ }, ++ "lightColorScheme": { ++ "type": "string", ++ "minLength": 1 ++ }, ++ "darkColorScheme": { ++ "type": "string", ++ "minLength": 1 ++ }, ++ "immediateModify": { ++ "type": "boolean" ++ } ++ } ++ }, ++ "HexColor": { ++ "id": "HexColor", ++ "type": "string", ++ "pattern": "^[0-9a-f]{6}$" ++ }, ++ "HexColorOrAuto": { ++ "id": "HexColorOrAuto", ++ "type": "string", ++ "pattern": "^([0-9a-f]{6}|auto)$" ++ }, ++ "FilterMode": { ++ "id": "FilterMode", ++ "type": "integer", ++ "enum": [ ++ 0, ++ 1 ++ ] ++ }, ++ "ThemePreset": { ++ "id": "ThemePreset", ++ "type": "object", ++ "properties": { ++ "id": { ++ "type": "string", ++ "minLength": 1 ++ }, ++ "name": { ++ "type": "string", ++ "minLength": 1 ++ }, ++ "urls": { ++ "type": "array", ++ "items": { ++ "type": "string", ++ "minLength": 1 ++ } ++ }, ++ "theme": { ++ "$ref": "Theme" ++ } ++ }, ++ "required": [ ++ "id", ++ "name", ++ "urls", ++ "theme" ++ ] ++ }, ++ "CustomSiteConfig": { ++ "id": "CustomSiteConfig", ++ "type": "object", ++ "properties": { ++ "url": { ++ "type": "array", ++ "items": { ++ "type": "string", ++ "minLength": 1 ++ } ++ }, ++ "theme": { ++ "$ref": "Theme" ++ } ++ }, ++ "required": [ ++ "url", ++ "theme" ++ ] ++ }, ++ "Automation": { ++ "id": "Automation", ++ "type": "object", ++ "properties": { ++ "enabled": { ++ "type": "boolean" ++ }, ++ "mode": { ++ "$ref": "AutomationMode" ++ }, ++ "behavior": { ++ "type": "string", ++ "enum": [ ++ "OnOff", ++ "Scheme" ++ ] ++ } ++ } ++ }, ++ "AutomationMode": { ++ "id": "AutomationMode", ++ "type": "string", ++ "enum": [ ++ "", ++ "time", ++ "system", ++ "location" ++ ] ++ }, ++ "TimeSettings": { ++ "id": "TimeSettings", ++ "type": "object", ++ "properties": { ++ "activation": { ++ "$ref": "Time" ++ }, ++ "deactivation": { ++ "$ref": "Time" ++ } ++ } ++ }, ++ "Time": { ++ "id": "Time", ++ "type": "string", ++ "pattern": "^((0?[0-9])|(1[0-9])|(2[0-3])):([0-5][0-9])$" ++ }, ++ "LocationSettings": { ++ "id": "LocationSettings", ++ "type": "object", ++ "properties": { ++ "latitude": { ++ "type": "number" ++ }, ++ "longitude": { ++ "type": "number" ++ } ++ } ++ } ++ } ++ } ++ } ++} +diff --git a/tasks/bundle-manifest.js b/tasks/bundle-manifest.js +index ae29531e67b7..f4058a129f52 100644 +--- a/tasks/bundle-manifest.js ++++ b/tasks/bundle-manifest.js +@@ -4,6 +4,7 @@ import {PLATFORM} from './platform.js'; + import * as reload from './reload.js'; + import {createTask} from './task.js'; + import {readJSON, writeJSON} from './utils.js'; ++import {copyFile} from 'node:fs/promises'; + + async function patchManifest(platform, debug, watch, test) { + const manifest = await readJSON(absolutePath('src/manifest.json')); +@@ -16,6 +17,11 @@ async function patchManifest(platform, debug, watch, test) { + if (platform === PLATFORM.CHROMIUM_MV3) { + patched.browser_action = undefined; + } ++ if (platform === PLATFORM.CHROMIUM_MV2 || platform === PLATFORM.CHROMIUM_MV3) { ++ patched.storage = { ++ managed_schema: 'managed-storage.json', ++ }; ++ } + if (debug) { + patched.version = '1'; + patched.description = `Debug build, platform: ${platform}, watch: ${watch ? 'yes' : 'no'}.`; +@@ -42,6 +48,9 @@ async function manifests({platforms, debug, watch, test}) { + const manifest = await patchManifest(platform, debug, watch, test); + const destDir = getDestDir({debug, platform}); + await writeJSON(`${destDir}/manifest.json`, manifest); ++ if (platform === PLATFORM.CHROMIUM_MV2 || platform === PLATFORM.CHROMIUM_MV3) { ++ await copyFile(absolutePath('src/managed-storage.json'), `${destDir}/managed-storage.json`); ++ } + } + } + +@@ -49,7 +58,7 @@ const bundleManifestTask = createTask( + 'bundle-manifest', + manifests, + ).addWatcher( +- ['src/manifest*.json'], ++ ['src/manifest*.json', 'src/managed-storage.json'], + async (changedFiles, _, buildPlatforms) => { + const chrome = changedFiles.some((file) => file.endsWith('manifest.json')); + const platforms = {}; diff --git a/patch/nvim/PressEnter.patch b/patch/nvim/PressEnter.patch new file mode 100644 index 00000000..321ed00e --- /dev/null +++ b/patch/nvim/PressEnter.patch @@ -0,0 +1,32 @@ +diff --git a/src/nvim/message.c b/src/nvim/message.c +index 10b90bde..628b9db8 100644 +--- a/src/nvim/message.c ++++ b/src/nvim/message.c +@@ -373,6 +373,7 @@ bool msg_attr_keep(const char *s, int attr, bool keep, bool multiline) + /// @param force always truncate + char *msg_strtrunc(const char *s, int force) + { ++ force = true; + char *buf = NULL; + + // May truncate message to avoid a hit-return prompt +@@ -1137,6 +1138,7 @@ void msg_end_prompt(void) + /// if -1, don't redraw at all + void wait_return(int redraw) + { ++ return; + int c; + int had_got_int; + FILE *save_scriptout; +diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c +index 16118028..2e291b6f 100644 +--- a/src/nvim/os/time.c ++++ b/src/nvim/os/time.c +@@ -56,6 +56,7 @@ uint64_t os_now(void) + /// @param ignoreinput If true, only SIGINT (CTRL-C) can interrupt. + void os_delay(uint64_t ms, bool ignoreinput) + { ++ return; + DLOG("%" PRIu64 " ms", ms); + if (ms > INT_MAX) { + ms = INT_MAX;