Skip to content

Commit

Permalink
Merge branch 'fix/1618' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
llaske committed May 12, 2024
2 parents c39d453 + b56e9c3 commit c9cc0f1
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Undismissable palletes in Dollar street #1605
- Localization error in FoodChain #1608
- Alignment issue in Abacus #1607
- Blank screen on iOS when opening a PDF #1618

## [1.8.0] - 2024-04-10
### Added
Expand Down
3 changes: 3 additions & 0 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
<config-file parent="NSPhotoLibraryUsageDescription" target="*-Info.plist">
<string>Library is use to insert images in the Journal.</string>
</config-file>
<config-file parent="ITSAppUsesNonExemptEncryption" target="*-Info.plist">
<false/>
</config-file>
<icon src="res/icon/ios/[email protected]" width="180" height="180" />
<icon src="res/icon/ios/icon-60.png" width="60" height="60" />
<icon src="res/icon/ios/[email protected]" width="120" height="120" />
Expand Down
13 changes: 13 additions & 0 deletions inapp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<!-- iOS dedicated page that displays the contents of a file that was opened using the InAppBrowser plugin. -->
<html>
<head>
<meta charset="utf-8" />
<title>Sugarizer In App Browser</title>
<script data-main="js/inapp" src="lib/require.js"></script>
</head>
<body style="margin:0;">
<iframe style="display:block;width:100vw;height:100vh;max-width:100%;margin:0;padding:0;border:0 none;box-sizing: border-box;" id="frame"
scrolling="yes"></iframe>
</body>
</html>
37 changes: 37 additions & 0 deletions js/inapp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Script use by the inappbrowser on iOS to display the content of a file

function base64toBlob(mimetype, base64) {
var contentType = mimetype;
var byteCharacters = atob(base64.substr(base64.indexOf(';base64,')+8));
var byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += 1024) {
var slice = byteCharacters.slice(offset, offset + 1024);
var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
var blob = new Blob(byteArrays, {type: contentType});
return blob;
}

requirejs.config({
baseUrl: "lib",
paths: {
activity: "../js"
}
});

requirejs(["sugar-web/datastore"], function (datastore) {
var objectId = window.localStorage.getItem("sugar_inappbrowser_objectId");
var dataentry = new datastore.DatastoreObject(objectId);
dataentry.loadAsText(function(err, metadata, text) {
var blob = base64toBlob(metadata.mimetype, text);
var frame = document.getElementById("frame");
frame.height = frame.contentWindow.document.documentElement.scrollHeight + 'px';
frame.src = URL.createObjectURL(blob);
window.localStorage.removeItem("sugar_inappbrowser_objectId");
});
});
2 changes: 1 addition & 1 deletion js/journal.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ enyo.kind({
var that = this;
this.loadEntry(activity, function(err, metadata, text) {
that.$.activityPopup.hidePopup();
util.openAsDocument(metadata, text);
util.openAsDocument(metadata, text, activity.objectId);
return;
});
}
Expand Down
9 changes: 4 additions & 5 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ define(["l10n","sugar-web/datastore","FileSaver"], function (l10n, datastore, Fi
}

// Open the content as a document in a new Window
util.openAsDocument = function(metadata, text) {
util.openAsDocument = function(metadata, text, objectId) {
if (util.getClientType() == constant.webAppType || (util.getClientType() == constant.appType && !enyo.platform.android && !enyo.platform.androidChrome && !enyo.platform.ios && !enyo.platform.electron) || constant.noServerMode) {
// Convert blob object URL
var blob = base64toBlob(metadata.mimetype, text);
Expand Down Expand Up @@ -691,10 +691,9 @@ define(["l10n","sugar-web/datastore","FileSaver"], function (l10n, datastore, Fi
});
});
} else if (enyo.platform.ios) {
// On iOS convert to blob object URL and Open InApp
var blob = base64toBlob(metadata.mimetype, text);
var blobUrl = URL.createObjectURL(blob);
cordova.InAppBrowser.open(blobUrl, '_blank', 'location=no,closebuttoncaption='+l10n.get("Ok"));
// On iOS save in localStorage and display it as blob object in Open InApp window
window.localStorage.setItem("sugar_inappbrowser_objectId", objectId);
cordova.InAppBrowser.open("inapp.html", '_blank', 'location=no,closebuttoncaption='+l10n.get("Ok"));
} else {
// Save in a temporary file
var electron = require("electron");
Expand Down

0 comments on commit c9cc0f1

Please sign in to comment.