Merge branch 'develop'
This commit is contained in:
47
.github/workflows/build.yml
vendored
47
.github/workflows/build.yml
vendored
@@ -100,27 +100,6 @@ jobs:
|
||||
name: gotify-tray.dmg
|
||||
path: gotify-tray.dmg
|
||||
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build-win64, build-ubuntu, build-debian, build-macos]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/download-artifact@master
|
||||
- name: Release
|
||||
uses: marvinpinto/action-automatic-releases@latest
|
||||
with:
|
||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
prerelease: false
|
||||
files: |
|
||||
gotify-tray-installer-win.exe
|
||||
gotify-tray_amd64_ubuntu_focal.deb
|
||||
gotify-tray_amd64_ubuntu_hirsute.deb
|
||||
gotify-tray_amd64_ubuntu_impish.deb
|
||||
gotify-tray_amd64_ubuntu_jammy.deb
|
||||
gotify-tray_amd64_debian_bullseye.deb
|
||||
gotify-tray_amd64_debian_bookworm.deb
|
||||
gotify-tray.dmg
|
||||
|
||||
pypi:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@@ -141,3 +120,29 @@ jobs:
|
||||
uses: pypa/gh-action-pypi-publish@release/v1
|
||||
with:
|
||||
password: ${{ secrets.PYPI_API_TOKEN }}
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
path: dist/gotify_tray-*.whl
|
||||
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [build-win64, build-ubuntu, build-debian, build-macos, pypi]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/download-artifact@master
|
||||
- name: Release
|
||||
uses: marvinpinto/action-automatic-releases@latest
|
||||
with:
|
||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
prerelease: false
|
||||
files: |
|
||||
gotify-tray-installer-win.exe
|
||||
gotify-tray_amd64_ubuntu_focal.deb
|
||||
gotify-tray_amd64_ubuntu_hirsute.deb
|
||||
gotify-tray_amd64_ubuntu_impish.deb
|
||||
gotify-tray_amd64_ubuntu_jammy.deb
|
||||
gotify-tray_amd64_debian_bullseye.deb
|
||||
gotify-tray_amd64_debian_bookworm.deb
|
||||
gotify-tray.dmg
|
||||
gotify_tray-*.whl
|
||||
|
||||
4
.github/workflows/develop.yml
vendored
4
.github/workflows/develop.yml
vendored
@@ -4,7 +4,6 @@ on:
|
||||
push:
|
||||
branches-ignore:
|
||||
- master
|
||||
- "dependabot/**"
|
||||
tags-ignore:
|
||||
- '*'
|
||||
|
||||
@@ -37,6 +36,7 @@ jobs:
|
||||
path: gotify-tray-installer-win.exe
|
||||
|
||||
build-ubuntu:
|
||||
if: ${{ github.actor != 'dependabot[bot]' }}
|
||||
strategy:
|
||||
matrix:
|
||||
tag: [focal]
|
||||
@@ -60,6 +60,7 @@ jobs:
|
||||
path: gotify-tray_amd64_ubuntu_${{ matrix.tag }}.deb
|
||||
|
||||
build-macos:
|
||||
if: ${{ github.actor != 'dependabot[bot]' }}
|
||||
runs-on: macos-12
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
@@ -99,5 +100,4 @@ jobs:
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: gotify_tray.whl
|
||||
path: dist/gotify_tray-*.whl
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import glob
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
import uuid
|
||||
|
||||
import requests
|
||||
|
||||
@@ -35,40 +35,34 @@ class Cache(object):
|
||||
def clear(self):
|
||||
self.cursor.execute("DELETE FROM cache")
|
||||
self.database.commit()
|
||||
|
||||
if not self.cache_dir:
|
||||
logger.error("Cache directory is empty.")
|
||||
return
|
||||
|
||||
for filename in glob.glob(self.cache_dir + "/*"):
|
||||
os.remove(filename)
|
||||
|
||||
def lookup(self, key: str) -> str:
|
||||
q = self.cursor.execute(
|
||||
"SELECT filename, cached_on FROM cache WHERE url=?", (key,)
|
||||
).fetchone()
|
||||
if q:
|
||||
if q := self.cursor.execute(
|
||||
"SELECT filename FROM cache WHERE url=?", (key,)
|
||||
).fetchone():
|
||||
# Cache hit
|
||||
filename, cached_on = q
|
||||
return filename if os.path.exists(filename) else ""
|
||||
return q["filename"] if os.path.exists(q["filename"]) else ""
|
||||
else:
|
||||
# Cache miss
|
||||
return ""
|
||||
|
||||
def store(
|
||||
self, key: str, response: requests.Response, add_time: bool = True
|
||||
) -> str:
|
||||
def store(self, key: str, response: requests.Response) -> str:
|
||||
# Create a file and store the response contents
|
||||
filename = str(time.time()).replace(".", "") if add_time else ""
|
||||
if "Content-Disposition" in response.headers.keys():
|
||||
filename += response.headers["Content-Disposition"]
|
||||
else:
|
||||
filename += response.url.split("/")[-1]
|
||||
filepath = os.path.join(self.cache_dir, uuid.uuid4().hex)
|
||||
|
||||
filename = "".join([c for c in filename if c.isalpha() or c.isdigit()]).rstrip()
|
||||
filename = os.path.join(self.cache_dir, filename)
|
||||
|
||||
with open(filename, "wb") as f:
|
||||
with open(filepath, "wb") as f:
|
||||
f.write(response.content)
|
||||
|
||||
self.cursor.execute(
|
||||
"INSERT INTO cache (url, filename, cached_on) VALUES(?, ?, datetime('now', 'localtime'))",
|
||||
(key, filename),
|
||||
(key, filepath),
|
||||
)
|
||||
self.database.commit()
|
||||
return filename
|
||||
return filepath
|
||||
|
||||
@@ -22,43 +22,12 @@ class Downloader(object):
|
||||
"""
|
||||
return self.session.get(url)
|
||||
|
||||
def get_bytes(self, url: str, cached: bool = True, add_time: bool = True) -> bytes:
|
||||
"""
|
||||
Get the content of an http get request, as bytes.
|
||||
Optionally use the cache.
|
||||
"""
|
||||
if cached:
|
||||
# Retrieve from cache
|
||||
filename = self.cache.lookup(url)
|
||||
if filename:
|
||||
with open(filename, "rb") as f:
|
||||
return f.read()
|
||||
|
||||
try:
|
||||
response = self.get(url)
|
||||
except Exception as e:
|
||||
logger.error(f"get_bytes: downloading {url} failed.: {e}")
|
||||
return b""
|
||||
|
||||
if not response.ok:
|
||||
return b""
|
||||
|
||||
if cached:
|
||||
# Store in cache
|
||||
self.cache.store(url, response, add_time=add_time)
|
||||
|
||||
return response.content
|
||||
|
||||
def get_filename(
|
||||
self, url: str, retrieve_from_cache: bool = True, add_time: bool = True
|
||||
) -> str:
|
||||
def get_filename(self, url: str) -> str:
|
||||
"""
|
||||
Get the content of an http get request, as a filename.
|
||||
"""
|
||||
if retrieve_from_cache:
|
||||
filename = self.cache.lookup(url)
|
||||
if filename:
|
||||
return filename
|
||||
if filename := self.cache.lookup(url):
|
||||
return filename
|
||||
|
||||
try:
|
||||
response = self.get(url)
|
||||
@@ -66,7 +35,4 @@ class Downloader(object):
|
||||
logger.error(f"get_filename: downloading {url} failed.: {e}")
|
||||
return ""
|
||||
|
||||
if not response.ok:
|
||||
return ""
|
||||
|
||||
return self.cache.store(url, response, add_time=add_time)
|
||||
return self.cache.store(url, response) if response.ok else ""
|
||||
|
||||
@@ -7,7 +7,7 @@ from typing import List, Union
|
||||
|
||||
from gotify_tray import gotify
|
||||
from gotify_tray.__version__ import __title__
|
||||
from gotify_tray.database import Downloader, Settings
|
||||
from gotify_tray.database import Cache, Downloader, Settings
|
||||
from gotify_tray.tasks import (
|
||||
DeleteApplicationMessagesTask,
|
||||
DeleteAllMessagesTask,
|
||||
@@ -308,6 +308,11 @@ class MainApplication(QtWidgets.QApplication):
|
||||
|
||||
self.messages_model.clear()
|
||||
|
||||
def refresh_callback(self):
|
||||
# Manual refresh -> also reset the image cache
|
||||
Cache().clear()
|
||||
self.refresh_applications()
|
||||
|
||||
def settings_callback(self):
|
||||
settings_dialog = SettingsDialog()
|
||||
settings_dialog.quit_requested.connect(self.quit)
|
||||
@@ -343,7 +348,7 @@ class MainApplication(QtWidgets.QApplication):
|
||||
self.tray.messageClicked.connect(self.main_window.bring_to_front)
|
||||
self.tray.activated.connect(self.tray_activated_callback)
|
||||
|
||||
self.main_window.refresh.connect(self.refresh_applications)
|
||||
self.main_window.refresh.connect(self.refresh_callback)
|
||||
self.main_window.delete_all.connect(self.delete_all_messages_callback)
|
||||
self.main_window.application_selection_changed.connect(
|
||||
self.application_selection_changed_callback
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
requests==2.27.1
|
||||
websocket-client==1.3.2
|
||||
pyqt6==6.3.0
|
||||
requests==2.28.1
|
||||
websocket-client==1.3.3
|
||||
pyqt6==6.3.1
|
||||
python-dateutil==2.8.2
|
||||
|
||||
Reference in New Issue
Block a user