Skip to content

Commit

Permalink
Use native menu to open settings
Browse files Browse the repository at this point in the history
  • Loading branch information
yajo10 authored and Patrick Hervieux committed Nov 19, 2023
1 parent 08ade73 commit 1578413
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 15 deletions.
1 change: 1 addition & 0 deletions harbour-hydrogen.pro
Expand Up @@ -4,6 +4,7 @@ CONFIG += sailfishapp_qml

DISTFILES += qml/harbour-hydrogen.qml \
qml/HydrogenWebView.qml \
qml/HydrogenWebViewPage.qml \
qml/cover/CoverPage.qml \
qml/framescript.js \
qml/server.py \
Expand Down
47 changes: 34 additions & 13 deletions qml/HydrogenWebView.qml
@@ -1,23 +1,47 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import Sailfish.Silica.private 1.0 as Private
import Sailfish.WebView 1.0
import Sailfish.WebEngine 1.0
import io.thp.pyotherside 1.5

WebViewPage {

WebViewFlickable {
id: webviewFlickable
allowedOrientations: Orientation.All
function runJavaScript(script) {
webView.runJavaScript(script)
}
function enterSettingsView() {
var urlParts = app.hydrogenUrl.toString().split('session')
var settingsURL = urlParts[0] + 'session/'+ urlParts[1].split('/')[1] + '/settings'
app.hydrogenUrl = settingsURL
}

Private.VirtualKeyboardObserver {
id: virtualKeyboardObserver

Component.onCompleted: {
WebEngineSettings.setPreference(
"security.fileuri.strict_origin_policy", false,
WebEngineSettings.BoolPref)
active: webview.enabled
//transpose: window._transpose
//orientation: browserPage.orientation

//onWindowChanged: webview.chromeWindow = window

// Update content height only after virtual keyboard fully opened.
states: State {
name: "boundHeightControl"
when: virtualKeyboardObserver.opened && webview.enabled
PropertyChanges {
target: webview
//TODO: make this work for Landscape mode as well
viewportHeight: Screen.height - virtualKeyboardObserver.imSize
}
}
}
WebView {

webView {
id: webview
url: app.hydrogenUrl
anchors.fill: parent

onViewInitialized: {
console.log("loading framescript")
webview.loadFrameScript(Qt.resolvedUrl("framescript.js"))
Expand All @@ -31,15 +55,12 @@ WebViewPage {
case "webview:log":
console.log("webapp-log: " + JSON.stringify(data))
break
case "embed:linkclicked":
var url = '/^http:\/\/localhost/'
if (!data.uri.match('http://localhost'))
Qt.openUrlExternally(data['uri'])
break
default:
console.log("Message: " + JSON.stringify(
message) + " data: " + JSON.stringify(data))
}
}
}
}


25 changes: 25 additions & 0 deletions qml/HydrogenWebViewPage.qml
@@ -0,0 +1,25 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import Sailfish.WebView 1.0

WebViewPage {
property string url

HydrogenWebView {
id: hydrogenwebview
anchors.fill: parent
urlFromParent: url

PullDownMenu {
MenuItem{
text: qsTr('Settings')
onClicked: hydrogenwebview.enterSettingsView()
}
MenuItem{
text: qsTr('Back')

}
}

}
}
5 changes: 3 additions & 2 deletions qml/harbour-hydrogen.qml
Expand Up @@ -60,7 +60,8 @@ ApplicationWindow {
}
}

initialPage: HydrogenWebView {
id: webview
initialPage:
HydrogenWebViewPage{
id: webviewPage
}
}

0 comments on commit 1578413

Please sign in to comment.