From 9ada9ef2cfd2bb7468ac79a21e4adbfa16b63f80 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Sat, 24 Sep 2022 06:57:21 -0400 Subject: [PATCH] add appimage stuff --- .gitignore | 2 + appimage-main.py | 10 ++ appimage-requirements.txt | 6 ++ appimage.yaml | 121 +++++++++++++++++++++++++ apt-requirements.txt | 3 + barkshark_web/cli.py | 56 ++++++++++++ barkshark_web/component/application.py | 12 ++- barkshark_web/component/window.py | 2 + barkshark_web/database/base.py | 4 +- barkshark_web/dbus.py | 4 + barkshark_web/functions.py | 66 ++++++++++++++ barkshark_web/themes.py | 3 - pyvenv.json | 12 ++- requirements.txt | 2 +- setup.cfg | 4 +- 15 files changed, 297 insertions(+), 10 deletions(-) create mode 100644 appimage-main.py create mode 100644 appimage-requirements.txt create mode 100644 appimage.yaml diff --git a/.gitignore b/.gitignore index f05aae2..e6871b9 100644 --- a/.gitignore +++ b/.gitignore @@ -126,3 +126,5 @@ test*.py # glade backup files *.ui~ +# appimage build +/AppDir diff --git a/appimage-main.py b/appimage-main.py new file mode 100644 index 0000000..e0e7cea --- /dev/null +++ b/appimage-main.py @@ -0,0 +1,10 @@ +import os +import sys + +appdir = os.environ['APPDIR'] +sys.path.insert(0, f'{appdir}/usr/src') + + +from barkshark_web.cli import main + +main() diff --git a/appimage-requirements.txt b/appimage-requirements.txt new file mode 100644 index 0000000..9e6b21e --- /dev/null +++ b/appimage-requirements.txt @@ -0,0 +1,6 @@ +configobj@git+https://github.com/DiffSK/configobj +izzylib-http-async@git+https://git.barkshark.xyz/izaliamae/izzylib-http-async +izzylib-sql@git+https://git.barkshark.xyz/izaliamae/izzylib-sql +objgraph==3.5.0 +pillow==8.3.2 +pysftp==0.2.9 diff --git a/appimage.yaml b/appimage.yaml new file mode 100644 index 0000000..f2c747a --- /dev/null +++ b/appimage.yaml @@ -0,0 +1,121 @@ +version: 1 +script: + #- rm -rf AppDir | true + - mkdir -p AppDir/usr/src + - mkdir -p AppDir/usr/share/icons/hicolor/128x128/apps + - cp -R barkshark_web AppDir/usr/src/ + - cp appimage-requirements.txt AppDir/usr/src/requirements.txt + - cp appimage-main.py AppDir/usr/src/main.py + - cp barkshark_web/resources/icon-128.png AppDir/usr/share/icons/hicolor/128x128/apps/barkshark-web.png + + +AppDir: + path: ./AppDir + + app_info: + id: xyz.barkshark.Web + name: barkshark-web + icon: barkshark-web + version: 0.4.0 + exec: usr/bin/python3 + exec_args: "${APPDIR}/usr/src/main.py $@" + + after_bundle: + - AppDir/usr/bin/python3 -m pip install --ignore-installed --prefix=/usr --root=AppDir -r appimage-requirements.txt + apt: + arch: amd64 + allow_unauthenticated: true + sources: + - sourceline: 'deb [arch=amd64] https://deb.debian.org/debian bookworm main' + #key_url: 'https://deb.debian.org/debian/pool/main/d/debian-archive-keyring/debian-archive-keyring_2021.1.1.dsc' + - sourceline: 'deb [arch=amd64] https://deb.debian.org/debian bookworm-updates main' + #key_url: 'https://deb.debian.org/debian/pool/main/d/debian-archive-keyring/debian-archive-keyring_2021.1.1.dsc' + - sourceline: 'deb [arch=amd64] https://security.debian.org/debian-security bookworm-security main' + #key_url: 'https://security.debian.org/debian-security/pool/main/d/debian-archive-keyring/debian-archive-keyring_2017.5+deb9u2.dsc' + + include: + - appmenu-gtk3-module + - gir1.2-glib-2.0 + - gir1.2-gst-plugins-bad-1.0 + - gir1.2-gst-plugins-base-1.0 + - gir1.2-gtk-3.0 + - gir1.2-webkit2-4.0 + - gir1.2-notify-0.7 + - git + - gstreamer1.0-plugins-bad + - gstreamer1.0-plugins-base + - gstreamer1.0-plugins-good + - gstreamer1.0-plugins-ugly + - libcairo-gobject2 + - librsvg2-common + - openssl + - python3 + - python3-bs4 + - python3-click + - python3-dasbus + - python3-dnspython + - python3-gi + - python3-gi-cairo + - python3-lxml + - python3-mastodon + - python3-pip + - python3-pkg-resources + - python3-psutil + - python3-secretstorage + - python3-watchdog + - python3-wheel + - xapp + + exclude: + - emacsen-common + - fdisk + - libapparmor1 + - libasound2 + - libasound2-data + - libmount + - libsystemd0 + - libudev1 + - mount + - systemd + - systemd-sysv + + files: + exclude: + - usr/share/man + - usr/share/doc + #- usr/share/doc/*/README.* + #- usr/share/doc/*/changelog.* + #- usr/share/doc/*/NEWS.* + #- usr/share/doc/*/TODO.* + + runtime: + env: + PYTHONHOME: '${APPDIR}/usr' + PYTHONPATH: '${APPDIR}/usr/lib/python3.10/site-packages' + + test: + fedora: + image: appimagecrafters/tests-env:fedora-30 + command: ./AppRun + use_host_x: true + debian: + image: appimagecrafters/tests-env:debian-stable + command: ./AppRun + use_host_x: true + arch: + image: appimagecrafters/tests-env:archlinux-latest + command: ./AppRun + use_host_x: true + centos: + image: appimagecrafters/tests-env:centos-7 + command: ./AppRun + use_host_x: true + ubuntu: + image: appimagecrafters/tests-env:ubuntu-xenial + command: ./AppRun + use_host_x: true + +AppImage: + update-information: 'zsync|https://static.barkshark.xyz/appimage-updates/{{APP_NAME}}-{{APP_VERSION}}-{{ARCH}}.AppImage.zsync' + sign-key: A12ACFEC461B90EAA89A43FD7519E7A4AD70227D + arch: x86_64 diff --git a/apt-requirements.txt b/apt-requirements.txt index 6d5f56b..6c314f8 100644 --- a/apt-requirements.txt +++ b/apt-requirements.txt @@ -6,10 +6,13 @@ gir1.2-notify-0.7 libcairo-gobject2 libgirepository1.0-dev libjson-glib-dev +librsvg2-common libwebkit2gtk-4.0-dev meson ninja python-gi-dev +python3-gi +python3-gi-cairo python3-dev python3-pip python3-venv diff --git a/barkshark_web/cli.py b/barkshark_web/cli.py index 6725abd..a6a32e4 100644 --- a/barkshark_web/cli.py +++ b/barkshark_web/cli.py @@ -6,7 +6,9 @@ from os import environ as env from . import __shortname__, __software__, __version__ from .component.application import Application +from .database.base import default_config from .dbus import Client +from .functions import install_desktop_file context_settings = dict( @@ -27,6 +29,9 @@ def cli(ctx, profile): dbus = Client() ) + if (deskfile := install_desktop_file(overwrite=False)): + logging.verbose(f'Installed new desktop file: {deskfile}') + if not ctx.invoked_subcommand: cli_run.callback([]) @@ -64,6 +69,16 @@ def cli_run(ctx, urls): ctx.obj.app.run([]) +@cli.command('install') +@click.pass_context +def cli_install(ctx): + if (deskfile := install_desktop_file(overwrite=True)): + click.echo(f'Installed new desktop file') + + else: + click.echo('Failed to install new desktop file') + + @cli.group('tab') @click.pass_context def cli_tab(ctx): @@ -95,5 +110,46 @@ def cli_tab_new(ctx, urls): ctx.obj.dbus.disconnect() +@cli.group('config') +@click.pass_context +def cli_config(ctx): + pass + + +@cli_config.command('list') +@click.pass_context +def cli_config_list(ctx): + click.echo('Current config:') + + with ctx.obj.app.db.session as s: + for key in default_config.keys(): + if key == 'version': + continue + + value = s.get_config(key) + click.echo(f'- {key.replace("_", "-").ljust(25)}: {value}') + + +@cli_config.command('get') +@click.argument('key') +@click.pass_context +def cli_config_get(ctx, key): + with ctx.obj.app.db.session as s: + value = s.get_config(key.replace('-', '_')) + + click.echo(f'{key} = {value}') + + +@cli_config.command('set') +@click.argument('key') +@click.argument('value') +@click.pass_context +def cli_config_set(ctx, key, value): + with ctx.obj.app.db.session as s: + value = s.put_config(key.replace('-', '_'), value) + + click.echo(f'{key} = {value}') + + def main(): cli(prog_name=__shortname__) diff --git a/barkshark_web/component/application.py b/barkshark_web/component/application.py index f08f9b5..5f6e379 100644 --- a/barkshark_web/component/application.py +++ b/barkshark_web/component/application.py @@ -1,7 +1,8 @@ import sys +from izzylib.enums import LogLevel from izzylib.http_client import HttpClient -from izzylib.misc import signal_handler +from izzylib.misc import class_name, signal_handler from izzylib_http_async import Template from izzylib_sql import Database from urllib.parse import quote @@ -182,8 +183,15 @@ class Application(Gtk.Application): self.window = Window(self) self.dbus = dbus.Server(self.window) - self.add_window(self.window) + try: + if logging.get_config('level') in [LogLevel.VERBOSE, LogLevel.DEBUG]: + self.window.themes.watcher_start() + except OSError as e: + logging.warning(f'Failed to start theme watcher') + logging.error(f'{class_name(e)}: {e}') + + self.add_window(self.window) self.setup_password_storage() with self.db.session as s: diff --git a/barkshark_web/component/window.py b/barkshark_web/component/window.py index 8c902d3..4922d98 100644 --- a/barkshark_web/component/window.py +++ b/barkshark_web/component/window.py @@ -441,6 +441,8 @@ class Window(BuilderBase, Gtk.ApplicationWindow): def handle_window_close(self, *args): logging.verbose('Saving data') + self.hide() + self.app.password.stop() self.tabs_save() diff --git a/barkshark_web/database/base.py b/barkshark_web/database/base.py index 263384a..10f37f9 100644 --- a/barkshark_web/database/base.py +++ b/barkshark_web/database/base.py @@ -393,13 +393,15 @@ class CustomSession(Session): if value == None: value = default_config[key][0] - return self.put_cached('config', key, + row = self.put_cached('config', key, row = self.fetch('config', key=key).one(), key = key, value = DotDict(value).to_json() if subtype == 'dict' else str(value), type = subtype ) + return row.value + def put_extension(self, extension): if self.get_extension(extension.digest): diff --git a/barkshark_web/dbus.py b/barkshark_web/dbus.py index dc67e3d..9ae12ea 100644 --- a/barkshark_web/dbus.py +++ b/barkshark_web/dbus.py @@ -116,6 +116,10 @@ class Client(): return self.run_cmd('GetTabs') + def Internal(self, data: str) -> str: + return self.run_command('Internal', data) + + def Present(self): return self.run_cmd('Present') diff --git a/barkshark_web/functions.py b/barkshark_web/functions.py index be249ce..60ee8fb 100644 --- a/barkshark_web/functions.py +++ b/barkshark_web/functions.py @@ -1,11 +1,14 @@ import cairo import multiprocessing import random +import os import socket +import sys import threading import time import traceback +from configobj import ConfigObj from ctypes import cdll, create_string_buffer, byref from dns.resolver import NXDOMAIN, resolve from izzylib.http_client import HttpClient @@ -17,6 +20,7 @@ from . import __version__, var js_cache = LruCache() +appimage_exec = os.environ.get('APPIMAGE') client_options = {'appagent': f'PyWeb/{__version__}'} glib_types = { bytes: GLib.Variant.new_byte, @@ -27,6 +31,17 @@ glib_types = { list: GLib.Variant.new_array } +categories = ['Network', 'WebBrowser'] +mimetypes = [ + 'application/x-extension-htm', 'application/x-extension-html', + 'application/x-extension-shtml', 'application/x-extension-xht', + 'application/x-extension-xhtml', 'application/x-extension-xml' + 'text/html', 'text/xml', + 'application/xhtml+xml', 'application/xml', + 'x-scheme-handler/http', 'x-scheme-handler/https', + 'x-scheme-handler/ftp', 'x-scheme-handler/file' +] + ## Haven't implemented proxy support yet #if var.proxy: #client_options.update({ @@ -113,6 +128,57 @@ def icon_set(widget, *args, **kwargs): return widget +def install_desktop_file(overwrite=False): + app = get_app() + deskfile = Path.xdg.data.join('applications/barkshark-web.desktop') + deskfile.parent.mkdir() + workdir = app.path.script.parent + executable = appimage_exec or f'{sys.executable} -m barkshark_web' + + if deskfile.exists() and not overwrite: + logging.debug(f'Desktop file already exists: {deskfile}') + return + + config = ConfigObj() + config.filename = deskfile + + config.update({ + 'Desktop Entry': { + 'Name': 'Barkshark Web', + 'GenericName': 'Web Browser', + 'Comment': 'Browse the World Wide Web', + 'Categories': ';'.join(categories), + 'Icon': 'applications-internet', + 'MimeType': ';'.join(mimetypes), + 'Exec': f'{sys.executable} -m barkshark_web %U', + 'Path': workdir, + 'StartupNotify': True, + 'StartupWMClass': 'BarksharkWeb', + 'Type': 'Application', + 'X-DBUS-ServiceName': 'xyz.barkshark.Web', + 'X-DBUS-StartupType': 'Unique' + }, + 'Desktop Action NewTab': { + 'Name': 'New Tab', + 'Exec': f'{sys.executable} -m barkshark_web tab new', + 'Path': workdir + } + }) + + if appimage_exec: + del config['Desktop Entry']['Path'] + del config['Desktop Action NewTab']['Path'] + + config.write() + deskfile.chmod(755) + + return deskfile + + +def set_default(): + subprocess.run(['xdg-settings' 'set' 'default-web-browser' 'barkshark-web.desktop']) + + def load_js_file(name, ext=False): cache_name = name + str(1 if ext else 0) cached = js_cache.fetch(cache_name) diff --git a/barkshark_web/themes.py b/barkshark_web/themes.py index 6e51b01..7f98524 100644 --- a/barkshark_web/themes.py +++ b/barkshark_web/themes.py @@ -33,9 +33,6 @@ class Themes(ComponentBase, ObjectBase): self.setup() - if logging.get_config('level') in [LogLevel.VERBOSE, LogLevel.DEBUG]: - self.watcher_start() - def __del__(self): self.watcher_stop() diff --git a/pyvenv.json b/pyvenv.json index 5e9a06d..82d22df 100644 --- a/pyvenv.json +++ b/pyvenv.json @@ -11,6 +11,11 @@ "options": [], "url": null }, + "configobj": { + "version": "5.1.0.dev0", + "options": [], + "url": "git+https://github.com/DiffSK/configobj" + }, "dasbus": { "version": "1.6", "options": [], @@ -32,7 +37,7 @@ "url": "git+https://git.barkshark.xyz/izaliamae/izzylib-http-async" }, "izzylib-sql": { - "version": "0.1.0", + "version": "0.1.1", "options": [], "url": "git+https://git.barkshark.xyz/izaliamae/izzylib-sql" }, @@ -61,6 +66,11 @@ "options": [], "url": null }, + "pycairo": { + "version": "1.21.0", + "options": [], + "url": null + }, "pygobject": { "version": "3.38.0", "options": [], diff --git a/requirements.txt b/requirements.txt index 04da5a4..bd463ba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ beautifulsoup4==4.9.3 click==8.1.0 +configobj@git+https://github.com/DiffSK/configobj dasbus==1.6 dnspython==2.2.1 -izzylib@git+https://git.barkshark.xyz/izaliamae/izzylib@0.7.5 izzylib-http-async@git+https://git.barkshark.xyz/izaliamae/izzylib-http-async izzylib-sql@git+https://git.barkshark.xyz/izaliamae/izzylib-sql lxml==4.6.3 diff --git a/setup.cfg b/setup.cfg index 226656e..9084765 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,13 +1,12 @@ [metadata] name = Barkshark Web -version = 0.3.8 +version = 0.4.0 author = Zoey Mae author_email = zoey@barkshark.xyz url = https://git.barkshark.xyz/izaliamae/barkshark-web description = Python venv manager long_description = file: README.md long_description_content_type = text/markdown; charset=UTF-8 -license = CNPL 4+ license_file = LICENSE platform = any keywords = python development venv @@ -35,6 +34,7 @@ packages = setup_requires = beautifulsoup4==4.9.3 click==8.1.0 + configobj@git+https://github.com/DiffSK/configobj dasbus==1.6 dnspython==2.2.1 izzylib@git+https://git.barkshark.xyz/izaliamae/izzylib@0.7.5