filepicker exportFile and popup blocker - filepicker.io

I program a webapp which use ink filepicker for opening/saving text files from/to the cloud. In mobile browsers, when I open a file via :
filepicker.pick({extension: '.txt'},
function(FPFile) {
filepicker.read(FPFile, function(data) {
// Open file
});
});
There is no problem, whether or not the "block popup" option is activated in browser. But when I save file via :
filepicker.store(
mycontent64,
{base64decode: true, mimetype: 'text/plain'},
function(InkBlob) {
filepicker.exportFile(
InkBlob,
{suggestedFilename:"myfile.txt",extension: ".txt"},
function(InkBlob) {
// ******* Save file
},
function(FPError) {
console.log(FPError.toString());
});
},
function(FPError) {
console.log(FPError.toString());
}
);
it only works when the "block popup" option is deactivated in the browser (Safari on iPad or Android stock browser, or google chrome Android...).
If it's activated, browser refuse to open export dialog in a new tab, and with "FPError 131" in console...
I can't tell my users to deactivate this option !
So is there any workaround that do the trick ?
Thank's !

Some workaround would be open filepicker dialog inside filepicker in the same page.
For mobile devices change filepicker.exportFile options:
filepicker.store(
mycontent64,
{base64decode: true, mimetype: 'text/plain'},
function(InkBlob) {
filepicker.exportFile(
InkBlob,
{
suggestedFilename:"myfile.txt",
extension: ".txt"
container: "yourIframeId",
mobile: true
},
function(InkBlob) {
// ******* Save file
},
function(FPError) {
console.log(FPError.toString());
});
},
function(FPError) {
console.log(FPError.toString());
}
);
"yourIframeId" is Id of iFrame tag inside your website.
'mobile: true' will force mobile - responsive version of dialog.
Check docs: https://developers.filepicker.io/docs/web/#export

Related

Unable to register the service worker

My app is under ionic 4 angular.
I've installed the pwa part with :
ng add #angular/pwa --project app
Then I build with : ionic build --prod
and deployed to firebase with : firebase deploy
But I have 2 problems :
1) the banner "add to screen" is not shown when I browse the app from my android phone.
Even with this code on the root url :
showBtn: boolean = false;
deferredPrompt;
constructor(private modalController: ModalController, public authUser: AuthUserService, private router: Router){}
ionViewWillEnter(){
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault();
// Stash the event so it can be triggered later on the button event.
this.deferredPrompt = e;
// Update UI by showing a button to notify the user they can add to home screen
this.showBtn = true;
});
//button click event to show the promt
window.addEventListener('appinstalled', (event) => {
alert('installed');
});
if (window.matchMedia('(display-mode: standalone)').matches) {
alert('display-mode is standalone');
}
}
2) When I launch lighthouse audit I get this warning :
Does not register a service worker that controls page and start_url
I've tried to uninstall, reinstall, rebuild everything but nothing works.
On ionic docs I can't find any clue to fix this problem.
After many days I was able to make it works.
First I add this following snippet to the firebase.json file to the hosting property:
{
"source": "ngsw-worker.js",
"headers": [
{
"key": "Cache-Control",
"value": "no-cache"
}
]
}
Then I add this script in my index.html :
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('ngsw-worker.js')
.then(() => console.log('service worker installed'))
.catch(err => console.error('Error', err));
}
</script>
Now it works !

Can't reload the opened page in a Chrome App

I'm trying to update a page in a Chrome App but I get the error:
Can't open same-window link to "chrome-extension://XXXX/page.html"; try target="_blank".
My manifest.json:
"app": {
"background": {
"scripts": [ "background.js" ]
},
"persistent": false
},
my background.js:
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('page.html', {
'outerBounds': {
'width': 7000,
'height': 7000
}
});
});
and a window.location.reload(); in page.js
P.S.: I considered chrome.runtime.reload();, but it will restart the window/browser, I just wanted to refresh the page without the window closing and opening.
I've created another page "main.html" and I'm loading the "page.html" from that one on an iframe and I'm able to reload it that way,
Just posting my own solution in hope that it might help someone.

