4
4
import logging
5
5
import shutil
6
6
import json
7
+ import subprocess
8
+ import time
7
9
from pathlib import Path
8
10
from typing import Optional , Set , Union , TextIO , Iterable
9
11
@@ -146,7 +148,7 @@ def save(name=None, include=None, exclude=None, follow_symlinks=False, destinati
146
148
f .write (json .dumps (new_info )) # Write only after JSON serialization is successful
147
149
148
150
149
- def load (name , include = None , exclude = None , overwrite_unsaved_configuration = False ) -> bool :
151
+ def load (name , include = None , exclude = None , overwrite_unsaved_configuration = False , restart = True ) -> bool :
150
152
"""
151
153
The name is not validated in this function.
152
154
True is returned if the user canceled the action.
@@ -176,6 +178,20 @@ def load(name, include=None, exclude=None, overwrite_unsaved_configuration=False
176
178
except Exception as e :
177
179
logger .error ('Refusing to overwrite unsaved configuration' )
178
180
raise
181
+ if restart :
182
+ restart_list = []
183
+ subprocess .run (
184
+ ['kquitapp5' , 'plasmashell' ],
185
+ stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL
186
+ )
187
+ try :
188
+ # Check if Latte Dock is running
189
+ subprocess .run (['ps' , '-C' , 'latte-dock' ], check = True , stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
190
+ except subprocess .CalledProcessError :
191
+ logger .info ('No running instance of Latte detected' )
192
+ else :
193
+ subprocess .run (['kquitapp5' , 'lattedock' ])
194
+ restart_list .append ('latte-dock' )
179
195
constants .CURRENT_PROFILE_PATH .unlink (missing_ok = True )
180
196
for path in map (lambda p : Path (p ).relative_to (Path .home ()), paths_to_save (include , exclude )):
181
197
source = profile_root / path
@@ -184,6 +200,25 @@ def load(name, include=None, exclude=None, overwrite_unsaved_configuration=False
184
200
else :
185
201
logger .info (f'The file { source } doesn\' t exist. Skipping\n ' )
186
202
shutil .copyfile (profile_root / constants .PROFILE_INFO_FILENAME , constants .CURRENT_PROFILE_PATH )
203
+ if restart :
204
+ subprocess .run (
205
+ ['kstart5' , 'plasmashell' ],
206
+ stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL
207
+ )
208
+ try :
209
+ # Check if Kwin is running
210
+ subprocess .run (['ps' , '-C' , 'kwin_x11' ], check = True , stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
211
+ except subprocess .CalledProcessError :
212
+ logger .info ('No running instance of KWin detected' )
213
+ else :
214
+ # If so, reload Kwin
215
+ subprocess .run (
216
+ ['dbus-send' , '--session' , '--dest=org.kde.KWin' , '/KWin' , 'org.kde.KWin.reloadConfig' ],
217
+ stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL
218
+ )
219
+ if 'latte-dock' in restart_list :
220
+ time .sleep (3 ) # Allow KWin to completely restart
221
+ subprocess .run (['kstart5' , 'latte-dock' ], stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
187
222
188
223
189
224
def change (results , profile = None ):
0 commit comments