From 6a0b58801beed3b7d7c774f10d7a6b051e72a10c Mon Sep 17 00:00:00 2001 From: jyyi1 Date: Tue, 22 Oct 2024 18:44:41 -0400 Subject: [PATCH] rename to the new function name --- .../java/org/outline/OutlinePlugin.java | 16 ++++++------ client/src/www/app/main.cordova.ts | 4 +++ .../src/www/app/resource_fetcher.cordova.ts | 25 +++++++++++++++++++ 3 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 client/src/www/app/resource_fetcher.cordova.ts diff --git a/client/src/cordova/plugin/android/java/org/outline/OutlinePlugin.java b/client/src/cordova/plugin/android/java/org/outline/OutlinePlugin.java index c185e00d87..bd10f0a6c7 100644 --- a/client/src/cordova/plugin/android/java/org/outline/OutlinePlugin.java +++ b/client/src/cordova/plugin/android/java/org/outline/OutlinePlugin.java @@ -43,7 +43,7 @@ import org.outline.vpn.VpnServiceStarter; import org.outline.vpn.VpnTunnelService; import outline.Outline; -import outline.FetchDynamicKeyResult; +import outline.FetchResourceResult; import platerrors.Platerrors; import platerrors.PlatformError; @@ -59,7 +59,7 @@ public enum Action { STOP("stop"), ON_STATUS_CHANGE("onStatusChange"), IS_RUNNING("isRunning"), - FETCH_CONFIG("fetchConfig"), + FETCH_RESOURCE("fetchResource"), INIT_ERROR_REPORTING("initializeErrorReporting"), REPORT_EVENTS("reportEvents"), QUIT("quitApplication"); @@ -205,16 +205,16 @@ private void executeAsync( final String tunnelId = args.getString(0); boolean isActive = isTunnelActive(tunnelId); callback.sendPluginResult(new PluginResult(PluginResult.Status.OK, isActive)); - } else if (Action.FETCH_CONFIG.is(action)) { + } else if (Action.FETCH_RESOURCE.is(action)) { final String url = args.getString(0); - LOG.fine(String.format(Locale.ROOT, "Fetching dynamic config at %s ...", url)); - final FetchDynamicKeyResult result = Outline.fetchDynamicKey(url); + LOG.fine(String.format(Locale.ROOT, "Fetching resource at %s ...", url)); + final FetchResourceResult result = Outline.fetchResource(url); if (result.getError() != null) { - LOG.warning(String.format(Locale.ROOT, "Fetch dynamic config failed: %s", result.getError())); + LOG.warning(String.format(Locale.ROOT, "Fetch resource failed: %s", result.getError())); sendActionResult(callback, result.getError()); } else { - LOG.info(String.format(Locale.ROOT, "Fetch dynamic config result: %s", result.getKey())); - callback.success(result.getKey()); + LOG.info(String.format(Locale.ROOT, "Fetch resource result: %s", result.getContent())); + callback.success(result.getContent()); } // Static actions diff --git a/client/src/www/app/main.cordova.ts b/client/src/www/app/main.cordova.ts index ab6d07cfdf..77061813b3 100644 --- a/client/src/www/app/main.cordova.ts +++ b/client/src/www/app/main.cordova.ts @@ -32,6 +32,7 @@ import {CordovaVpnApi} from './outline_server_repository/vpn.cordova'; import {OutlinePlatform} from './platform'; import {OUTLINE_PLUGIN_NAME, pluginExec} from './plugin.cordova'; import {BrowserResourceFetcher, ResourceFetcher} from './resource_fetcher'; +import {CordovaResourceFetcher} from './resource_fetcher.cordova'; import {AbstractUpdater} from './updater'; import * as interceptors from './url_interceptor'; import {NoOpVpnInstaller, VpnInstaller} from './vpn_installer'; @@ -117,6 +118,9 @@ class CordovaPlatform implements OutlinePlatform { } getResourceFetcher(): ResourceFetcher { + if (cordova.platformId === 'android') { + return new CordovaResourceFetcher(); + } // TODO: move to Go fetch implementation later return new BrowserResourceFetcher(); } diff --git a/client/src/www/app/resource_fetcher.cordova.ts b/client/src/www/app/resource_fetcher.cordova.ts new file mode 100644 index 0000000000..1fbea930cd --- /dev/null +++ b/client/src/www/app/resource_fetcher.cordova.ts @@ -0,0 +1,25 @@ +// Copyright 2024 The Outline Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import {pluginExecWithErrorCode} from './plugin.cordova'; +import {ResourceFetcher} from './resource_fetcher'; + +/** + * Fetches resources using Cordova plugin. + */ +export class CordovaResourceFetcher implements ResourceFetcher { + fetch(url: string): Promise { + return pluginExecWithErrorCode('fetchResource', url); + } +}