Example #1
0
    def launch(self, app_id, app_uris=[]):
        """Launch an application with upstart.

        This method launches an application via the ``upstart-app-launch``
        library, on platforms that support it.

        Usage is similar to NormalApplicationLauncher::

            from autopilot.application import UpstartApplicationLauncher
            launcher = UpstartApplicationLauncher()
            launcher.setUp()
            app_proxy = launcher.launch('gallery-app')

        :param app_id: name of the application to launch
        :param app_uris: list of separate application uris to launch
        :raises RuntimeError: If the specified application cannot be launched.

        :returns: proxy object for the launched package application

        """
        if isinstance(app_uris, str):
            app_uris = [app_uris]
        if isinstance(app_uris, bytes):
            app_uris = [app_uris.decode()]
        _logger.info(
            "Attempting to launch application '%s' with URIs '%s' via "
            "upstart-app-launch", app_id, ','.join(app_uris))
        state = {}
        state['loop'] = self._get_glib_loop()
        state['expected_app_id'] = app_id
        state['message'] = ''

        UbuntuAppLaunch.observer_add_app_failed(self._on_failed, state)
        UbuntuAppLaunch.observer_add_app_started(self._on_started, state)
        UbuntuAppLaunch.observer_add_app_focus(self._on_started, state)
        GLib.timeout_add_seconds(10.0, self._on_timeout, state)

        self._launch_app(app_id, app_uris)
        state['loop'].run()
        UbuntuAppLaunch.observer_delete_app_failed(self._on_failed)
        UbuntuAppLaunch.observer_delete_app_started(self._on_started)
        UbuntuAppLaunch.observer_delete_app_focus(self._on_started)
        self._maybe_add_application_cleanups(state)
        self._check_status_error(state.get('status', None),
                                 state.get('message', ''))
        pid = self._get_pid_for_launched_app(app_id)

        return self._get_proxy_object(pid)
    def launch(self):
        UAL.observer_add_app_failed(self.on_failed)
        UAL.observer_add_app_started(self.on_started)
        UAL.observer_add_app_focus(self.on_focus)
        UAL.observer_add_app_stop(self.on_stopped)
        UAL.observer_add_app_resume(self.on_resume)

        #start up the application
        UAL.start_application(self.appid)

        try:
            self.loop.run()
        except KeyboardInterrupt:
            pass

        print("Sdk-Launcher> The Application exited, cleaning up")

        UAL.observer_delete_app_failed(self.on_failed)
        UAL.observer_delete_app_started(self.on_started)
        UAL.observer_delete_app_focus(self.on_focus)
        UAL.observer_delete_app_stop(self.on_stopped)
        UAL.observer_delete_app_resume(self.on_resume)

        return self.exitCode