Skip to content

Commit

Permalink
rename to the new function name
Browse files Browse the repository at this point in the history
  • Loading branch information
jyyi1 committed Oct 22, 2024
1 parent b033c7b commit 6a0b588
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions client/src/www/app/main.cordova.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
}
Expand Down
25 changes: 25 additions & 0 deletions client/src/www/app/resource_fetcher.cordova.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
return pluginExecWithErrorCode<string>('fetchResource', url);
}
}

0 comments on commit 6a0b588

Please sign in to comment.