0
0
Fork 0
mirror of https://github.com/boltgolt/howdy.git synced 2024-10-17 10:06:53 +02:00

Some small fixes (#862)

* Also use PKEXEC_UID to get username

Privilege elevation can occur through pkexec, where many environment
variables are not accessible.

This fixes the following problem - if howdy-gtk is run without sudo,
authorization occurs via pkexec, and the user variable is empty. So when
adding the first model, it is unclear to which user to add it.

* Update the container when the slide changes

In some GTK themes, when we change a slide, we see a blank window
because there is nothing to trigger the size update, and the slide is
displayed at zero size. Let's force a size update so that it always
works.

* Remove reading of non-existent '_variables' file

* More correct preview when stretching the window

The "Video" tab layout did not display correctly when resizing the
window.

* Don't add a model if the user list is empty

The list of users may be empty, and if you try to add a model, a string
concatenation error with None will occur.

For simplicity and consistency with the "Delete" button, we simply check
the size of the list after clicking.

* Show real camera ID in the 'Video' tab

* Handle the case if there are no cameras via except

Otherwise, when trying to read the /dev/v4l/by-path directory, an
exception is thrown and the program visually freezes.
This commit is contained in:
Gliese852 2024-01-17 16:25:40 +03:00 committed by GitHub
parent d4eb16cf9f
commit 344eb342f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 16 additions and 11 deletions

View file

@ -355,14 +355,11 @@
</child> </child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<placeholder/>
</child>
</object> </object>
<packing> <packing>
<property name="position">1</property> <property name="position">1</property>

View file

@ -27,6 +27,7 @@ class OnboardingWindow(gtk.Window):
self.builder.connect_signals(self) self.builder.connect_signals(self)
self.window = self.builder.get_object("onboardingwindow") self.window = self.builder.get_object("onboardingwindow")
self.slidecontainer = self.builder.get_object("slidecontainer")
self.nextbutton = self.builder.get_object("nextbutton") self.nextbutton = self.builder.get_object("nextbutton")
self.slides = [ self.slides = [
@ -53,6 +54,8 @@ class OnboardingWindow(gtk.Window):
self.slides[self.window.current_slide].hide() self.slides[self.window.current_slide].hide()
self.slides[self.window.current_slide + 1].show() self.slides[self.window.current_slide + 1].show()
self.window.current_slide += 1 self.window.current_slide += 1
# the shown child may have zero/wrong dimensions
self.slidecontainer.queue_resize()
if self.window.current_slide == 1: if self.window.current_slide == 1:
self.execute_slide1() self.execute_slide1()
@ -119,10 +122,10 @@ class OnboardingWindow(gtk.Window):
except Exception: except Exception:
self.show_error(_("Error while importing OpenCV2"), _("Try reinstalling cv2")) self.show_error(_("Error while importing OpenCV2"), _("Try reinstalling cv2"))
device_ids = os.listdir("/dev/v4l/by-path")
device_rows = [] device_rows = []
try:
if not device_ids: device_ids = os.listdir("/dev/v4l/by-path")
except Exception:
self.show_error(_("No webcams found on system"), _("Please configure your camera yourself if you are sure a compatible camera is connected")) self.show_error(_("No webcams found on system"), _("Please configure your camera yourself if you are sure a compatible camera is connected"))
# Loop though all devices # Loop though all devices

View file

@ -44,6 +44,8 @@ def on_user_add(self, button):
def on_model_add(self, button): def on_model_add(self, button):
if self.userlist.items == 0:
return
# Open question dialog # Open question dialog
dialog = gtk.MessageDialog(parent=self, flags=gtk.DialogFlags.MODAL, type=gtk.MessageType.QUESTION, buttons=gtk.ButtonsType.OK_CANCEL) dialog = gtk.MessageDialog(parent=self, flags=gtk.DialogFlags.MODAL, type=gtk.MessageType.QUESTION, buttons=gtk.ButtonsType.OK_CANCEL)
dialog.set_title(_("Confirm Model Creation")) dialog.set_title(_("Confirm Model Creation"))

View file

@ -14,7 +14,6 @@ MAX_WIDTH = 300
def on_page_switch(self, notebook, page, page_num): def on_page_switch(self, notebook, page, page_num):
if page_num == 1: if page_num == 1:
path = "/dev/video1"
try: try:
self.config = configparser.ConfigParser() self.config = configparser.ConfigParser()
@ -22,6 +21,8 @@ def on_page_switch(self, notebook, page, page_num):
except Exception: except Exception:
print(_("Can't open camera")) print(_("Can't open camera"))
path = self.config.get("video", "device_path")
try: try:
# if not self.cv2: # if not self.cv2:
import cv2 import cv2
@ -30,7 +31,7 @@ def on_page_switch(self, notebook, page, page_num):
print(_("Can't import OpenCV2")) print(_("Can't import OpenCV2"))
try: try:
self.capture = cv2.VideoCapture(self.config.get("video", "device_path")) self.capture = cv2.VideoCapture(path)
except Exception: except Exception:
print(_("Can't open camera")) print(_("Can't open camera"))

View file

@ -5,7 +5,6 @@
_howdy() { _howdy() {
local cur prev opts local cur prev opts
local config_path="@config_path@" local config_path="@config_path@"
source _variables
COMPREPLY=() COMPREPLY=()
# The argument typed so far # The argument typed so far
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"

View file

@ -4,6 +4,7 @@
# Import required modules # Import required modules
import sys import sys
import os import os
import pwd
import getpass import getpass
import argparse import argparse
import builtins import builtins
@ -13,8 +14,10 @@ from i18n import _
# Try to get the original username (not "root") from shell # Try to get the original username (not "root") from shell
sudo_user = os.environ.get("SUDO_USER") sudo_user = os.environ.get("SUDO_USER")
doas_user = os.environ.get("DOAS_USER") doas_user = os.environ.get("DOAS_USER")
pkexec_uid = os.environ.get("PKEXEC_UID")
pkexec_user = pwd.getpwuid(int(pkexec_uid))[0] if pkexec_uid else ""
env_user = getpass.getuser() env_user = getpass.getuser()
user = next((u for u in [sudo_user, doas_user, env_user] if u), "") user = next((u for u in [sudo_user, doas_user, pkexec_user, env_user] if u), "")
# If that fails, error out # If that fails, error out
if user == "": if user == "":