Skip to content

Commit 8fd7e46

Browse files
Refactor get exec string in separate method (#212)
* move exec string build, to separate method
1 parent 8a1fd90 commit 8fd7e46

File tree

1 file changed

+81
-71
lines changed

1 file changed

+81
-71
lines changed

usr/lib/webapp-manager/common.py

Lines changed: 81 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -211,78 +211,10 @@ def create_webapp(self, name, url, icon, category, browser, custom_parameters, i
211211
desktop_file.write("Name=%s\n" % name)
212212
desktop_file.write("Comment=%s\n" % _("Web App"))
213213

214-
if browser.browser_type in [BROWSER_TYPE_FIREFOX, BROWSER_TYPE_FIREFOX_FLATPAK]:
215-
# Firefox based
216-
firefox_profiles_dir = FIREFOX_PROFILES_DIR if browser.browser_type == BROWSER_TYPE_FIREFOX else FIREFOX_FLATPAK_PROFILES_DIR
217-
firefox_profile_path = os.path.join(firefox_profiles_dir, codename)
218-
exec_string = ("Exec=sh -c 'XAPP_FORCE_GTKWINDOW_ICON=\"" + icon + "\" " + browser.exec_path +
219-
" --class WebApp-" + codename +
220-
" --profile " + firefox_profile_path +
221-
" --no-remote ")
222-
if privatewindow:
223-
exec_string += "--private-window "
224-
if custom_parameters:
225-
exec_string += " {}".format(custom_parameters)
226-
desktop_file.write(exec_string + "\"" + url + "\"" + "'\n")
227-
# Create a Firefox profile
228-
shutil.copytree('/usr/share/webapp-manager/firefox/profile', firefox_profile_path)
229-
if navbar:
230-
shutil.copy('/usr/share/webapp-manager/firefox/userChrome-with-navbar.css', os.path.join(firefox_profile_path, "chrome", "userChrome.css"))
231-
elif browser.browser_type == BROWSER_TYPE_LIBREWOLF_FLATPAK:
232-
# LibreWolf flatpak
233-
firefox_profiles_dir = LIBREWOLF_FLATPAK_PROFILES_DIR
234-
firefox_profile_path = os.path.join(firefox_profiles_dir, codename)
235-
exec_string = ("Exec=sh -c 'XAPP_FORCE_GTKWINDOW_ICON=\"" + icon + "\" " + browser.exec_path +
236-
" --class WebApp-" + codename +
237-
" --profile " + firefox_profile_path +
238-
" --no-remote ")
239-
if privatewindow:
240-
exec_string += "--private-window "
241-
desktop_file.write(exec_string + "\"" + url + "\"" + "'\n")
242-
# Create a Firefox profile
243-
shutil.copytree('/usr/share/webapp-manager/firefox/profile', firefox_profile_path)
244-
if navbar:
245-
shutil.copy('/usr/share/webapp-manager/firefox/userChrome-with-navbar.css', os.path.join(firefox_profile_path, "chrome", "userChrome.css"))
246-
elif browser.browser_type == BROWSER_TYPE_EPIPHANY:
247-
# Epiphany based
248-
epiphany_profile_path = os.path.join(EPIPHANY_PROFILES_DIR, "org.gnome.Epiphany.WebApp-" + codename)
249-
# Create symlink of profile dir at ~/.local/share
250-
epiphany_orig_prof_dir=os.path.join(os.path.expanduser("~/.local/share"), "org.gnome.Epiphany.WebApp-" + codename)
251-
os.symlink(epiphany_profile_path, epiphany_orig_prof_dir)
252-
exec_string = "Exec=" + browser.exec_path
253-
exec_string += " --application-mode "
254-
exec_string += " --profile=\"" + epiphany_orig_prof_dir + "\""
255-
exec_string += " " + "\"" + url + "\"" + "\n"
256-
if custom_parameters:
257-
exec_string += " {}".format(custom_parameters)
258-
desktop_file.write(exec_string)
259-
else:
260-
# Chromium based
261-
if isolate_profile:
262-
profile_path = os.path.join(PROFILES_DIR, codename)
263-
exec_string = ("Exec=" + browser.exec_path +
264-
" --app=" + "\"" + url + "\"" +
265-
" --class=WebApp-" + codename +
266-
" --user-data-dir=" + profile_path)
267-
else:
268-
exec_string = ("Exec=" + browser.exec_path +
269-
" --app=" + "\"" + url + "\"" +
270-
" --class=WebApp-" + codename)
271-
272-
if privatewindow:
273-
if browser.name == "Microsoft Edge":
274-
exec_string += " --inprivate"
275-
elif browser.name == "Microsoft Edge Beta":
276-
exec_string += " --inprivate"
277-
elif browser.name == "Microsoft Edge Dev":
278-
exec_string += " --inprivate"
279-
else:
280-
exec_string += " --incognito"
214+
exec_string = self.get_exec_string(browser, codename, custom_parameters, icon, isolate_profile, navbar,
215+
privatewindow, url)
281216

282-
if custom_parameters:
283-
exec_string += " {}".format(custom_parameters)
284-
285-
desktop_file.write(exec_string + "\n")
217+
desktop_file.write(exec_string + "\n")
286218

287219
desktop_file.write("Terminal=false\n")
288220
desktop_file.write("X-MultipleArgs=false\n")
@@ -302,6 +234,7 @@ def create_webapp(self, name, url, icon, category, browser, custom_parameters, i
302234

303235
if browser.browser_type == BROWSER_TYPE_EPIPHANY:
304236
# Move the desktop file and create a symlink
237+
epiphany_profile_path = os.path.join(EPIPHANY_PROFILES_DIR, "org.gnome.Epiphany.WebApp-" + codename)
305238
new_path = os.path.join(epiphany_profile_path, "org.gnome.Epiphany.WebApp-%s.desktop" % codename)
306239
os.makedirs(epiphany_profile_path)
307240
os.replace(path, new_path)
@@ -314,6 +247,83 @@ def create_webapp(self, name, url, icon, category, browser, custom_parameters, i
314247
with open(app_mode_file, 'w') as fp:
315248
pass
316249

250+
def get_exec_string(self, browser, codename, custom_parameters, icon, isolate_profile, navbar, privatewindow, url):
251+
if browser.browser_type in [BROWSER_TYPE_FIREFOX, BROWSER_TYPE_FIREFOX_FLATPAK]:
252+
# Firefox based
253+
firefox_profiles_dir = FIREFOX_PROFILES_DIR if browser.browser_type == BROWSER_TYPE_FIREFOX else FIREFOX_FLATPAK_PROFILES_DIR
254+
firefox_profile_path = os.path.join(firefox_profiles_dir, codename)
255+
exec_string = ("Exec=sh -c 'XAPP_FORCE_GTKWINDOW_ICON=\"" + icon + "\" " + browser.exec_path +
256+
" --class WebApp-" + codename +
257+
" --profile " + firefox_profile_path +
258+
" --no-remote ")
259+
if privatewindow:
260+
exec_string += "--private-window "
261+
if custom_parameters:
262+
exec_string += " {}".format(custom_parameters)
263+
exec_string += "\"" + url + "\"" + "'\n"
264+
# Create a Firefox profile
265+
shutil.copytree('/usr/share/webapp-manager/firefox/profile', firefox_profile_path)
266+
if navbar:
267+
shutil.copy('/usr/share/webapp-manager/firefox/userChrome-with-navbar.css',
268+
os.path.join(firefox_profile_path, "chrome", "userChrome.css"))
269+
elif browser.browser_type == BROWSER_TYPE_LIBREWOLF_FLATPAK:
270+
# LibreWolf flatpak
271+
firefox_profiles_dir = LIBREWOLF_FLATPAK_PROFILES_DIR
272+
firefox_profile_path = os.path.join(firefox_profiles_dir, codename)
273+
exec_string = ("Exec=sh -c 'XAPP_FORCE_GTKWINDOW_ICON=\"" + icon + "\" " + browser.exec_path +
274+
" --class WebApp-" + codename +
275+
" --profile " + firefox_profile_path +
276+
" --no-remote ")
277+
if privatewindow:
278+
exec_string += "--private-window "
279+
exec_string += "\"" + url + "\"" + "'\n"
280+
# Create a Firefox profile
281+
shutil.copytree('/usr/share/webapp-manager/firefox/profile', firefox_profile_path)
282+
if navbar:
283+
shutil.copy('/usr/share/webapp-manager/firefox/userChrome-with-navbar.css',
284+
os.path.join(firefox_profile_path, "chrome", "userChrome.css"))
285+
elif browser.browser_type == BROWSER_TYPE_EPIPHANY:
286+
# Epiphany based
287+
epiphany_profile_path = os.path.join(EPIPHANY_PROFILES_DIR, "org.gnome.Epiphany.WebApp-" + codename)
288+
# Create symlink of profile dir at ~/.local/share
289+
epiphany_orig_prof_dir = os.path.join(os.path.expanduser("~/.local/share"),
290+
"org.gnome.Epiphany.WebApp-" + codename)
291+
os.symlink(epiphany_profile_path, epiphany_orig_prof_dir)
292+
exec_string = "Exec=" + browser.exec_path
293+
exec_string += " --application-mode "
294+
exec_string += " --profile=\"" + epiphany_orig_prof_dir + "\""
295+
exec_string += " " + "\"" + url + "\"" + "\n"
296+
if custom_parameters:
297+
exec_string += " {}".format(custom_parameters)
298+
else:
299+
# Chromium based
300+
if isolate_profile:
301+
profile_path = os.path.join(PROFILES_DIR, codename)
302+
exec_string = ("Exec=" + browser.exec_path +
303+
" --app=" + "\"" + url + "\"" +
304+
" --class=WebApp-" + codename +
305+
" --user-data-dir=" + profile_path)
306+
else:
307+
exec_string = ("Exec=" + browser.exec_path +
308+
" --app=" + "\"" + url + "\"" +
309+
" --class=WebApp-" + codename)
310+
311+
if privatewindow:
312+
if browser.name == "Microsoft Edge":
313+
exec_string += " --inprivate"
314+
elif browser.name == "Microsoft Edge Beta":
315+
exec_string += " --inprivate"
316+
elif browser.name == "Microsoft Edge Dev":
317+
exec_string += " --inprivate"
318+
else:
319+
exec_string += " --incognito"
320+
321+
if custom_parameters:
322+
exec_string += " {}".format(custom_parameters)
323+
324+
exec_string += "\n"
325+
return exec_string
326+
317327
def edit_webapp(self, path, name, browser, url, icon, category, custom_parameters):
318328
config = configparser.RawConfigParser()
319329
config.optionxform = str

0 commit comments

Comments
 (0)