File upload in ionic (image or any file)?

can any one please sort it out it gives error FileTransfer is not defined.
Below is my code
controller("ExampleController", function($scope, $cordovaFileTransfer) {
$scope.upload = function() {
var options = {
fileKey: "avatar",
fileName: "yedu.jpg",
chunkedMode: false,
mimeType: "image/jpg"
};
$cordovaFileTransfer.upload("http://192.168.1.109/uploads/upload", "/android_asset/www/img/yedu.jpg", options).then(function(result) {
console.log("SUCCESS: " + JSON.stringify(result.response));
}, function(err) {
console.log("ERROR: " + JSON.stringify(err));
}, function (progress) {
// constant progress updates
});
}
});
I think you getting error in browser . As per the official documentation of plugin this plugin is not supported to browser for more details go to here and here.
If you testing in browser then before installing app in device add the cordovaFileTransfer plugin to your project.
cordova plugin add org.apache.cordova.file-transfer
And for the full implementation of file upload and download with cordova you may go to here.

Google Cloud Print from Web

I wrote a script that prints some test pages from url on Web-site,
and every time I press a print button, a dialog frame for choosing printer appears . But I want to avoid this because my account synchronized with printer.
window.onload = function() {
var gadget = new cloudprint.Gadget();
gadget.setPrintButton(
cloudprint.Gadget.createDefaultPrintButton("print_button_container")); // div id to contain the button
gadget.setPrintDocument("url", "Test Page", "https://www.google.com/landing/cloudprint/testpage.pdf");
}
You could use oath and an html button rather than a gadget to accomplish this. This requires using the google developer console to get oauth permissions.
Then you need to authorize the cloud print service.
The following set of functions are specifically good for use in Google Apps Scripts, but can be adapted. The first thing to do is Log a url link that you can go to in order to Authorize the cloud print service.
function showURL() {
var cpService = getCloudPrintService();
if (!cpService.hasAccess()) {
Logger.log(cpService.getAuthorizationUrl());
}
}
In the following component of this set of functions, make sure to replace the client Id and Secret.
function getCloudPrintService() {
return OAuth2.createService('print')
.setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')
.setTokenUrl('https://accounts.google.com/o/oauth2/token')
.setClientId('**YOUR CLIENT ID FROM GOOGLE DEVELOPER CONSOLE**')
.setClientSecret('**YOUR CLIENT SECRET**')
.setCallbackFunction('authCallback')
.setPropertyStore(PropertiesService.getUserProperties())
.setScope('https://www.googleapis.com/auth/cloudprint')
.setParam('login_hint', Session.getActiveUser().getEmail())
.setParam('access_type', 'offline')
.setParam('approval_prompt', 'force');
}
function authCallback(request) {
var isAuthorized = getCloudPrintService().handleCallback(request);
if (isAuthorized) {
return HtmlService.createHtmlOutput('You can now use Google Cloud Print from Apps Script.');
} else {
return HtmlService.createHtmlOutput('Cloud Print Error: Access Denied');
}
}
Next, get the ID of the Cloud Print Printer that you want to use. This can be obtained in the settings menu of Chrome. Settings --> Show Advanced Settings --> Under Cloud Print " Manage" --> Select the Printer that you want to use "Manage" -->Advanced Details
To initiate cloud print, you need to add the details to a ticket:
var ticket = {
version: "1.0",
print: {
color: {
type: "STANDARD_COLOR",
vendor_id: "Color"
},
duplex: {
type: "LONG_EDGE"
},
copies: {copies: 1},
media_size: {
width_microns: 215900,
height_microns:279400
},
page_orientation: {
type: "PORTRAIT"
},
margins: {
top_microns:0,
bottom_microns:0,
left_microns:0,
right_microns:0
},
page_range: {
interval:
[{start:1,
end:????}]
}
}
};
There are many options that you can add to the ticket. See documentation
Finally, you need to initiate the Cloud Print Service. Here is where you get to define the specific printer that you want.
var payload = {
"printerid" : '**COPY YOUR PRINTER ID HERE**',
"title" : "Prep Print",
"content" : PUT YOUR CONTENT HERE...(e.g. If you do all of this using Google Apps Script...HtmlService.createHtmlOutput(VARIABLE).getAs('application/pdf')),
"contentType": 'text/html',
"ticket" : JSON.stringify(ticket)
};
var response = UrlFetchApp.fetch('https://www.google.com/cloudprint/submit', {
method: "POST",
payload: payload,
headers: {
Authorization: 'Bearer ' + getCloudPrintService().getAccessToken()
},
"muteHttpExceptions": true
});
response = JSON.parse(response);
if (response.success) {
Logger.log("%s", response.message);
} else {
Logger.log("Error Code: %s %s", response.errorCode, response.message);}
var outcome = response.message;
}

