From 48146f8351d47065908164be992bbc436b9dad74 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 2 May 2025 14:33:33 -0400 Subject: [PATCH] [mv3] Address various issues for Safari build --- Makefile | 11 +- platform/mv3/extension/css/filtering-mode.css | 5 +- platform/mv3/extension/css/popup.css | 10 +- platform/mv3/extension/popup.html | 19 ++-- platform/mv3/safari/manifest.json | 3 +- platform/mv3/safari/patch-extension.js | 107 ++++++++++++++++++ 6 files changed, 139 insertions(+), 16 deletions(-) create mode 100644 platform/mv3/safari/patch-extension.js diff --git a/Makefile b/Makefile index 477a3b3f7..5aac4a6e8 100644 --- a/Makefile +++ b/Makefile @@ -5,10 +5,11 @@ run_options := $(filter-out $@,$(MAKECMDGOALS)) mv3-chromium mv3-firefox mv3-edge mv3-safari \ compare maxcost medcost mincost modifiers record wasm -sources := $(wildcard assets/* assets/*/* dist/version src/* src/*/* src/*/*/* src/*/*/*/*) -platform := $(wildcard platform/* platform/*/* platform/*/*/* platform/*/*/*/* platform/*/*/*/*/*) +sources := ./dist/version $(shell find ./assets -type f) $(shell find ./src -type f) +platform := $(wildcard platform/**/*) assets := dist/build/uAssets -mv3-data := $(wildcard dist/build/mv3-data/*) +mv3-data := $(shell find ./dist/build/mv3-data -type f) +mv3-safari-deps := $(shell find ./platform/mv3/extension -type f) $(wildcard platform/mv3/safari/*) all: chromium firefox npm @@ -80,8 +81,10 @@ dist/build/uBOLite.edge: tools/make-mv3.sh tools/make-edge.mjs $(sources) $(plat mv3-edge: dist/build/uBOLite.edge -dist/build/uBOLite.safari: tools/make-mv3.sh $(sources) $(platform) $(mv3-data) dist/build/mv3-data +dist/build/uBOLite.safari: tools/make-mv3.sh $(sources) $(mv3-safari-deps) $(mv3-data) dist/build/mv3-data tools/make-mv3.sh safari + node platform/mv3/safari/patch-extension.js \ + packageDir=./dist/build/uBOLite.safari mv3-safari: dist/build/uBOLite.safari diff --git a/platform/mv3/extension/css/filtering-mode.css b/platform/mv3/extension/css/filtering-mode.css index f6ed77831..c7d37c03b 100644 --- a/platform/mv3/extension/css/filtering-mode.css +++ b/platform/mv3/extension/css/filtering-mode.css @@ -1,5 +1,6 @@ .filteringModeSlider { align-items: center; + container-type: size; display: flex; height: 60px; justify-content: center; @@ -11,9 +12,9 @@ background-color: var(--surface-1); box-sizing: border-box; border-radius: 30% 15% / 15% 30%; - height: 100%; + height: calc(25cqw + 2px); position: absolute; - width: calc(25% + 2px); + width: calc(25cqw + 2px); z-index: 10; } diff --git a/platform/mv3/extension/css/popup.css b/platform/mv3/extension/css/popup.css index 6ccc8f814..19bef6ac1 100644 --- a/platform/mv3/extension/css/popup.css +++ b/platform/mv3/extension/css/popup.css @@ -70,9 +70,14 @@ body[data-forbid~="dashboard"] #gotoDashboard { display: none; } +.lrspacer { + padding-left: var(--default-gap-small); + padding-right: var(--default-gap-small); + } + #filteringModeText { color: var(--ink-3); - margin: var(--default-gap-small); + margin-bottom: var(--default-gap-small); margin-top: 0; text-align: center; text-transform: lowercase; @@ -95,7 +100,8 @@ body[data-forbid~="dashboard"] #gotoDashboard { .filteringModeSlider { align-self: center; - margin: var(--popup-gap); + margin-bottom: var(--popup-gap); + margin-top: var(--popup-gap); width: calc(var(--popup-main-min-width) - 1em); } diff --git a/platform/mv3/extension/popup.html b/platform/mv3/extension/popup.html index bd1c00d91..1c4ed595a 100644 --- a/platform/mv3/extension/popup.html +++ b/platform/mv3/extension/popup.html @@ -17,15 +17,20 @@
­
-
-
- - - - +
+
+
+ + + + +
+
+ +
+

_
-

_
bolt list-altShow matched rules diff --git a/platform/mv3/safari/manifest.json b/platform/mv3/safari/manifest.json index a24dfb885..d4c8725f8 100644 --- a/platform/mv3/safari/manifest.json +++ b/platform/mv3/safari/manifest.json @@ -6,7 +6,8 @@ "author": "Raymond Hill", "background": { "scripts": [ "/js/background.js" ], - "type": "module" + "type": "module", + "persistent": false }, "commands": { "enter-zapper-mode": { diff --git a/platform/mv3/safari/patch-extension.js b/platform/mv3/safari/patch-extension.js new file mode 100644 index 000000000..6a285535c --- /dev/null +++ b/platform/mv3/safari/patch-extension.js @@ -0,0 +1,107 @@ +/******************************************************************************* + + uBlock Origin - a comprehensive, efficient content blocker + Copyright (C) 2025-present Raymond Hill + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see {http://www.gnu.org/licenses/}. + + Home: https://github.com/gorhill/uBlock +*/ + +import fs from 'fs/promises'; +import process from 'process'; + +/******************************************************************************/ + +const commandLineArgs = (( ) => { + const args = new Map(); + let name, value; + for ( const arg of process.argv.slice(2) ) { + const pos = arg.indexOf('='); + if ( pos === -1 ) { + name = arg; + value = ''; + } else { + name = arg.slice(0, pos); + value = arg.slice(pos+1); + } + args.set(name, value); + } + return args; +})(); + +/******************************************************************************/ + +// Apple store rejects when description (extShortDesc) is longer than 112 +// characters. + +async function fixLongDescription(path) { + let text = await fs.readFile(path, { encoding: 'utf8' }); + const messages = JSON.parse(text); + let message = messages.extShortDesc.message; + if ( message.length <= 112 ) { return; } + const pos = message.indexOf('.'); + if ( pos !== -1 ) { + message = message.slice(0, pos+1); + } + if ( message.length >= 112 ) { + message = `${message.slice(0, 111)}…`; + } + messages.extShortDesc.message = message; + text = JSON.stringify(messages, null, 2); + await fs.writeFile(path, text); +} + +async function fixLongDescriptions() { + const promises = []; + const packageDir = commandLineArgs.get('packageDir'); + const entries = await fs.readdir(`${packageDir}/_locales/`, { withFileTypes: true }); + for ( const entry of entries ) { + if ( entry.isDirectory() === false ) { continue; } + promises.push(fixLongDescription(`${packageDir}/_locales/${entry.name}/messages.json`)); + } + return Promise.all(promises); +} + +/******************************************************************************/ + +// Apple store rejects when version has four components. + +async function fixManifest() { + const packageDir = commandLineArgs.get('packageDir'); + const path = `${packageDir}/manifest.json`; + let text = await fs.readFile(path, { encoding: 'utf8' }); + const manifest = JSON.parse(text); + const match = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/.exec(manifest.version); + const month = parseInt(match[2], 10); + const dayofmonth = parseInt(match[3], 10); + const monthday /* sort of */ = month * 100 + dayofmonth; + manifest.version = `${match[1]}.${monthday}.${match[4]}`; + text = JSON.stringify(manifest, null, 2); + await fs.writeFile(path, text); +} + +/******************************************************************************/ + +async function main() { + await Promise.all([ + fixLongDescriptions(), + fixManifest(), + ]); + +} + +main(); + +/******************************************************************************/