Browse Source

QWebChannel and Web Greeter Bundle merged as one file.

LightDM API should be instantly accessible.
sisyphus
JezerM 3 years ago
parent
commit
06df707434
No known key found for this signature in database
GPG Key ID: 66BBC5D01388C6B5
  1. 10
      web-greeter/browser/browser.py
  2. 12
      web-greeter/resources/js/bootstrap.js

10
web-greeter/browser/browser.py

@ -183,6 +183,9 @@ class NoneLayout(QLayout):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
def count(self) -> int:
return 0
def sizeHint(self) -> QSize: def sizeHint(self) -> QSize:
size = QSize(0, 0) size = QSize(0, 0)
return size return size
@ -319,12 +322,13 @@ class Browser(Application):
if (theme.startswith("/")): path_to_theme = theme if (theme.startswith("/")): path_to_theme = theme
elif (theme.__contains__(".") or theme.__contains__("/")): elif (theme.__contains__(".") or theme.__contains__("/")):
path_to_theme = os.path.join(os.getcwd(), theme) path_to_theme = os.path.join(os.getcwd(), theme)
path_to_theme = os.path.realpath(path_to_theme)
if (not path_to_theme.endswith(".html")): if (not path_to_theme.endswith(".html")):
path_to_theme = os.path.join(path_to_theme, "index.html") path_to_theme = os.path.join(path_to_theme, "index.html")
if (not os.path.exists(path_to_theme)): if (not os.path.exists(path_to_theme)):
print("Path does not exists") print("Path does not exists", path_to_theme)
path_to_theme = os.path.join(dir, def_theme, "index.html") path_to_theme = os.path.join(dir, def_theme, "index.html")
web_greeter_config["config"]["greeter"]["theme"] = path_to_theme web_greeter_config["config"]["greeter"]["theme"] = path_to_theme
@ -357,7 +361,6 @@ class Browser(Application):
def _init_bridge_channel(self) -> None: def _init_bridge_channel(self) -> None:
self.page.setWebChannel(self.channel) self.page.setWebChannel(self.channel)
self.page.scripts().insert(self._get_channel_api_script())
self.bridge_initialized = True self.bridge_initialized = True
def initialize_bridge_objects(self) -> None: def initialize_bridge_objects(self) -> None:
@ -371,6 +374,9 @@ class Browser(Application):
# print("Registered", obj._name) # print("Registered", obj._name)
def load_script(self, path: Url, name: str): def load_script(self, path: Url, name: str):
qt_api = self._get_channel_api_script()
qt_api_source = qt_api.sourceCode()
script = self._create_webengine_script(path, name) script = self._create_webengine_script(path, name)
script.setSourceCode(qt_api_source + "\n" + script.sourceCode())
self.page.scripts().insert(script) self.page.scripts().insert(script)

12
web-greeter/resources/js/bootstrap.js vendored

@ -25,7 +25,6 @@
* along with web-greeter; If not, see <http://www.gnu.org/licenses/>. * along with web-greeter; If not, see <http://www.gnu.org/licenses/>.
*/ */
(() => { (() => {
let _channel; let _channel;
@ -36,7 +35,7 @@
* @type Event * @type Event
* @memberOf window * @memberOf window
*/ */
window._ready_event = new Event( 'GreeterReady' ); window._ready_event = new Event("GreeterReady");
function channel_ready_cb(channel) { function channel_ready_cb(channel) {
_channel = channel; _channel = channel;
@ -64,15 +63,12 @@
* @memberOf window * @memberOf window
*/ */
window.theme_utils = new ThemeUtils(_channel.objects.ThemeUtils); window.theme_utils = new ThemeUtils(_channel.objects.ThemeUtils);
}
new QWebChannel(qt.webChannelTransport, channel_ready_cb);
document.addEventListener("DOMContentLoaded", (event) => {
setTimeout(function () { setTimeout(function () {
window.dispatchEvent(_ready_event); window.dispatchEvent(_ready_event);
}, 2); }, 2);
}
document.addEventListener( 'DOMContentLoaded', ( event ) => {
new QWebChannel( qt.webChannelTransport, channel_ready_cb );
}); });
})(); })();

Loading…
Cancel
Save