~hristoast/mousikofidi

0dc609f3b99a41b7a8b2fcf9bb36b32dbd181a37 — Hristos N. Triantafillou a month ago 7522c9f
Adding a webmanifest (#117)
3 files changed, 31 insertions(+), 0 deletions(-)

M mousikofidi/mousikofidi.py
M mousikofidi/templates/base.html
M test_mousikofidi.py
M mousikofidi/mousikofidi.py => mousikofidi/mousikofidi.py +16 -0
@@ 1359,6 1359,22 @@ def test_js():
    return render_template("test_js.html", **c)


@app.route("/manifest.webmanifest")
def webmanifest():
    c = request_context(app.fidiConfig)
    return jsonify(
        {
            "name": c["site_name"],
            "start_url": ".",
            "display": "standalone",
            "background_color": "#000" if c["theme"] == "dark" else "#fff",
            "description": "A MousikóFídi instance called: " + c["site_name"],
            # TODO: Don't hardcode the size or type
            "icons": [{"src": c["logo_path"], "sizes": "416x416", "type": "image/png"}],
        }
    )


# API routes
@app.route("/api/v1/metadata/<path:path>")
def metadata_for_path(path):

M mousikofidi/templates/base.html => mousikofidi/templates/base.html +1 -0
@@ 6,6 6,7 @@
    <meta name="description" content="{{ meta_desc }}">
    <meta name="author" content="{{ meta_author }}">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="manifest" href="/manifest.webmanifest">

    {% for c in css %}
      <link href="{{ c }}" rel="stylesheet" type="text/css">

M test_mousikofidi.py => test_mousikofidi.py +14 -0
@@ 13,6 13,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
import json
import os
import pytest
import shutil


@@ 3684,3 3685,16 @@ def test_settings_edit(client):
    with app.app_context():
        client.post(url, data={"icons": "disabled"})
    assert session["icons"] is False


def test_webmanifest(client):
    url = "/manifest.webmanifest"

    with app.app_context():
        rv = client.get(url)
        d = json.loads(rv.data.decode())

    assert rv.status == "200 OK"
    assert d["background_color"] == "#000"
    assert d["icons"][0]["src"] == "/fidi.png"
    assert d["name"] == "MousikóFídi - Your Music Cloud"