diff --git a/searx/brand.py b/searx/brand.py index af1a8eec8..dcd1dd9ed 100644 --- a/searx/brand.py +++ b/searx/brand.py @@ -18,6 +18,17 @@ class BrandCustom(msgspec.Struct, kw_only=True, forbid_unknown_fields=True): """Custom entries in the footer of the WEB page: ``[title]: [link]``""" +class ThemeColors(msgspec.Struct, kw_only=True, forbid_unknown_fields=True): + """Custom settings for theme colors in the brand section.""" + + theme_color_light: str = "#3050ff" + background_color_light: str = "#fff" + theme_color_dark: str = "#58f" + background_color_dark: str = "#222428" + theme_color_black: str = "#3050ff" + background_color_black: str = "#000" + + class SettingsBrand(msgspec.Struct, kw_only=True, forbid_unknown_fields=True): """Options for configuring brand properties. @@ -53,3 +64,19 @@ class SettingsBrand(msgspec.Struct, kw_only=True, forbid_unknown_fields=True): .. autoclass:: searx.brand.BrandCustom :members: """ + + pwa_colors: ThemeColors = msgspec.field(default_factory=ThemeColors) + """Custom settings for PWA colors.""" + + # new_issue_url is a hackish solution tailored for only one hoster (GH). As + # long as we don't have a more general solution, we should support it in the + # given function, but it should not be expanded further. + + new_issue_url: str = "https://github.com/searxng/searxng/issues/new" + """If you host your own issue tracker not on GitHub, then unset this URL. + + Note: This URL will create a pre-filled GitHub bug report form for an + engine. Since this feature is implemented only for GH (and limited to + engines), it will probably be replaced by another solution in the near + future. + """ diff --git a/searx/settings.yml b/searx/settings.yml index 2cf2c29ed..1cf62987d 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -27,6 +27,15 @@ brand: # links: # Uptime: https://uptime.searxng.org/history/darmarit-org # About: "https://searxng.org" + # pwa_colors: + # # Custom settings for PWA icon an colors used in manifest.json + # # Default colors are: + # theme_color_light: "#3050ff" + # background_color_light: "fff" + # theme_color_dark: "#58f" + # background_color_dark: "#222428" + # theme_color_black: "#3050ff" + # background_color_black: "#000" search: # Filter results. 0: None, 1: Moderate, 2: Strict diff --git a/searx/templates/simple/base.html b/searx/templates/simple/base.html index b07168a34..7b2cd6a66 100644 --- a/searx/templates/simple/base.html +++ b/searx/templates/simple/base.html @@ -26,6 +26,7 @@ +
diff --git a/searx/templates/simple/manifest.json b/searx/templates/simple/manifest.json new file mode 100644 index 000000000..390e52022 --- /dev/null +++ b/searx/templates/simple/manifest.json @@ -0,0 +1,25 @@ +{ + "name": "{{ instance_name }}", + "short_name": "{{ instance_name }}", + "icons": [ + { + "src": "{{ url_for('static', filename='img/favicon.svg', _external=True) }}", + "sizes": "any", + "type": "image/svg+xml" + }, + { + "src": "{{ url_for('static', filename='img/192.png', _external=True) }}", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "{{ url_for('static', filename='img/512.png', _external=True) }}", + "sizes": "512x512", + "type": "image/png" + } + ], + "start_url": "{{ url_for('index') }}", + "theme_color": "{{ theme_color }}" , + "background_color": "{{ background_color }}", + "display": "standalone" +} \ No newline at end of file diff --git a/searx/webapp.py b/searx/webapp.py index ed2deeabb..b0820c753 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -1215,6 +1215,29 @@ def opensearch(): return resp +@app.route('/manifest.json', methods=['GET']) +def manifest(): + theme = sxng_request.preferences.get_value('simple_style') + if theme not in ("light", "dark", "black"): + theme = "light" + + theme_color = get_setting(f'brand.pwa_colors.theme_color_{theme}') + background_color = get_setting(f'brand.pwa_colors.background_color_{theme}') + ret = render('manifest.json', theme_color=theme_color, background_color=background_color) + resp = Response(response=ret, status=200, mimetype="application/json") + return resp + + +@app.route('/logo/') +def manifest_logo(resolution=0): + theme = sxng_request.preferences.get_value("theme") + return send_from_directory( + os.path.join(app.root_path, settings['ui']['static_path'], 'themes', theme, 'img', 'logos'), # type: ignore + resolution, + mimetype='image/vnd.microsoft.icon', + ) + + @app.route('/favicon.ico') def favicon(): theme = sxng_request.preferences.get_value("theme")