inkstitch/lib/gui/electron.py

35 wiersze
1011 B
Python
Czysty Zwykły widok Historia

2019-04-12 05:41:14 +00:00
from glob import glob
2019-04-11 03:37:16 +00:00
import os
import subprocess
2019-04-11 04:03:23 +00:00
import sys
2019-04-11 03:37:16 +00:00
from ..utils import get_bundled_dir
app_process = None
def open_url(url):
global app
2019-04-11 04:03:23 +00:00
if getattr(sys, 'frozen', None) is not None:
electron_path = os.path.join(get_bundled_dir("electron"), "inkstitch-gui")
else:
# It's a bit trickier to find the electron app in a development environment.
base_dir = get_bundled_dir("electron")
2019-04-12 20:48:25 +00:00
try:
package_dir = glob(os.path.join(base_dir, 'dist', '*-unpacked'))[0]
except IndexError:
2019-04-12 05:41:14 +00:00
raise Exception("Electron app not found. Be sure to run 'yarn; yarn dist' in %s." % base_dir)
2019-04-11 04:03:23 +00:00
2019-04-12 05:41:14 +00:00
electron_path = os.path.join(base_dir, package_dir, "inkstitch-gui")
2019-04-11 04:03:23 +00:00
2019-04-11 05:00:28 +00:00
if sys.platform == "darwin":
electron_path += ".app/Contents/MacOS/inkstitch-gui"
app_process = subprocess.Popen(["open", "-a", electron_path, "--args", url])
else:
app_process = subprocess.Popen([electron_path, url])
2019-04-11 03:37:16 +00:00
return app_process