From 90f92722be7b746cd9069b3be9c9d357dd122a1e Mon Sep 17 00:00:00 2001 From: Mark Washeim Date: Tue, 1 Nov 2022 20:07:17 +0100 Subject: [PATCH 1/2] Modified to use modern WebView. --- .gitignore | 1 + qml/pages/LoginPage.qml | 20 ++++++++++++++------ rpm/harbour-tooterb.spec | 4 +++- rpm/harbour-tooterb.yaml | 3 ++- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index e5f8bc2..23ca2a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.user README.md +harbour-tooterb.pro.user diff --git a/qml/pages/LoginPage.qml b/qml/pages/LoginPage.qml index 5227d13..5208f18 100644 --- a/qml/pages/LoginPage.qml +++ b/qml/pages/LoginPage.qml @@ -1,6 +1,8 @@ import QtQuick 2.0 -import QtWebKit 3.0 +// import QtWebKit 3.0 import Sailfish.Silica 1.0 +import Sailfish.WebView 1.0 +import Sailfish.WebEngine 1.0 import "../lib/API.js" as Logic @@ -90,17 +92,23 @@ Page { } } } - - SilicaWebView { + WebView { id: webView + + /* This will probably be required from 4.4 on. */ + Component.onCompleted: { + WebEngineSettings.setPreference("security.disable_cors_checks", true, WebEngineSettings.BoolPref) + WebEngineSettings.setPreference("security.fileuri.strict_origin_policy", false, WebEngineSettings.BoolPref) + } visible: false - opacity: 0 + //opacity: 0 anchors { top: parent.top left: parent.left right: parent.right bottom: parent.bottom } + onLoadingChanged: { console.log(url) if ( @@ -136,7 +144,7 @@ Page { } - switch (loadRequest.status) + /*switch (loadRequest.status) { case WebView.LoadSucceededStatus: opacity = 1 @@ -147,7 +155,7 @@ Page { default: //opacity = 0 break - } + }*/ } FadeAnimation on opacity {} diff --git a/rpm/harbour-tooterb.spec b/rpm/harbour-tooterb.spec index 4b290da..d6c4e9b 100644 --- a/rpm/harbour-tooterb.spec +++ b/rpm/harbour-tooterb.spec @@ -1,6 +1,6 @@ # # Do NOT Edit the Auto-generated Part! -# Generated by: spectacle version 0.27 +# Generated by: spectacle version 0.32 # Name: harbour-tooterb @@ -21,6 +21,8 @@ URL: http://example.org/ Source0: %{name}-%{version}.tar.bz2 Source100: harbour-tooterb.yaml Requires: sailfishsilica-qt5 >= 0.10.9 +Requires: nemo-qml-plugin-configuration-qt5 +Requires: nemo-qml-plugin-notifications-qt5 BuildRequires: pkgconfig(sailfishapp) >= 1.0.2 BuildRequires: pkgconfig(Qt5Core) BuildRequires: pkgconfig(Qt5Qml) diff --git a/rpm/harbour-tooterb.yaml b/rpm/harbour-tooterb.yaml index 927cb80..078cba6 100644 --- a/rpm/harbour-tooterb.yaml +++ b/rpm/harbour-tooterb.yaml @@ -27,7 +27,8 @@ PkgConfigBR: - Qt5Quick - Qt5DBus - Qt5Multimedia - - nemonotifications-qt5 + #- nemonotifications-qt5 nemo-qml-plugin-notifications-qt5 + - nemo-qml-plugin-notifications-qt5-devel - openssl # Build dependencies without a pkgconfig setup can be listed here From f3c987376639505ff59ef31fd3f2128e8239014f Mon Sep 17 00:00:00 2001 From: Mark Washeim Date: Fri, 4 Nov 2022 15:40:35 +0100 Subject: [PATCH 2/2] Add a small web server service to respond to redirect on the login page. --- harbour-tooterb.pro | 2 ++ qml/lib/index.html | 26 ++++++++++++++++++++ qml/lib/server.py | 43 +++++++++++++++++++++++++++++++++ qml/pages/LoginPage.qml | 53 +++++++++++++++++++++++++++++++++++++---- 4 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 qml/lib/index.html create mode 100644 qml/lib/server.py diff --git a/harbour-tooterb.pro b/harbour-tooterb.pro index cf3b679..7401286 100644 --- a/harbour-tooterb.pro +++ b/harbour-tooterb.pro @@ -73,6 +73,8 @@ DISTFILES += qml/harbour-tooterb.qml \ qml/pages/LoginPage.qml \ qml/pages/Browser.qml \ qml/lib/API.js \ + qml/lib/server.py \ + qml/lib/index.html \ qml/images/icon-s-following \ qml/images/icon-s-bookmark \ qml/images/icon-m-emoji.svg \ diff --git a/qml/lib/index.html b/qml/lib/index.html new file mode 100644 index 0000000..1e3f3a1 --- /dev/null +++ b/qml/lib/index.html @@ -0,0 +1,26 @@ + + + + + + + + + +

