Skip to content

Commit

Permalink
Add close to tray functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
justin025 committed Nov 30, 2024
1 parent a8f3ff8 commit d57cca5
Showing 6 changed files with 167 additions and 103 deletions.
1 change: 1 addition & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
@@ -86,6 +86,7 @@ Customize **OnTheSpot** to fit your preferences by adjusting the settings in the
| **Disable Bulk Download Notices** | Disables pop-up messages while downloading multiple songs or episodes. |
| **Mirror Spotify Playback** | Download currently playing song on the selected spotify account |
| **Windows 10 Explorer Thumbnails** | Embed thumbnails in a format that respects Windows 10 explorer and media player, this is an older format of ID3 and not widely supported. |
| **Close To Tray** | Close application to tray on exit. |
| **Check for Updates** | Automatically check for application updates. |
| **Track/Episode Format** | Select the audio format for your downloaded music or podcasts (e.g. `mp3`, `flac`, `ogg`, `m4a`). |
| [**Track/Episode Path**](#trackplaylist-path-format) | Customize the file naming pattern for tracks, episodes, and playlists using variables like `{artist}`, `{album}`, etc. |
45 changes: 39 additions & 6 deletions src/onthespot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,51 @@
#!/usr/bin/env python3
import os
import sys
import threading
from PyQt6.QtCore import QTranslator
from PyQt6.QtWidgets import QApplication
from PyQt6.QtWidgets import QApplication, QSystemTrayIcon, QMenu, QStyle
from PyQt6.QtGui import QIcon
from .gui.mainui import MainWindow
from .gui.minidialog import MiniDialog
from .runtimedata import get_logger
from .otsconfig import config
from .parse_item import parsingworker

class TrayApp:
def __init__(self, main_window):
self.main_window = main_window
self.tray_icon = QSystemTrayIcon(self.main_window)
self.tray_icon.setIcon(QIcon(os.path.join(config.app_root, 'resources', 'icons', 'onthespot.png')))
self.tray_icon.setVisible(True)
tray_menu = QMenu()
tray_menu.addAction("Show", self.show_window)
tray_menu.addAction("Quit", self.quit_application)
self.tray_icon.setContextMenu(tray_menu)
self.tray_icon.activated.connect(self.tray_icon_clicked)

def tray_icon_clicked(self, reason):
if reason == QSystemTrayIcon.ActivationReason.Trigger:
self.show_window()

def show_window(self):
self.main_window.show()
self.main_window.raise_()
self.main_window.activateWindow()

def quit_application(self):
QApplication.quit()


def main():
logger = get_logger('__init__')
logger.info('Starting application in \n3\n2\n1')
app = QApplication(sys.argv)

# Migration (>v1.0.3)
if isinstance(config.get("file_hertz"), str):
config.set_("file_hertz", int(config.get("file_hertz")))

# Set Application Version
version = "v1.0.3"
logger.info(f'OnTheSpot Version: {version}')

config.set_("version", version)

# Language
@@ -34,6 +61,8 @@ def main():

config.update()

app = QApplication(sys.argv)

translator = QTranslator()
path = os.path.join(os.path.join(config.app_root, 'resources', 'translations'),
f"{config.get('language')}.qm")
@@ -45,7 +74,7 @@ def main():
thread.daemon = True
thread.start()

# Check for start url
# Check for start URL
try:
if sys.argv[1] == "-u" or sys.argv[1] == "--url":
start_url = sys.argv[2]
@@ -56,11 +85,15 @@ def main():

_dialog = MiniDialog()
window = MainWindow(_dialog, start_url)

if config.get('close_to_tray'):
tray_app = TrayApp(window)

app.setDesktopFileName('org.onthespot.OnTheSpot')
app.exec()

logger.info('Good bye ..')
os._exit(0)


if __name__ == '__main__':
main()
5 changes: 5 additions & 0 deletions src/onthespot/gui/mainui.py
Original file line number Diff line number Diff line change
@@ -56,6 +56,11 @@ def contribute(self):
url = "https://github.com/justin025/OnTheSpot/tree/main#contributing"
open_item(url)

def closeEvent(self, event):
if config.get('close_to_tray'):
event.ignore()
self.hide()

def __init__(self, _dialog, start_url=''):
super(MainWindow, self).__init__()
self.path = os.path.dirname(os.path.realpath(__file__))
214 changes: 118 additions & 96 deletions src/onthespot/gui/qtui/main.ui
Original file line number Diff line number Diff line change
@@ -656,7 +656,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-1320</y>
<y>-732</y>
<width>627</width>
<height>3152</height>
</rect>
@@ -1390,6 +1390,41 @@
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_100">
<item>
<widget class="QGroupBox" name="group_playlist_cfg_m3u_9">
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_82">
<item>
<widget class="QCheckBox" name="inp_close_to_tray">
<property name="toolTip">
<string/>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Close To Tray</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_21">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="group_playlist_cfg_m3u_7">
<property name="title">
@@ -1425,19 +1460,6 @@
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_15">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
@@ -1453,6 +1475,88 @@
<string>Downloads</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_27">
<item>
<widget class="QGroupBox" name="gb1_13">
<property name="title">
<string/>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_244">
<item>
<widget class="QGroupBox" name="groupBox_134">
<property name="title">
<string/>
</property>
<property name="flat">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_245">
<item>
<widget class="QLabel" name="lb_file_bitrate">
<property name="text">
<string>File Bitrate</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="inp_file_bitrate"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_135">
<property name="title">
<string/>
</property>
<property name="flat">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_246">
<item>
<widget class="QLabel" name="lb_file_bitrate_2">
<property name="text">
<string>File Hertz</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_20">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="inp_file_hertz">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<number>10000</number>
</property>
<property name="maximum">
<number>10000000</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb1_0">
<property name="title">
@@ -1994,88 +2098,6 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb1_13">
<property name="title">
<string/>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_244">
<item>
<widget class="QGroupBox" name="groupBox_134">
<property name="title">
<string/>
</property>
<property name="flat">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_245">
<item>
<widget class="QLabel" name="lb_file_bitrate">
<property name="text">
<string>File Bitrate</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="inp_file_bitrate"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_135">
<property name="title">
<string/>
</property>
<property name="flat">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_246">
<item>
<widget class="QLabel" name="lb_file_bitrate_2">
<property name="text">
<string>File Hertz</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_20">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="inp_file_hertz">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<number>10000</number>
</property>
<property name="maximum">
<number>10000000</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb1_4">
<property name="title">
2 changes: 2 additions & 0 deletions src/onthespot/gui/settings.py
Original file line number Diff line number Diff line change
@@ -72,6 +72,7 @@ def load_config(self):
self.inp_overwrite_existing_metadata.setChecked(config.get("overwrite_existing_metadata"))
self.inp_embed_service_id.setChecked(config.get("embed_service_id"))
self.inp_windows_explorer_thumbnails.setChecked(config.get("windows_10_explorer_thumbnails"))
self.inp_close_to_tray.setChecked(config.get("close_to_tray"))

self.inp_enable_search_tracks.setChecked(config.get("enable_search_tracks"))
self.inp_enable_search_albums.setChecked(config.get("enable_search_albums"))
@@ -167,6 +168,7 @@ def save_config(self):
config.set_('overwrite_existing_metadata', self.inp_overwrite_existing_metadata.isChecked())
config.set_('embed_service_id', self.inp_embed_service_id.isChecked())
config.set_('windows_10_explorer_thumbnails', self.inp_windows_explorer_thumbnails.isChecked())
config.set_('close_to_tray', self.inp_close_to_tray.isChecked())

config.set_('enable_search_tracks', self.inp_enable_search_tracks.isChecked())
config.set_('enable_search_albums', self.inp_enable_search_albums.isChecked())
3 changes: 2 additions & 1 deletion src/onthespot/otsconfig.py
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ def __init__(self, cfg_path=None):
self.__template_data = {
"version": "", # Application version
"debug_mode": False, # Application version
"close_to_tray": False, # Close application to tray
"check_for_updates": True, # Check for updates
"language": "en_US", # Language
"language_index": 0, # Language Index
@@ -60,7 +61,7 @@ def __init__(self, cfg_path=None):
"media_format": "mp3", # Song track media format
"podcast_media_format": "mp3", # Podcast track media format
"file_bitrate": "320k", # Converted file bitrate
"file_hertz": "44100", # Converted file hertz
"file_hertz": 44100, # Converted file hertz
"illegal_character_replacement": "-", # Character used to replace illegal characters or values in path
"force_raw": False, # Skip media conversion and metadata writing
"chunk_size": 50000, # Chunk size in bytes to download in

0 comments on commit d57cca5

Please sign in to comment.