11import { Zip } from "nativescript-zip" ;
2- import * as appSettings from "tns-core-modules/application-settings" ;
3- import * as fs from "tns-core-modules/file-system" ;
4- import * as fsa from "tns-core-modules/file-system/file-system-access" ;
5- import { isIOS } from "tns-core-modules/platform" ;
6- import * as utils from "tns-core-modules/utils/utils" ;
2+ import { isIOS , ApplicationSettings , knownFolders , File , Folder , Utils } from "@nativescript/core" ;
3+ import { FileSystemAccess } from "@nativescript/core/file-system/file-system-access" ;
74import { AppSync } from "./app-sync" ;
85import { TNSAcquisitionManager } from "./TNSAcquisitionManager" ;
96
@@ -30,15 +27,15 @@ export class TNSLocalPackage implements ILocalPackage {
3027 serverUrl : string ;
3128
3229 install ( installSuccess : Function , errorCallback ?: ErrorCallback , installOptions ?: InstallOptions ) : void {
33- let appFolderPath = fs . knownFolders . documents ( ) . path + "/app" ;
34- let unzipFolderPath = fs . knownFolders . documents ( ) . path + "/AppSync-Unzipped/" + this . packageHash ;
35- let appSyncFolder = fs . knownFolders . documents ( ) . path + "/AppSync" ;
30+ let appFolderPath = knownFolders . documents ( ) . path + "/app" ;
31+ let unzipFolderPath = knownFolders . documents ( ) . path + "/AppSync-Unzipped/" + this . packageHash ;
32+ let appSyncFolder = knownFolders . documents ( ) . path + "/AppSync" ;
3633 // make sure the AppSync folder exists
37- fs . Folder . fromPath ( appSyncFolder ) ;
38- let newPackageFolderPath = fs . knownFolders . documents ( ) . path + "/AppSync/" + this . packageHash ;
34+ Folder . fromPath ( appSyncFolder ) ;
35+ let newPackageFolderPath = knownFolders . documents ( ) . path + "/AppSync/" + this . packageHash ;
3936 // in case of a rollback make 'newPackageFolderPath' could already exist, so check and remove
40- if ( fs . Folder . exists ( newPackageFolderPath ) ) {
41- fs . Folder . fromPath ( newPackageFolderPath ) . removeSync ( ) ;
37+ if ( Folder . exists ( newPackageFolderPath ) ) {
38+ Folder . fromPath ( newPackageFolderPath ) . removeSync ( ) ;
4239 }
4340
4441 const onUnzipComplete = ( success : boolean , error ?: string ) => {
@@ -48,10 +45,10 @@ export class TNSLocalPackage implements ILocalPackage {
4845 return ;
4946 }
5047
51- const previousHash = appSettings . getString ( AppSync . CURRENT_HASH_KEY , null ) ;
52- const isDiffPackage = fs . File . exists ( unzipFolderPath + "/hotappsync.json" ) ;
48+ const previousHash = ApplicationSettings . getString ( AppSync . CURRENT_HASH_KEY , null ) ;
49+ const isDiffPackage = File . exists ( unzipFolderPath + "/hotappsync.json" ) ;
5350 if ( isDiffPackage ) {
54- const copySourceFolder = previousHash === null ? appFolderPath : fs . knownFolders . documents ( ) . path + "/AppSync/" + previousHash ;
51+ const copySourceFolder = previousHash === null ? appFolderPath : knownFolders . documents ( ) . path + "/AppSync/" + previousHash ;
5552 if ( ! TNSLocalPackage . copyFolder ( copySourceFolder , newPackageFolderPath ) ) {
5653 errorCallback && errorCallback ( new Error ( `Failed to copy ${ copySourceFolder } to ${ newPackageFolderPath } ` ) ) ;
5754 return ;
@@ -61,39 +58,39 @@ export class TNSLocalPackage implements ILocalPackage {
6158 return ;
6259 }
6360 } else {
64- new fsa . FileSystemAccess ( ) . rename ( unzipFolderPath , newPackageFolderPath , ( error ) => {
61+ new FileSystemAccess ( ) . rename ( unzipFolderPath , newPackageFolderPath , ( error ) => {
6562 errorCallback && errorCallback ( new Error ( error ) ) ;
6663 return ;
6764 } ) ;
6865 }
6966
7067 if ( ! isIOS ) {
71- let pendingFolderPath = fs . knownFolders . documents ( ) . path + "/AppSync/pending" ;
72- if ( fs . Folder . exists ( pendingFolderPath ) ) {
73- fs . Folder . fromPath ( pendingFolderPath ) . removeSync ( ) ;
68+ let pendingFolderPath = knownFolders . documents ( ) . path + "/AppSync/pending" ;
69+ if ( Folder . exists ( pendingFolderPath ) ) {
70+ Folder . fromPath ( pendingFolderPath ) . removeSync ( ) ;
7471 }
7572 if ( ! TNSLocalPackage . copyFolder ( newPackageFolderPath , pendingFolderPath ) ) {
7673 errorCallback && errorCallback ( new Error ( `Failed to copy ${ newPackageFolderPath } to ${ pendingFolderPath } ` ) ) ;
7774 return ;
7875 }
7976 }
8077
81- appSettings . setString ( TNSLocalPackage . APPSYNC_CURRENT_APPVERSION , this . appVersion ) ;
78+ ApplicationSettings . setString ( TNSLocalPackage . APPSYNC_CURRENT_APPVERSION , this . appVersion ) ;
8279 TNSLocalPackage . saveCurrentPackage ( this ) ;
8380
8481 let buildTime : string ;
8582 // Note that this 'if' hardly justifies subclassing so we're not
8683 if ( isIOS ) {
8784 const plist = NSBundle . mainBundle . pathForResourceOfType ( null , "plist" ) ;
88- const fileDate = new fsa . FileSystemAccess ( ) . getLastModified ( plist ) ;
85+ const fileDate = new FileSystemAccess ( ) . getLastModified ( plist ) ;
8986 buildTime = "" + fileDate . getTime ( ) ;
9087 } else {
91- const appSyncApkBuildTimeStringId = utils . ad . resources . getStringId ( TNSLocalPackage . APPSYNC_APK_BUILD_TIME ) ;
92- buildTime = utils . ad . getApplicationContext ( ) . getResources ( ) . getString ( appSyncApkBuildTimeStringId ) ;
88+ const appSyncApkBuildTimeStringId = Utils . android . resources . getStringId ( TNSLocalPackage . APPSYNC_APK_BUILD_TIME ) ;
89+ buildTime = Utils . android . getApplicationContext ( ) . getResources ( ) . getString ( appSyncApkBuildTimeStringId ) ;
9390 }
94- appSettings . setString ( TNSLocalPackage . APPSYNC_CURRENT_APPBUILDTIME , buildTime ) ;
91+ ApplicationSettings . setString ( TNSLocalPackage . APPSYNC_CURRENT_APPBUILDTIME , buildTime ) ;
9592 //noinspection JSIgnoredPromiseFromCall (removal is async, don't really care if it fails)
96- fs . File . fromPath ( this . localPath ) . remove ( ) ;
93+ File . fromPath ( this . localPath ) . remove ( ) ;
9794
9895 installSuccess ( ) ;
9996 } ;
@@ -121,7 +118,11 @@ export class TNSLocalPackage implements ILocalPackage {
121118 }
122119 ) ;
123120 } else {
124- Zip . unzipWithProgress ( archive , destination , progressCallback ) . then (
121+ Zip . unzip ( {
122+ archive,
123+ directory : destination ,
124+ onProgress : progressCallback
125+ } ) . then (
125126 ( ) => {
126127 completionCallback ( true ) ;
127128 } ,
@@ -138,20 +139,20 @@ export class TNSLocalPackage implements ILocalPackage {
138139 return ;
139140 }
140141
141- appSettings . remove ( TNSLocalPackage . APPSYNC_CURRENT_APPVERSION ) ;
142- appSettings . remove ( TNSLocalPackage . APPSYNC_CURRENT_APPBUILDTIME ) ;
142+ ApplicationSettings . remove ( TNSLocalPackage . APPSYNC_CURRENT_APPVERSION ) ;
143+ ApplicationSettings . remove ( TNSLocalPackage . APPSYNC_CURRENT_APPBUILDTIME ) ;
143144
144- const appSyncFolder = fs . Folder . fromPath ( fs . knownFolders . documents ( ) . path + "/AppSync" ) ;
145+ const appSyncFolder = Folder . fromPath ( knownFolders . documents ( ) . path + "/AppSync" ) ;
145146 //noinspection JSIgnoredPromiseFromCall
146147 appSyncFolder . clear ( ) ;
147148 }
148149
149150 private static saveCurrentPackage ( pack : IPackage ) : void {
150- appSettings . setString ( TNSLocalPackage . APPSYNC_CURRENT_PACKAGE , JSON . stringify ( pack ) ) ;
151+ ApplicationSettings . setString ( TNSLocalPackage . APPSYNC_CURRENT_PACKAGE , JSON . stringify ( pack ) ) ;
151152 }
152153
153154 static getCurrentPackage ( ) : IPackage {
154- const packageStr : string = appSettings . getString ( TNSLocalPackage . APPSYNC_CURRENT_PACKAGE , null ) ;
155+ const packageStr : string = ApplicationSettings . getString ( TNSLocalPackage . APPSYNC_CURRENT_PACKAGE , null ) ;
155156 return packageStr === null ? null : JSON . parse ( packageStr ) ;
156157 }
157158
0 commit comments