Skip to content

Commit

Permalink
fix: expose isAutoUpdateEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed May 5, 2022
1 parent b8a3e56 commit b0befb1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,32 @@ public void cancelDelay(final PluginCall call) {
}
}

private Boolean _isAutoUpdateEnabled() {
return !"".equals(CapacitorUpdaterPlugin.this.autoUpdateUrl);
}

@PluginMethod
public void isAutoUpdateEnabled(final PluginCall call) {
final JSObject ret = new JSObject();
ret.put("enabled", this._isAutoUpdateEnabled());
call.resolve(ret);
}

private void checkAppReady() {
try {
if(this.appReadyCheck != null) {
this.appReadyCheck.interrupt();
}
this.appReadyCheck = new Thread(new DeferredNotifyAppReadyCheck());
this.appReadyCheck.start();
} catch (final Exception e) {
Log.e(CapacitorUpdater.TAG, "Failed to start " + DeferredNotifyAppReadyCheck.class.getName(), e);
}
}

@Override
public void onActivityStarted(@NonNull final Activity activity) {
if (CapacitorUpdaterPlugin.this.isAutoUpdateEnabled()) {
if (CapacitorUpdaterPlugin.this._isAutoUpdateEnabled()) {
new Thread(new Runnable(){
@Override
public void run() {
Expand Down Expand Up @@ -528,44 +551,6 @@ public void onActivityStopped(@NonNull final Activity activity) {
}
}

private Boolean isAutoUpdateEnabled() {
return !"".equals(CapacitorUpdaterPlugin.this.autoUpdateUrl);
}

// not use but necessary here to remove warnings
@Override
public void onActivityResumed(@NonNull final Activity activity) {
// TODO: Implement background updating based on `backgroundUpdate` and `backgroundUpdateDelay` capacitor.config.ts settings
}

@Override
public void onActivityPaused(@NonNull final Activity activity) {
// TODO: Implement background updating based on `backgroundUpdate` and `backgroundUpdateDelay` capacitor.config.ts settings
}
@Override
public void onActivityCreated(@NonNull final Activity activity, @Nullable final Bundle savedInstanceState) {
}

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

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

private void checkAppReady() {
try {
if(this.appReadyCheck != null) {
this.appReadyCheck.interrupt();
}
this.appReadyCheck = new Thread(new DeferredNotifyAppReadyCheck());
this.appReadyCheck.start();
} catch (final Exception e) {
Log.e(CapacitorUpdater.TAG, "Failed to start " + DeferredNotifyAppReadyCheck.class.getName(), e);
}
}

private class DeferredNotifyAppReadyCheck implements Runnable {
@Override
public void run() {
Expand Down Expand Up @@ -593,4 +578,26 @@ public void run() {
}
}
}

// not use but necessary here to remove warnings
@Override
public void onActivityResumed(@NonNull final Activity activity) {
// TODO: Implement background updating based on `backgroundUpdate` and `backgroundUpdateDelay` capacitor.config.ts settings
}

@Override
public void onActivityPaused(@NonNull final Activity activity) {
// TODO: Implement background updating based on `backgroundUpdate` and `backgroundUpdateDelay` capacitor.config.ts settings
}
@Override
public void onActivityCreated(@NonNull final Activity activity, @Nullable final Bundle savedInstanceState) {
}

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

@Override
public void onActivityDestroyed(@NonNull final Activity activity) {
}
}
8 changes: 8 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="@capacitor/cli" />
import type { PluginListenerHandle } from '@capacitor/core';

declare module '@capacitor/cli' {
export interface PluginsConfig {
/**
Expand Down Expand Up @@ -141,6 +142,13 @@ export interface CapacitorUpdaterPlugin {
*/
next(options: { version: string, versionName?: string }): Promise<VersionInfo>;

/**
* Get the state of auto update config.
*
* @returns {Promise<{enabled: boolean}>} The status for auto update.
*/
isAutoUpdateEnabled(): Promise<{enabled: boolean}>;

/**
* Set the current bundle version and immediately reloads the app.
*
Expand Down
5 changes: 5 additions & 0 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export class CapacitorUpdaterWeb
console.warn('Cannot set next version in web', options);
return VERSION_BUILTIN;
}

async isAutoUpdateEnabled(): Promise<{ enabled: boolean }> {
console.warn('Cannot get isAutoUpdateEnabled version in web');
return { enabled: false };
}
async set(options: { version: string, versionName?: string }): Promise<void> {
console.warn('Cannot set version in web', options);
return;
Expand Down

0 comments on commit b0befb1

Please sign in to comment.