-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
executable file
·127 lines (109 loc) · 4.49 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/python3
#
# The Qubes OS Project, http://www.qubes-os.org
# Ali's personal Qubes OS improvements, http://www.mirjamali.com
#
# Copyright (C) 2010 Joanna Rutkowska <[email protected]>
# Copyright (C) 2013 Marek Marczykowski <[email protected]>
# Copyright (C) 2024 Ali Mirjamai <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
""" My tweaks: Handle menu entries for starting applications in qubes"""
import os
import os.path
import itertools
import re
import xdg.BaseDirectory
import qubesadmin
import qubesadmin.exc
import qubesadmin.tools
import qubesadmin.vm
import qubesimgconvertertt
from qubesimgconvertertt import Image
import qubesappmenus
basedir = os.path.join(xdg.BaseDirectory.xdg_data_home, 'qubes-appmenus')
class Appmenus(qubesappmenus.Appmenus):
"""Derived class for tweaked menu entries handling"""
def appicons_create(self, vm, srcdirs=(), force=False):
"""Create/update applications icons"""
if not srcdirs:
srcdirs = self.template_icons_dirs(vm)
if not srcdirs:
return
if vm.features.get('internal', False):
return
if vm.klass == 'DispVM' and vm.auto_cleanup:
return
whitelist = self.whitelist_path(vm)
if 'menu-items' in vm.features:
whitelist = vm.features['menu-items'].split(' ')
elif os.path.exists(whitelist):
with open(whitelist, encoding='utf-8') as whitelist_f:
whitelist = [line.strip() for line in whitelist_f]
else:
whitelist = None
dstdir = self.icons_dir(vm)
if not os.path.exists(dstdir):
os.makedirs(dstdir)
elif not os.path.isdir(dstdir):
os.unlink(dstdir)
os.makedirs(dstdir)
if whitelist:
expected_icons = [os.path.splitext(x)[0] + '.png'
for x in whitelist]
else:
expected_icons = list(itertools.chain.from_iterable(
os.listdir(srcdir)
for srcdir in srcdirs
if os.path.exists(srcdir)))
for icon in expected_icons:
src_icon = self.template_for_file(srcdirs, icon)
if not src_icon:
continue
dst_icon = os.path.join(dstdir, icon)
if not os.path.exists(dst_icon) or force or \
os.path.getmtime(src_icon) > os.path.getmtime(dst_icon):
img = Image.load_from_file_pil(src_icon)
filter = vm.features.get("ttfilter", "tint")
''' Python 3.11 is nicely shipped with Qubes OS 4.2 '''
''' so we use match statement '''
match filter:
case "tint":
img=img.tint(vm.label.color)
case "overlay":
img=img.overlay(vm.label.color)
case "thin-border":
img=img.thin_border(vm.label.color)
case "thick-border":
img=img.thick_border(vm.label.color)
case "untouched":
img=img.untouched()
case "invert":
img=img.invert()
case "mirror":
img=img.mirror(1)
case "flip":
img=img.mirror(0)
case "marker":
img=img.marker(vm.label.color)
case s if re.match(r'^diagonal\+[tb][lr]$', s):
img=img.diagonal(vm.label.color, filter[-2:])
case _:
img=img.tint(args.colour)
img.save_pil(dst_icon)
for icon in os.listdir(dstdir):
if icon not in expected_icons:
os.unlink(os.path.join(dstdir, icon))