@@ -432,22 +432,85 @@ module openflow {
432432 setTimeout ( this . scanForQRScanner . bind ( this ) , 200 ) ;
433433
434434 console . log ( "get mobiledomain" ) ;
435- var storage = window . localStorage ;
436- var value = storage . getItem ( "mobiledomain" ) ; // Pass a key name to get its value.
435+ var value = await this . readfile ( "mobiledomain.txt" ) ;
437436 console . log ( value ) ;
438- if ( value == "aiotdev-frontend.openrpa.dk" || value == "slagelse.access-iot.com" || value == "slagelsedev.access-iot.com" ) {
439- storage . removeItem ( "mobiledomain" ) ;
440- value = null ;
441- }
442437 if ( value !== null && value !== undefined && value !== "" ) {
443438 if ( value !== window . location . hostname ) {
444439 window . location . replace ( "https://" + value ) ;
445440 return ;
446441 }
447442 }
443+ // console.log("get mobiledomain");
444+ // var storage = window.localStorage;
445+ // var value = storage.getItem("mobiledomain"); // Pass a key name to get its value.
446+ // console.log(value);
447+ // if (value == "aiotdev-frontend.openrpa.dk" || value == "slagelse.access-iot.com" || value == "slagelsedev.access-iot.com") {
448+ // storage.removeItem("mobiledomain");
449+ // value = null;
450+ // }
451+ // if (value !== null && value !== undefined && value !== "") {
452+ // if (value !== window.location.hostname) {
453+ // window.location.replace("https://" + value);
454+ // return;
455+ // }
456+ // }
448457
449458 } ) ;
450459 }
460+ readfile ( filename : string ) {
461+ return new Promise < string > ( async ( resolve , reject ) => {
462+ var win : any = window ;
463+ //var type = win.TEMPORARY;
464+ var type = win . PERSISTENT ;
465+ var size = 5 * 1024 * 1024 ;
466+ win . requestFileSystem ( type , size , successCallback , errorCallback )
467+ function successCallback ( fs ) {
468+ fs . root . getFile ( filename , { } , function ( fileEntry ) {
469+
470+ fileEntry . file ( function ( file ) {
471+ var reader = new FileReader ( ) ;
472+ reader . onloadend = function ( e ) {
473+ resolve ( this . result as string ) ;
474+ } ;
475+ reader . readAsText ( file ) ;
476+ } , errorCallback ) ;
477+ } , errorCallback ) ;
478+ }
479+ function errorCallback ( error ) {
480+ console . log ( error ) ;
481+ resolve ( ) ;
482+ }
483+ } ) ;
484+ }
485+ writefile ( filename : string , content : string ) {
486+ return new Promise < string > ( async ( resolve , reject ) => {
487+ var win : any = window ;
488+ //var type = win.TEMPORARY;
489+ var type = win . PERSISTENT ;
490+ var size = 5 * 1024 * 1024 ;
491+ win . requestFileSystem ( type , size , successCallback , errorCallback )
492+ function successCallback ( fs ) {
493+ fs . root . getFile ( filename , { create : true } , function ( fileEntry ) {
494+ fileEntry . createWriter ( function ( fileWriter ) {
495+ fileWriter . onwriteend = function ( e ) {
496+ console . log ( 'Write completed.' ) ;
497+ resolve ( ) ;
498+ } ;
499+ fileWriter . onerror = function ( e ) {
500+ console . error ( 'Write failed: ' + e . toString ( ) ) ;
501+ resolve ( ) ;
502+ } ;
503+ var blob = new Blob ( [ content ] , { type : 'text/plain' } ) ;
504+ fileWriter . write ( blob ) ;
505+ } , errorCallback ) ;
506+ } , errorCallback ) ;
507+ }
508+ function errorCallback ( error ) {
509+ console . error ( error ) ;
510+ resolve ( ) ;
511+ }
512+ } ) ;
513+ }
451514 scanForQRScanner ( ) {
452515 try {
453516 if ( QRScanner !== undefined ) {
@@ -481,7 +544,7 @@ module openflow {
481544 console . error ( error ) ;
482545 }
483546 }
484- QRScannerHit ( err , contents ) {
547+ async QRScannerHit ( err , contents ) {
485548 try {
486549 console . log ( "QRScannerHit" ) ;
487550 if ( err ) {
@@ -493,11 +556,13 @@ module openflow {
493556 QRScanner . hide ( ) ;
494557 QRScanner . destroy ( ) ;
495558
496- var storage = window . localStorage ;
497- var value = storage . getItem ( "mobiledomain" ) ; // Pass a key name to get its value.
498- storage . setItem ( "mobiledomain" , contents ) // Pass a key name and its value to add or update that key.
499- // storage.removeItem(key) // Pass a key name to remove that key from storage.
500559 console . log ( "set mobiledomain to " + contents ) ;
560+ await this . writefile ( "mobiledomain.txt" , contents ) ;
561+
562+ // var storage = window.localStorage;
563+ // var value = storage.getItem("mobiledomain"); // Pass a key name to get its value.
564+ // storage.setItem("mobiledomain", contents) // Pass a key name and its value to add or update that key.
565+ // // storage.removeItem(key) // Pass a key name to remove that key from storage.
501566
502567 window . location . replace ( "https://" + contents ) ;
503568
0 commit comments