Skip to content

Commit

Permalink
Adding notice on snap permissions (#790)
Browse files Browse the repository at this point in the history
  • Loading branch information
raivisdejus authored Jun 9, 2024
1 parent 2f0b826 commit 3bb9dd8
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ Download and run the `.exe` file in the [releases page](https://github.com/chidi
```shell
sudo apt-get install libportaudio2
sudo snap install buzz
sudo snap connect buzz:audio-record
sudo snap connect buzz:password-manager-service
sudo snap connect buzz:pulseaudio
sudo snap connect buzz:removable-media
```
36 changes: 28 additions & 8 deletions buzz/locale/lv_LV/LC_MESSAGES/buzz.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-07 21:05+0300\n"
"PO-Revision-Date: 2024-06-07 21:06+0300\n"
"POT-Creation-Date: 2024-06-09 13:25+0300\n"
"PO-Revision-Date: 2024-06-09 13:27+0300\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: lv_LV\n"
Expand Down Expand Up @@ -43,7 +43,7 @@ msgid "View Transcript Timestamps"
msgstr "Aplūkot atpazīšanas laikus"

#: buzz/settings/shortcut.py:25 buzz/widgets/main_window_toolbar.py:60
#: buzz/widgets/main_window.py:200
#: buzz/widgets/main_window.py:214
msgid "Clear History"
msgstr "Notīrīt vēsturi"

Expand Down Expand Up @@ -148,6 +148,26 @@ msgstr ""
"Lūdzu pārbaudiet savas audio ierīces vai pārbaudiet lietotnes ziņojumu "
"žurnālus, lai iegūtu papildu informāciju."

#: buzz/widgets/snap_notice.py:9
msgid "Snap permission notice"
msgstr "Snap atļauju piezīme"

#: buzz/widgets/snap_notice.py:13
msgid ""
"No input devices found, please check that snap permissions have been granted"
msgstr ""
"Nav atrasta neviena skaņas ievades ierīce, iespējams nav piešķirtas "
"nepieciešamās snap atļaujas"

#: buzz/widgets/snap_notice.py:16
msgid ""
"To enable necessary permissions run the following commands in the terminal"
msgstr "Lai piešķirtu nepieciešamās atļaujas izpildiet šīs komandas"

#: buzz/widgets/snap_notice.py:30
msgid "Close"
msgstr "Aizvērt"

#: buzz/widgets/menu_bar.py:38
msgid "Import File..."
msgstr "Importēt failu..."
Expand All @@ -168,24 +188,24 @@ msgstr "Fails"
msgid "Help"
msgstr "Palīdzība"

#: buzz/widgets/main_window.py:202
#: buzz/widgets/main_window.py:216
msgid ""
"Are you sure you want to delete the selected transcription(s)? This action "
"cannot be undone."
msgstr ""
"Vai tiešām vēlaties dzēst izvēlētos transkriptus? Šī ir neatgriezeniska "
"darbība."

#: buzz/widgets/main_window.py:222
#: buzz/widgets/main_window.py:236
msgid "Select audio file"
msgstr "Izvēlieties audio failu"

#: buzz/widgets/main_window.py:256
#: buzz/widgets/main_window.py:270
#: buzz/widgets/preferences_dialog/models_preferences_widget.py:191
msgid "Error"
msgstr "Kļūda"

#: buzz/widgets/main_window.py:256
#: buzz/widgets/main_window.py:270
msgid "Unable to save OpenAI API key to keyring"
msgstr "Neizdevās saglabāt OpenAI API atslēgu atslēgu saišķī"

Expand Down Expand Up @@ -342,7 +362,7 @@ msgstr ""
"Jūsu API atslēga ir derīga. Buzz izmantos to runas atpazīšanai ar Whisper "
"API."

#: buzz/widgets/preferences_dialog/general_preferences_widget.py:157
#: buzz/widgets/preferences_dialog/general_preferences_widget.py:156
msgid "Select Export Folder"
msgstr "Izvēlieties mapi kurā eksportēt"

Expand Down
14 changes: 14 additions & 0 deletions buzz/widgets/main_window.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import logging
import sounddevice
from typing import Tuple, List, Optional

from PyQt6 import QtGui
Expand Down Expand Up @@ -32,6 +34,7 @@
from buzz.widgets.import_url_dialog import ImportURLDialog
from buzz.widgets.main_window_toolbar import MainWindowToolbar
from buzz.widgets.menu_bar import MenuBar
from buzz.widgets.snap_notice import SnapNotice
from buzz.widgets.preferences_dialog.models.preferences import Preferences
from buzz.widgets.transcriber.file_transcriber_widget import FileTranscriberWidget
from buzz.widgets.transcription_task_folder_watcher import (
Expand Down Expand Up @@ -137,6 +140,17 @@ def __init__(self, transcription_service: TranscriptionService):
self.folder_watcher.task_found.connect(self.add_task)
self.folder_watcher.find_tasks()

if os.environ.get('SNAP_NAME', '') == 'buzz':
self.check_linux_permissions()

def check_linux_permissions(self):
devices = sounddevice.query_devices()
input_devices = [device for device in devices if device['max_input_channels'] > 0]

if len(input_devices) == 0:
snap_notice = SnapNotice(self)
snap_notice.show()

def on_preferences_changed(self, preferences: Preferences):
self.preferences = preferences
self.save_preferences(preferences)
Expand Down
32 changes: 32 additions & 0 deletions buzz/widgets/snap_notice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from PyQt6.QtWidgets import QDialog, QVBoxLayout, QTextEdit, QLabel, QPushButton
from buzz.locale import _


class SnapNotice(QDialog):
def __init__(self, parent=None):
super().__init__(parent)

self.setWindowTitle(_("Snap permission notice"))

self.layout = QVBoxLayout(self)

self.notice_label = QLabel(_("No input devices found, please check that snap permissions have been granted"))
self.layout.addWidget(self.notice_label)

self.instruction_label = QLabel(_("To enable necessary permissions run the following commands in the terminal"))
self.layout.addWidget(self.instruction_label)

self.text_edit = QTextEdit(self)
self.text_edit.setPlainText(
"sudo snap connect buzz:audio-record\n"
"sudo snap connect buzz:password-manager-service\n"
"sudo snap connect buzz:pulseaudio\n"
"sudo snap connect buzz:removable-media"
)
self.text_edit.setReadOnly(True)
self.text_edit.setFixedHeight(80)
self.layout.addWidget(self.text_edit)

self.button = QPushButton(_("Close"), self)
self.button.clicked.connect(self.close)
self.layout.addWidget(self.button)
4 changes: 4 additions & 0 deletions docs/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Download and run the `Buzz-x.y.z.exe` file.
```shell
sudo apt-get install libportaudio2
sudo snap install buzz
sudo snap connect buzz:audio-record
sudo snap connect buzz:password-manager-service
sudo snap connect buzz:pulseaudio
sudo snap connect buzz:removable-media
```

[![Get it from the Snap Store](https://snapcraft.io/static/images/badges/en/snap-store-black.svg)](https://snapcraft.io/buzz)
Expand Down
10 changes: 10 additions & 0 deletions tests/widgets/main_window_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from buzz.db.entity.transcription import Transcription
from buzz.db.service.transcription_service import TranscriptionService
from buzz.widgets.main_window import MainWindow
from buzz.widgets.snap_notice import SnapNotice
from buzz.widgets.transcriber.file_transcriber_widget import FileTranscriberWidget
from buzz.widgets.transcription_viewer.transcription_viewer_widget import (
TranscriptionViewerWidget,
Expand Down Expand Up @@ -284,3 +285,12 @@ def _get_status(table_widget: QTableView, row_index: int):
def _get_toolbar_action(window: MainWindow, text: str):
toolbar: QToolBar = window.findChild(QToolBar)
return [action for action in toolbar.actions() if action.text() == text][0]

def test_snap_notice_dialog(self, qtbot: QtBot):
snap_notice = SnapNotice()
snap_notice.show()

qtbot.wait_until(lambda: snap_notice.isVisible(), timeout=1000)

snap_notice.close()
assert not snap_notice.isVisible()

0 comments on commit 3bb9dd8

Please sign in to comment.