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