Implement support for synchronous profile sessions
This commit is contained in:
parent
7cf9fdf0b3
commit
cb122c7dc0
2 changed files with 25 additions and 13 deletions
|
@ -28,7 +28,9 @@ class ApplicationController:
|
||||||
return Application.all()
|
return Application.all()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def launch(version: ApplicationVersion, profile: SessionProfile, port_number: int = None, profile_observer: Optional[ProfileObserver] = None):
|
def launch(version: ApplicationVersion, profile: SessionProfile, port_number: int = None, asynchronous: bool = True, profile_observer: Optional[ProfileObserver] = None):
|
||||||
|
|
||||||
|
from core.controllers.ProfileController import ProfileController
|
||||||
|
|
||||||
persistent_state_path = f'{profile.get_data_path()}/persistent-state'
|
persistent_state_path = f'{profile.get_data_path()}/persistent-state'
|
||||||
|
|
||||||
|
@ -56,23 +58,23 @@ class ApplicationController:
|
||||||
initialization_file.write(initialization_file_contents)
|
initialization_file.write(initialization_file_contents)
|
||||||
initialization_file.close()
|
initialization_file.close()
|
||||||
|
|
||||||
|
if asynchronous:
|
||||||
|
|
||||||
fork_process_id = os.fork()
|
fork_process_id = os.fork()
|
||||||
|
|
||||||
if not fork_process_id:
|
if not fork_process_id:
|
||||||
|
|
||||||
process = subprocess.Popen(('xinit', initialization_file_path, '--', '/usr/bin/Xephyr', '-ac', '-title', f'Simplified Privacy - {profile.name or "Unnamed Profile"}', '-screen', profile.resolution, '-no-host-grab', display), stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
|
ApplicationController.__run_process(initialization_file_path, profile, display, session_state)
|
||||||
|
|
||||||
session_state = SessionState(session_state.id, session_state.network_port_numbers, [process.pid])
|
|
||||||
SessionStateController.update_or_create(session_state)
|
|
||||||
|
|
||||||
os.waitpid(process.pid, 0)
|
|
||||||
|
|
||||||
from core.controllers.ProfileController import ProfileController
|
|
||||||
ProfileController.disable(profile, False, profile_observer=profile_observer)
|
ProfileController.disable(profile, False, profile_observer=profile_observer)
|
||||||
|
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
else:
|
||||||
|
|
||||||
|
ApplicationController.__run_process(initialization_file_path, profile, display, session_state)
|
||||||
|
ProfileController.disable(profile, False, profile_observer=profile_observer)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _sync(proxies: Optional[dict] = None):
|
def _sync(proxies: Optional[dict] = None):
|
||||||
|
|
||||||
|
@ -105,3 +107,13 @@ class ApplicationController:
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return ':170'
|
return ':170'
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __run_process(initialization_file_path, profile, display, session_state):
|
||||||
|
|
||||||
|
process = subprocess.Popen(('xinit', initialization_file_path, '--', '/usr/bin/Xephyr', '-ac', '-title', f'Simplified Privacy - {profile.name or "Unnamed Profile"}', '-screen', profile.resolution, '-no-host-grab', display), stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
|
session_state = SessionState(session_state.id, session_state.network_port_numbers, [process.pid])
|
||||||
|
SessionStateController.update_or_create(session_state)
|
||||||
|
|
||||||
|
process.wait()
|
||||||
|
|
|
@ -42,7 +42,7 @@ class ProfileController:
|
||||||
profile_observer.notify('updated', profile)
|
profile_observer.notify('updated', profile)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def enable(profile: Union[SessionProfile, SystemProfile], force: bool = False, pristine: bool = False, profile_observer: ProfileObserver = None, application_version_observer: ApplicationVersionObserver = None, connection_observer: ConnectionObserver = None):
|
def enable(profile: Union[SessionProfile, SystemProfile], force: bool = False, pristine: bool = False, asynchronous: bool = True, profile_observer: ProfileObserver = None, application_version_observer: ApplicationVersionObserver = None, connection_observer: ConnectionObserver = None):
|
||||||
|
|
||||||
from core.controllers.ConnectionController import ConnectionController
|
from core.controllers.ConnectionController import ConnectionController
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ class ProfileController:
|
||||||
if profile_observer is not None:
|
if profile_observer is not None:
|
||||||
profile_observer.notify('enabled', profile)
|
profile_observer.notify('enabled', profile)
|
||||||
|
|
||||||
ApplicationController.launch(application_version, profile, port_number, profile_observer=profile_observer)
|
ApplicationController.launch(application_version, profile, port_number, asynchronous=asynchronous, profile_observer=profile_observer)
|
||||||
|
|
||||||
if profile.is_system_profile():
|
if profile.is_system_profile():
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue