Skip to content

Commit

Permalink
Ue CapacitorHttp globally
Browse files Browse the repository at this point in the history
  • Loading branch information
6c65726f79 committed Mar 12, 2023
1 parent c5dabe0 commit e2aca9f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions android/app/src/main/assets/capacitor.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
},
"Keyboard": {
"resize": "native"
},
"CapacitorHttp": {
"enabled": true
}
},
"cordova": {}
Expand Down
3 changes: 3 additions & 0 deletions capacitor.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
},
"Keyboard": {
"resize": "native"
},
"CapacitorHttp": {
"enabled": true
}
},
"cordova": {}
Expand Down
3 changes: 3 additions & 0 deletions electron/capacitor.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
},
"Keyboard": {
"resize": "native"
},
"CapacitorHttp": {
"enabled": true
}
},
"cordova": {}
Expand Down
12 changes: 4 additions & 8 deletions src/services/TransmissionRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* Transmission RPC Client for Ionic/Capacitor, inspired by kkito-transmission-rpc
*/

import { CapacitorHttp } from '@capacitor/core';
import { isPlatform } from '@ionic/vue';
import * as _ from 'lodash';

declare const Buffer: any
Expand All @@ -25,15 +23,13 @@ class TRPC {
sessionArguments: any;
options: any;
lastRequestId: number;
useNativePlugin: boolean;
persistentData: any;
persistentDataValid=false;
sessionStats: any;
statsHistory: Array<Array<number|null>>=[];
pathMapping: Record<string,string>;

constructor() {
this.useNativePlugin = (isPlatform("capacitor") && (isPlatform("android") || isPlatform("ios")))
this.lastRequestId = 0;
this.pathMapping = {};
}
Expand Down Expand Up @@ -482,7 +478,7 @@ class TRPC {
ret = await this.electronRequest(options,datas);
}
else {
ret = await this.nativePluginRequest(requestUrl,options,datas);
ret = await this.browserRequest(requestUrl,options,datas);
}

// Don't return result if tags doesn't match or server has been changed
Expand All @@ -498,7 +494,7 @@ class TRPC {
return ret;
}

async nativePluginRequest(requestUrl: string, options: any, datas: Record<string, any>) {
/*async nativePluginRequest(requestUrl: string, options: any, datas: Record<string, any>) {
// HTTP request using CapacitorHttp (allow CORS)
let result: Record<string, any>={};
options.data = datas
Expand All @@ -521,7 +517,7 @@ class TRPC {
});
return result;
}
}*/

async electronRequest(options: any, datas: Record<string, any>) {
// HTTP request using Electron net (allow CORS)
Expand Down Expand Up @@ -551,7 +547,7 @@ class TRPC {
}

async browserRequest(requestUrl: string, options: any, datas: Record<string, any>) {
// HTTP request using fetch (no CORS)
// HTTP request using fetch or CapacitorHttp
let result: Record<string, any>={};
options.body = JSON.stringify(datas);

Expand Down

0 comments on commit e2aca9f

Please sign in to comment.