Flowplayer Menu plugin issue

I am trying to implement bit rate selection like in flowplayer like in youtube. One option should be 'auto' and others manual. I am using a smil file to load my videos. Flowplayer documentation http://flash.flowplayer.org/plugins/flash/menu.html shows using the menu plugin. I cannot do it using that method since the url path is generated at run time. So I have use smil for menu creation and it works.I just mention the smil file name and the menu plugin loads the bit rates from the smil seamlessly. I am not exactly sure how this works though.
This is the code
clip: {
url:"<?php echo getxml(); ?>",
autoPlay: true,
provider: 'rtmp',
scaling:"fit",
urlResolvers: [ 'smil', 'bwcheck','brselect' ],
onStart: function() {
}
},
plugins: {
smil: {
url: "flowplayer.smil/flowplayer.smil-3.2.8.swf"
},
bwcheck: {
url: "flowplayer.bwcheck/flowplayer.bwcheck-3.2.11.swf",
serverType: 'wowza',
dynamic: true,
dynamicBuffer:true,
netConnectionUrl: 'rtmp://itl.bc-s.cdn.bitgravity.com/cdn',
checkOnStart: true,
rememberBitrate: true,
onStreamSwitchBegin: function(newItem, currentItem) {
$f().getPlugin('content').setHtml("Will switch to: " + newItem.streamName +" from " + currentItem.streamName);
},
onStreamSwitch: function(newItem) {
$f().getPlugin('content').setHtml("Switched to: " + newItem.streamName);
}
},
menu: {
url: "http://releases.flowplayer.org/swf/flowplayer.menu-3.2.12.swf",
items: [
{ label: " Auto", enabled: true, index: 0,toggle:true , selected:true},
],
onSelect: function(item) {
if(item.index == 0){
$f().getPlugin('bwcheck').enableDynamic(true);
$f().getPlugin('content').setHtml("Auto Mode Slected : Best bit rate will be selected according to your bandwidth");
}
else{
$f().getPlugin('bwcheck').enableDynamic(false);
$f().getPlugin('content').setHtml("Manual bit rate selection activated");
}
}
},
brselect: {
url: "http://releases.flowplayer.org/swf/flowplayer.bitrateselect-3.2.13.swf",
menu: true,
},
As you can see from the code I placesd a single item like this
{ label: " Auto", enabled: true, index: 0,toggle:true , selected:true},
By default auto mode is selected and I have to give a tick mark to the menu item 'Auto'. This was also achieved using the parameter 'selected'. But the problem is that the bit rate being played when the file starts playing in the auto mode is also selected and that too gets a tick mark like this.
http://tinypic.com/r/2nkt9fl/6
I need to disable that. The switching is happening and functionality is implemented but the user gets the wrong idea. There is a property by the name 'group' and I guess I will have to make all the items as a part of the group. A combination of the 'group' , 'selected' and 'toggle' property should be able do this but I cannot implement it.