summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
Diffstat (limited to 'service/pixelated')
-rw-r--r--service/pixelated/application.py31
-rw-r--r--service/pixelated/assets/Interstitial.html6
-rw-r--r--service/pixelated/resources/loading_page.py49
-rw-r--r--service/pixelated/resources/root_resource.py24
4 files changed, 40 insertions, 70 deletions
diff --git a/service/pixelated/application.py b/service/pixelated/application.py
index dfeb8d82..082f45ee 100644
--- a/service/pixelated/application.py
+++ b/service/pixelated/application.py
@@ -25,7 +25,6 @@ from pixelated.config.services import Services
from pixelated.config.leap import initialize_leap
from pixelated.config import logger
from pixelated.config.site import PixelatedSite
-from pixelated.resources.loading_page import LoadingResource
from pixelated.resources.root_resource import RootResource
from leap.common.events import (
@@ -35,26 +34,18 @@ from leap.common.events import (
@defer.inlineCallbacks
-def start_user_agent(loading_app, host, port, sslkey, sslcert, leap_home, leap_session):
- yield loading_app.stopListening()
+def start_user_agent(root_resource, leap_home, leap_session):
services = Services(leap_home, leap_session)
yield services.setup(leap_home, leap_session)
- resource = RootResource()
-
- resource.initialize(
+ root_resource.initialize(
services.keymanager,
services.search_engine,
services.mail_service,
services.draft_service,
services.feedback_service)
- if sslkey and sslcert:
- reactor.listenSSL(port, PixelatedSite(resource), _ssl_options(sslkey, sslcert), interface=host)
- else:
- reactor.listenTCP(port, PixelatedSite(resource), interface=host)
-
# soledad needs lots of threads
reactor.threadpool.adjustPoolsize(5, 15)
@@ -77,7 +68,9 @@ def _ssl_options(sslkey, sslcert):
def initialize():
args = arguments.parse_user_agent_args()
logger.init(debug=args.debug)
- loading_app = reactor.listenTCP(args.port, PixelatedSite(LoadingResource()), interface=args.host)
+ resource = RootResource()
+
+ start_site(args, resource)
deferred = initialize_leap(args.leap_provider_cert,
args.leap_provider_cert_fingerprint,
@@ -87,11 +80,7 @@ def initialize():
deferred.addCallback(
lambda leap_session: start_user_agent(
- loading_app,
- args.host,
- args.port,
- args.sslkey,
- args.sslcert,
+ resource,
args.leap_home,
leap_session))
@@ -107,3 +96,11 @@ def initialize():
deferred.addErrback(_quit_on_error)
reactor.run()
+
+
+def start_site(config, resource):
+ if config.sslkey and config.sslcert:
+ reactor.listenSSL(config.port, PixelatedSite(resource), _ssl_options(config.sslkey, config.sslcert),
+ interface=config.host)
+ else:
+ reactor.listenTCP(config.port, PixelatedSite(resource), interface=config.host)
diff --git a/service/pixelated/assets/Interstitial.html b/service/pixelated/assets/Interstitial.html
index e98080be..bc6cc738 100644
--- a/service/pixelated/assets/Interstitial.html
+++ b/service/pixelated/assets/Interstitial.html
@@ -4,15 +4,15 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
- <script src="assets/snap.svg-min.js"></script>
- <script src="assets/jquery-2.1.3.min.js"></script>
+ <script src="startup-assets/snap.svg-min.js"></script>
+ <script src="startup-assets/jquery-2.1.3.min.js"></script>
</head>
<body style="border: 0px; padding: 0px; margin: 0px;background-color: #808181">
<section id="hive-section" style="background-color: #808181;" name="hive-section">
<svg id="hive" style="width: 100%; height: 100%;"></svg>
</section>
- <script src="assets/Interstitial.js"></script>
+ <script src="startup-assets/Interstitial.js"></script>
</body>
</html>
diff --git a/service/pixelated/resources/loading_page.py b/service/pixelated/resources/loading_page.py
deleted file mode 100644
index 84388068..00000000
--- a/service/pixelated/resources/loading_page.py
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# Copyright (c) 2014 ThoughtWorks, Inc.
-#
-# Pixelated is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Pixelated is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
-
-import os
-from twisted.internet.threads import deferToThread
-from twisted.web.resource import Resource
-from twisted.web.server import NOT_DONE_YET
-from twisted.web.static import File
-
-
-class LoadingResource(Resource):
-
- def __init__(self):
- Resource.__init__(self)
- self._path = os.path.dirname(os.path.abspath(__file__))
- self.putChild('assets', File(os.path.join(self._path, '..', 'assets')))
-
- def render_GET(self, request):
-
- def open_html():
- return open(os.path.join(self._path, '..', 'assets', 'Interstitial.html')).read()
-
- def close_request(html):
- request.responseHeaders.addRawHeader("Connection", "close")
- request.write(html)
- request.finish()
-
- d = deferToThread(open_html)
- d.addCallback(close_request)
-
- return NOT_DONE_YET
-
- def getChild(self, path, request):
- if path == '':
- return self
- return Resource.getChild(self, path, request)
diff --git a/service/pixelated/resources/root_resource.py b/service/pixelated/resources/root_resource.py
index 8b536450..e6046eae 100644
--- a/service/pixelated/resources/root_resource.py
+++ b/service/pixelated/resources/root_resource.py
@@ -12,11 +12,21 @@ from twisted.web.resource import Resource
from twisted.web.static import File
+MODE_STARTUP = 1
+MODE_RUNNING = 2
+
+
class RootResource(Resource):
def __init__(self):
Resource.__init__(self)
+ self._startup_assets_folder = self._get_startup_folder()
self._static_folder = self._get_static_folder()
+ self._startup_mode()
+
+ def _startup_mode(self):
+ self.putChild('startup-assets', File(self._startup_assets_folder))
+ self._mode = MODE_STARTUP
def getChild(self, path, request):
if path == '':
@@ -34,6 +44,12 @@ class RootResource(Resource):
self.putChild('mail', MailResource(mail_service))
self.putChild('feedback', FeedbackResource(feedback_service))
+ self._mode = MODE_RUNNING
+
+ def _get_startup_folder(self):
+ path = os.path.dirname(os.path.abspath(__file__))
+ return os.path.join(path, '..', 'assets')
+
def _get_static_folder(self):
static_folder = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "..", "web-ui", "app"))
# this is a workaround for packaging
@@ -44,5 +60,11 @@ class RootResource(Resource):
static_folder = os.path.join('/', 'usr', 'share', 'pixelated-user-agent')
return static_folder
+ def _is_starting(self):
+ return self._mode == MODE_STARTUP
+
def render_GET(self, request):
- return open(os.path.join(self._static_folder, 'index.html')).read()
+ if self._is_starting():
+ return open(os.path.join(self._startup_assets_folder, 'Interstitial.html')).read()
+ else:
+ return open(os.path.join(self._static_folder, 'index.html')).read()