Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

add custom user scripts for webapps defined in webapp-properties.json #140

Merged
merged 2 commits into from
Feb 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions src/app/webcontainer/webapp-container.qml
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,43 @@ BrowserWindow {
focus: true

onLoaded: {
var context = item.currentWebview.context
onlineAccountsController.setupWebcontextForAccount(context)
item.currentWebview.settings.localContentCanAccessRemoteUrls = localContentCanAccessRemoteUrls
var context = item.currentWebview.context;
onlineAccountsController.setupWebcontextForAccount(context);
item.currentWebview.settings.localContentCanAccessRemoteUrls = localContentCanAccessRemoteUrls;

loadCustomUserScripts();
}

function loadCustomUserScripts() {

var scripts = [];

// app specific user scripts
var idx = webappModel.getWebappIndex(getWebappName());
var customScripts = webappModel.data(idx, UnityWebApps.UnityWebappsAppModel.Scripts);

if (customScripts.length === 0)
{
return;
}

var i;
for (i = 0; i < customScripts.length; i++)
{
var script = Qt.createQmlObject('import QtWebEngine 1.7; WebEngineScript {}', webappViewLoader);
script.sourceUrl = customScripts[i];
script.injectionPoint = WebEngineScript.DocumentCreation;
script.worldId = WebEngineScript.MainWorld;
script.runOnSubframes = true;
scripts.push(script);
}

// global user scripts
for (i = 0; i < item.currentWebview.profile.userScripts.length; i++) {
scripts.push(item.currentWebview.profile.userScripts[i]);
}

item.currentWebview.profile.userScripts = scripts;
}
}

Expand Down