Skip to content

Commit

Permalink
feat: allow reset to auto update version + add CI
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Mar 7, 2022
1 parent 5a58eda commit 1b946c1
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 271 deletions.
8 changes: 8 additions & 0 deletions .cz.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "$major.$minor.$patch$prerelease"
version = "1.4.7"
version_files = [
"package.json:version",
".cz.toml"
]
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build source code and send to Capgo

on:
push:
tags:
- '*'

jobs:
deploy:
runs-on: ubuntu-latest
name: "Build code and release"
steps:
- name: Check out
uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install dependencies
id: install_code
run: npm i
- name: Lint
id: lint_code
run: npm run lint
- name: Build
id: build_code
run: npm run build
- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}


23 changes: 23 additions & 0 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Bump version

on:
push:
branches:
- main

jobs:
bump-version:
if: "!startsWith(github.event.head_commit.message, 'bump:')"
runs-on: ubuntu-latest
name: "Bump version and create changelog with commitizen"
steps:
- name: Check out
uses: actions/checkout@v2
with:
fetch-depth: 0
token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'
- name: Create bump and changelog
uses: commitizen-tools/commitizen-action@0.7.0
with:
github_token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'
branch: 'main'
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,26 @@ public void list(PluginCall call) {
call.resolve(ret);
}

private boolean _reset() {
private boolean _reset(Bool toAutoUpdate) {
String version = prefs.getString("LatestVersionAutoUpdate", "");
String versionName = prefs.getString("LatestVersionNameAutoUpdate", "");
if (toAutoUpdate && !version.equals("") && !versionName.equals("")) {
Boolean res = implementation.set(version, versionName);
return res && this._reload();
}
implementation.reset();
String pathHot = implementation.getLastPathHot();
this.bridge.setServerAssetPath(pathHot);
return true;
}

@PluginMethod
public void reset(PluginCall call) {
this._reset();
call.resolve();
Bool toAutoUpdate = call.getBoolean("toAutoUpdate");
if (this._reset(toAutoUpdate)) {
return call.resolve();
}
call.reject("✨ Capacitor-updater: Reset failed");
}

@PluginMethod
Expand Down Expand Up @@ -166,6 +176,13 @@ public void delayUpdate(PluginCall call) {
call.resolve();
}

@PluginMethod
public void cancelDelay(PluginCall call) {
editor.putBoolean("delayUpdate", false);
editor.commit();
call.resolve();
}

@Override
public void onActivityStarted(@NonNull Activity activity) {
Log.i(TAG, "Check for update in the server");
Expand All @@ -182,7 +199,6 @@ public void run() {
new Thread(new Runnable(){
@Override
public void run() {
// Do network action in this function
try {
String dl = implementation.download((String) res.get("url"));
if (dl.equals("")) {
Expand Down Expand Up @@ -233,6 +249,8 @@ public void onActivityStopped(@NonNull Activity activity) {
Boolean res = implementation.set(nextVersion, nextVersionName);
if (res && this._reload()) {
Log.i(TAG, "Auto update to version: " + nextVersionName);
editor.putString("LatestVersionAutoUpdate", nextVersion);
editor.putString("LatestVersionNameAutoUpdate", nextVersionName);
editor.putString("nextVersion", "");
editor.putString("nextVersionName", "");
editor.putString("pastVersion", curVersion);
Expand All @@ -251,6 +269,8 @@ public void onActivityStopped(@NonNull Activity activity) {
Boolean res = implementation.set(pastVersion, pastVersionName);
if (res && this._reload()) {
Log.i(TAG, "Revert to version: " + (pastVersionName.equals("") ? "builtin" : pastVersionName));
editor.putString("LatestVersionAutoUpdate", pastVersion);
editor.putString("LatestVersionNameAutoUpdate", pastVersionName);
editor.putString("pastVersion", "");
editor.putString("pastVersionName", "");
editor.commit();
Expand All @@ -259,6 +279,8 @@ public void onActivityStopped(@NonNull Activity activity) {
}
} else {
if (this._reset()) {
editor.putString("LatestVersionAutoUpdate", "");
editor.putString("LatestVersionNameAutoUpdate", "");
Log.i(TAG, "Auto reset done");
}
}
Expand Down Expand Up @@ -286,30 +308,30 @@ public void onActivityStopped(@NonNull Activity activity) {
editor.putString("pastVersionName", "");
editor.commit();
}

}

// not use but necessary here to remove warnings
@Override
public void onActivityResumed(@NonNull Activity activity) {

super.onActivityResumed();
}

@Override
public void onActivityPaused(@NonNull Activity activity) {

super.onActivityPaused();
}
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {

super.onActivityCreated();
}

@Override
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {

super.onActivitySaveInstanceState();
}

@Override
public void onActivityDestroyed(@NonNull Activity activity) {

super.onActivityDestroyed();
}
}
Loading

0 comments on commit 1b946c1

Please sign in to comment.