Login Complete

+ + diff --git a/qml/lib/server.py b/qml/lib/server.py new file mode 100644 index 0000000..716658b --- /dev/null +++ b/qml/lib/server.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- + +# POETASTER +import sys +sys.path.append('/usr/share/harbour-tooterb/qml') +sys.path.append('/usr/share/harbour-tooterb/qml/lib') +sys.path.append('/usr/share/harbour-tooterb/qml/pages') + +# POETASTER + +import pyotherside +import threading +import time +import random +import os +import http.server +import socketserver + +PORT = 8000 +directory = '/usr/share/harbour-tooterb/qml/lib' +Handler = http.server.SimpleHTTPRequestHandler +os.chdir(directory) + +def serveMe(): + with socketserver.TCPServer(("", PORT), Handler) as httpd: + print("serving at port", PORT) + pyotherside.send('finished', PORT) + httpd.serve_forever() + +class Downloader: + def __init__(self): + # Set bgthread to a finished thread so we never + # have to check if it is None. + self.bgthread = threading.Thread() + self.bgthread.start() + + def serve(self): + if self.bgthread.is_alive(): + return + self.bgthread = threading.Thread(target=serveMe) + self.bgthread.start() + +downloader = Downloader() diff --git a/qml/pages/LoginPage.qml b/qml/pages/LoginPage.qml index 5208f18..d71b389 100644 --- a/qml/pages/LoginPage.qml +++ b/qml/pages/LoginPage.qml @@ -1,12 +1,33 @@ import QtQuick 2.0 -// import QtWebKit 3.0 import Sailfish.Silica 1.0 import Sailfish.WebView 1.0 import Sailfish.WebEngine 1.0 +import io.thp.pyotherside 1.5 import "../lib/API.js" as Logic Page { + + // Python connections and signals, callable from QML side + // This is not ideal but keeps the page from erroring out on redirect + Python { + id: py + Component.onCompleted: { + addImportPath(Qt.resolvedUrl('../lib/')); + importModule('server', function () {}); + + setHandler('finished', function(newvalue) { + console.debug(newvalue) + }); + startDownload(); + } + function startDownload() { + call('server.downloader.serve', function() {}); + console.debug("called") + + } + } + id: loginPage // The effective value will be restricted by ApplicationWindow.allowedOrientations allowedOrientations: Orientation.All @@ -41,7 +62,7 @@ Page { EnterKey.onClicked: { Logic.api = Logic.mastodonAPI({ instance: instance.text, api_user_token: "" }); Logic.api.registerApplication("Tooter", - 'http://localhost/harbour-tooter', // redirect uri, we will need this later on + 'http://localhost:8000/index.html', // redirect uri, we will need this later on ["read", "write", "follow"], //scopes "http://grave-design.com/harbour-tooter", //website on the login screen function(data) { @@ -100,6 +121,28 @@ Page { WebEngineSettings.setPreference("security.disable_cors_checks", true, WebEngineSettings.BoolPref) WebEngineSettings.setPreference("security.fileuri.strict_origin_policy", false, WebEngineSettings.BoolPref) } + onViewInitialized: { + //webview.loadFrameScript(Qt.resolvedUrl("../html/framescript.js")); + //webview.addMessageListener("webview:action"); + //webview.runJavaScript("return latlon('" + lat + "','" + lon + "')"); + } + + onRecvAsyncMessage: { + console.log('async changed: ' + url) + console.debug(message) + switch (message) { + case "embed:contentOrientationChanged": + break + case "webview:action": + if ( data.topic != lon ) { + //webview.runJavaScript("return latlon('" + lat + "','" + lon + "')"); + //if (debug) console.debug(data.topic) + //if (debug) console.debug(data.also) + //if (debug) console.debug(data.src) + } + break + } + } visible: false //opacity: 0 anchors { @@ -110,10 +153,10 @@ Page { } onLoadingChanged: { - console.log(url) + console.log('loading changed: ' + url) if ( - (url+"").substr(0, 37) === 'http://localhost/harbour-tooter?code=' || - (url+"").substr(0, 38) === 'https://localhost/harbour-tooter?code=' + (url+"").substr(0, 38) === 'http://localhost:8000/index.html?code=' || + (url+"").substr(0, 39) === 'https://localhost:8000/index.html?code=' ) { visible = false;