24
24
import threading
25
25
import RNS .vendor .umsgpack as msgpack
26
26
27
+ app_ui_scaling_path = None
28
+ def apply_ui_scale ():
29
+ global app_ui_scaling_path
30
+ default_scale = os .environ ["KIVY_METRICS_DENSITY" ] if "KIVY_METRICS_DENSITY" in os .environ else "unknown"
31
+ config_path = None
32
+ ui_scale_path = None
33
+
34
+ try :
35
+ if RNS .vendor .platformutils .is_android ():
36
+ import plyer
37
+ ui_scale_path = plyer .storagepath .get_application_dir ()+ "/io.unsigned.sideband/files/app_storage/ui_scale"
38
+ else :
39
+ if config_path == None :
40
+ import sbapp .plyer as plyer
41
+ ui_scale_path = plyer .storagepath .get_home_dir ()+ "/.config/sideband/app_storage/ui_scale"
42
+ if ui_scale_path .startswith ("file://" ):
43
+ ui_scale_path = ui_scale_path .replace ("file://" , "" )
44
+ else :
45
+ ui_scale_path = config_path + "/app_storage/ui_scale"
46
+
47
+ app_ui_scaling_path = ui_scale_path
48
+
49
+ except Exception as e :
50
+ RNS .log (f"Error while locating UI scale file: { e } " , RNS .LOG_ERROR )
51
+
52
+ if ui_scale_path != None :
53
+ RNS .log ("Default scaling factor on this platform is " + str (default_scale ), RNS .LOG_NOTICE )
54
+ try :
55
+ RNS .log ("Looking for scaling info in " + str (ui_scale_path ))
56
+ if os .path .isfile (ui_scale_path ):
57
+ scale_factor = None
58
+ with open (ui_scale_path , "r" ) as sf :
59
+ scale_factor = float (sf .readline ())
60
+
61
+ if scale_factor != None :
62
+ if scale_factor >= 0.3 and scale_factor <= 5.0 :
63
+ os .environ ["KIVY_METRICS_DENSITY" ] = str (scale_factor )
64
+ RNS .log ("UI scaling factor set to " + str (os .environ ["KIVY_METRICS_DENSITY" ]), RNS .LOG_NOTICE )
65
+ elif scale_factor == 0.0 :
66
+ RNS .log ("Using default UI scaling factor" , RNS .LOG_NOTICE )
67
+
68
+
69
+ except Exception as e :
70
+ RNS .log (f"Error while reading UI scaling factor: { e } " , RNS .LOG_ERROR )
71
+
27
72
if args .export_settings :
28
73
from .sideband .core import SidebandCore
29
74
sideband = SidebandCore (
@@ -143,9 +188,11 @@ class DaemonApp():
143
188
NewConv = DaemonElement ; Telemetry = DaemonElement ; ObjectDetails = DaemonElement ; Announces = DaemonElement ;
144
189
Messages = DaemonElement ; ts_format = DaemonElement ; messages_screen_kv = DaemonElement ; plyer = DaemonElement ; multilingual_markup = DaemonElement ;
145
190
ContentNavigationDrawer = DaemonElement ; DrawerList = DaemonElement ; IconListItem = DaemonElement ; escape_markup = DaemonElement ;
146
- SoundLoader = DaemonElement ;
191
+ SoundLoader = DaemonElement ; BoxLayout = DaemonElement ;
147
192
148
193
else :
194
+ apply_ui_scale ()
195
+
149
196
from kivymd .app import MDApp
150
197
app_superclass = MDApp
151
198
from kivy .core .window import Window
@@ -157,6 +204,7 @@ class DaemonApp():
157
204
from kivy .effects .scroll import ScrollEffect
158
205
from kivy .uix .screenmanager import ScreenManager
159
206
from kivy .uix .screenmanager import FadeTransition , NoTransition , SlideTransition
207
+ from kivy .uix .boxlayout import BoxLayout
160
208
from kivymd .uix .list import OneLineIconListItem , IconLeftWidget
161
209
from kivy .properties import StringProperty
162
210
from kivymd .uix .button import BaseButton , MDIconButton
@@ -2729,6 +2777,72 @@ def settings_open(self, sender=None, direction="left", no_transition=False):
2729
2777
if no_transition :
2730
2778
self .root .ids .screen_manager .transition = self .slide_transition
2731
2779
2780
+ def configure_ui_scaling_action (self , sender = None ):
2781
+ global app_ui_scaling_path
2782
+ try :
2783
+ cancel_button = MDRectangleFlatButton (text = "Cancel" ,font_size = dp (18 ))
2784
+ set_button = MDRectangleFlatButton (text = "Set" ,font_size = dp (18 ), theme_text_color = "Custom" , line_color = self .color_accept , text_color = self .color_accept )
2785
+
2786
+ dialog_content = UIScaling ()
2787
+ dialog = MDDialog (
2788
+ title = "UI Scaling" ,
2789
+ type = "custom" ,
2790
+ content_cls = dialog_content ,
2791
+ buttons = [ set_button , cancel_button ],
2792
+ # elevation=0,
2793
+ )
2794
+ dialog .d_content = dialog_content
2795
+ dialog .d_content .ids ["scaling_factor" ].text = os .environ ["KIVY_METRICS_DENSITY" ] if "KIVY_METRICS_DENSITY" in os .environ else "0.0"
2796
+ def dl_yes (s ):
2797
+ new_sf = 1.0
2798
+ scaling_ok = False
2799
+ try :
2800
+ si = dialog .d_content .ids ["scaling_factor" ].text
2801
+ sf = float (si )
2802
+ if (sf >= 0.3 and sf <= 5.0 ) or sf == 0.0 :
2803
+ new_sf = sf
2804
+ scaling_ok = True
2805
+
2806
+ except Exception as e :
2807
+ RNS .log ("Error while getting scaling factor from user: " + str (e ), RNS .LOG_ERROR )
2808
+
2809
+ if scaling_ok :
2810
+ dialog .d_content .ids ["scaling_factor" ].helper_text = ""
2811
+ dialog .d_content .ids ["scaling_factor" ].helper_text_mode = "on_focus"
2812
+ dialog .d_content .ids ["scaling_factor" ].error = False
2813
+ dialog .dismiss ()
2814
+ if app_ui_scaling_path == None :
2815
+ RNS .log ("No path to UI scaling factor file could be found, cannot save scaling factor" , RNS .LOG_ERROR )
2816
+ else :
2817
+ try :
2818
+ with open (app_ui_scaling_path , "w" ) as sfile :
2819
+ sfile .write (str (new_sf ))
2820
+ RNS .log (f"Saved configured scaling factor { new_sf } to { app_ui_scaling_path } " , RNS .LOG_DEBUG )
2821
+ except Exception as e :
2822
+ RNS .log (f"Error while saving scaling factor { new_sf } to { app_ui_scaling_path } : { e } " , RNS .LOG_ERROR )
2823
+
2824
+ else :
2825
+ dialog .d_content .ids ["scaling_factor" ].helper_text = "Invalid scale factor, check your input"
2826
+ dialog .d_content .ids ["scaling_factor" ].helper_text_mode = "persistent"
2827
+ dialog .d_content .ids ["scaling_factor" ].error = True
2828
+
2829
+ def dl_no (s ):
2830
+ dialog .dismiss ()
2831
+
2832
+ def dl_ds (s ):
2833
+ self .dialog_open = False
2834
+
2835
+ set_button .bind (on_release = dl_yes )
2836
+ cancel_button .bind (on_release = dl_no )
2837
+
2838
+ dialog .bind (on_dismiss = dl_ds )
2839
+ dialog .open ()
2840
+ self .dialog_open = True
2841
+
2842
+ except Exception as e :
2843
+ RNS .log ("Error while creating UI scaling dialog: " + str (e ), RNS .LOG_ERROR )
2844
+
2845
+
2732
2846
def settings_action (self , sender = None , direction = "left" ):
2733
2847
if self .settings_ready :
2734
2848
self .settings_open (direction = direction )
@@ -5966,6 +6080,9 @@ class DialogItem(OneLineIconListItem):
5966
6080
class MDMapIconButton (MDIconButton ):
5967
6081
pass
5968
6082
6083
+ class UIScaling (BoxLayout ):
6084
+ pass
6085
+
5969
6086
if not args .daemon :
5970
6087
from kivy .base import ExceptionManager , ExceptionHandler
5971
6088
class SidebandExceptionHandler (ExceptionHandler ):
0 commit comments