Skip to content

Commit c627757

Browse files
NativeScript CodePush 2.0, baby!
1 parent 0c74014 commit c627757

File tree

96 files changed

+333
-320
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+333
-320
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*.log
77

88
src/*.d.ts
9-
!src/install-hooks.js
9+
!src/*install-hooks.js
1010
!src/scripts/**/*.js
1111
!src/index.d.ts
1212
!src/references.d.ts

README.md

Lines changed: 73 additions & 21 deletions

demo/app/app.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

demo/app/main-page.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

demo/app/main-view-model.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

demo/app/tests/tests.js

Lines changed: 0 additions & 56 deletions
This file was deleted.
File renamed without changes.

demo/demoapp/app.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as application from "tns-core-modules/application";
2+
3+
application.run({moduleName: "main-page"});

demo/demoapp/main-page.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as observable from "tns-core-modules/data/observable";
2+
import * as pages from "tns-core-modules/ui/page";
3+
import { HelloWorldModel } from "./main-view-model";
4+
5+
// Event handler for Page 'loaded' event attached in main-page.xml
6+
export function pageLoaded(args: observable.EventData) {
7+
// Get the event sender
8+
const page = <pages.Page>args.object;
9+
page.bindingContext = new HelloWorldModel();
10+
}

demo/app/main-page.xml renamed to demo/demoapp/main-page.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<StackLayout class="p-20">
33

44
<!-- you can toggle these labels when building/releasing -->
5-
<Label text="I'm the AppStore version" class="t-20 text-center c-orange" textWrap="true"/>
6-
<!--<Label text="I'm CodePush Staging v1" class="t-20 text-center c-blue" textWrap="true"/>-->
5+
<!-- <Label text="I'm CODEPUSH version v5" class="t-20 text-center c-orange" textWrap="true"/>-->
6+
<Label text="I'm the APPSTORE version" class="t-20 text-center c-orange" textWrap="true"/>
77

88
<Label text="{{ message }}" class="t-20 m-30 text-center c-black" textWrap="true"/>
99
</StackLayout>

demo/demoapp/main-view-model.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { CodePush, InstallMode, SyncStatus } from "nativescript-code-push";
2+
import * as application from "tns-core-modules/application";
3+
import { Observable } from "tns-core-modules/data/observable";
4+
import { isIOS } from "tns-core-modules/platform";
5+
6+
export class HelloWorldModel extends Observable {
7+
private codePush: CodePush;
8+
9+
private static CODEPUSH_IOS_STAGING_KEY = "YTmVMy0GLCknVu3GVIynTxmfwxJN4ksvOXqog";
10+
private static CODEPUSH_IOS_PRODUCTION_KEY = "r1DVaLfKjc0Y5d6BzqX45SFVss6a4ksvOXqog";
11+
12+
private static CODEPUSH_ANDROID_STAGING_KEY = "0HwIQn0nkoRPEX93uv1dqmbWwvvJ4ksvOXqog";
13+
private static CODEPUSH_ANDROID_PRODUCTION_KEY = "C0Mf7oZS5BWYNABikJUFXlSF8rjF4ksvOXqog";
14+
15+
public message: string;
16+
17+
constructor() {
18+
super();
19+
this.codePush = new CodePush();
20+
21+
// let's immediately check for updates on the server
22+
this.syncWithCodePushServer();
23+
24+
// and also check for updates whenever the application is resumed
25+
application.on(application.resumeEvent, () => {
26+
this.syncWithCodePushServer();
27+
});
28+
}
29+
30+
private syncWithCodePushServer(): void {
31+
this.set("message", "Querying CodePush..");
32+
let that = this;
33+
34+
CodePush.sync({
35+
deploymentKey: isIOS ? HelloWorldModel.CODEPUSH_IOS_STAGING_KEY : HelloWorldModel.CODEPUSH_ANDROID_STAGING_KEY,
36+
installMode: InstallMode.ON_NEXT_RESTART, // has not effect currently, always using ON_NEXT_RESTART
37+
mandatoryInstallMode: InstallMode.IMMEDIATE // has not effect currently, always using ON_NEXT_RESTART
38+
}, (syncStatus: SyncStatus): void => {
39+
console.log("syncStatus: " + syncStatus);
40+
if (syncStatus === SyncStatus.UP_TO_DATE) {
41+
that.set("message", "CodePush: up to date");
42+
} else if (syncStatus === SyncStatus.UPDATE_INSTALLED) {
43+
that.set("message", "CodePush: update installed, kill/restart your app to see the changes");
44+
}
45+
});
46+
}
47+
}
File renamed without changes.

demo/nsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"appPath": "demoapp",
3+
"appResourcesPath": "appresources"
4+
}

0 commit comments

Comments
 (0)