Skip to content

Commit

Permalink
Merge pull request #1256 from complexdatacollective/december-23-cordo…
Browse files Browse the repository at this point in the history
…va-fixes

Implement experimental workaround for Android Server pairing
  • Loading branch information
jthrilly committed Jan 11, 2024
2 parents 19c835e + 0864ae1 commit a15d1a6
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 52 deletions.
8 changes: 6 additions & 2 deletions config.xml
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget android-versionCode="6374" id="org.codaco.NetworkCanvasInterviewer6" ios-CFBundleIdentifier="org.codaco.networkCanvasInterviewerBusiness" ios-CFBundleVersion="6374" version="6.5.1" xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget android-versionCode="6415" id="org.codaco.NetworkCanvasInterviewer6" ios-CFBundleIdentifier="org.codaco.networkCanvasInterviewerBusiness" ios-CFBundleVersion="6415" version="6.5.2"
xmlns="http://www.w3.org/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Network Canvas Interviewer</name>
<description>
A tool for conducting Network Canvas Interviews.
Expand All @@ -16,6 +19,7 @@
<hook src="scripts/cordova/after-run.js" type="after_run"/>
<hook src="scripts/cordova/before-prepare.js" type="before_prepare"/>
<platform name="android">
<preference name="scheme" value="http"/>
<allow-intent href="market:*"/>
<allow-navigation href="https://*/*"/>
<uses-permission android:name="android.permission.INTERNET"/>
Expand Down Expand Up @@ -81,4 +85,4 @@
<plugin name="cordova-plugin-network-information" spec="~2.0.2"/>
<plugin name="cordova-plugin-chooser" spec="~1.3.1"/>
<plugin name="cordova-sqlite-storage" spec="6.0.0"/>
</widget>
</widget>
64 changes: 28 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "network-canvas-interviewer",
"version": "6.5.1",
"version": "6.5.2",
"productName": "Network Canvas Interviewer",
"description": "A tool for conducting Network Canvas Interviews.",
"author": "Complex Data Collective",
Expand Down Expand Up @@ -78,8 +78,8 @@
"connected-react-router": "^6.8.0",
"cordova-android": "~12.0.0",
"cordova-ios": "~7.0.0",
"cordova-plugin-file": "github:apache/cordova-plugin-file",
"cordova-plugin-file-transfer": "github:apache/cordova-plugin-file-transfer",
"cordova-plugin-file": "github:apache/cordova-plugin-file#265a932",
"cordova-plugin-file-transfer": "github:apache/cordova-plugin-file-transfer#f12b73e",
"cordova-plugin-fullscreen": "github:mesmotronic/cordova-plugin-fullscreen",
"cordova-plugin-ionic-keyboard": "github:ionic-team/cordova-plugin-ionic-keyboard",
"cordova-plugin-network-canvas-client": "github:complexdatacollective/cordova-plugin-network-canvas-client",
Expand Down Expand Up @@ -176,11 +176,11 @@
"whatwg-fetch": "2.0.3",
"worker-loader": "^2.0.0",
"xml2js": "~0.4.23",
"xmldom": "~0.1.27",
"xss": "^0.3.4"
},
"dependencies": {
"@babel/runtime": "7.10.1",
"@xmldom/xmldom": "~0.8.10",
"archiver": "^4.0.1",
"d3-force": "~3.0.0",
"dmg-builder": "~23.6.0",
Expand Down
2 changes: 1 addition & 1 deletion public/package.json
@@ -1,6 +1,6 @@
{
"name": "network-canvas-interviewer",
"version": "6.5.1",
"version": "6.5.2",
"productName": "Network Canvas Interviewer",
"description": "A tool for conducting Network Canvas Interviews.",
"author": "Complex Data Collective",
Expand Down
Expand Up @@ -23,12 +23,14 @@ const fatalExportErrorAction = withErrorDialog((error) => ({
error,
}));

const getInitialFilename = () => `networkCanvasExport-${Date.now()}`;

const DataExportScreen = ({ show, onClose }) => {
const [step, setStep] = useState(3);
const [selectedSessions, setSelectedSessions] = useState([]);

// Set the default filename to 'networkCanvasExport-<timestamp>'
const [filename, setFilename] = useState(`networkCanvasExport-${Date.now()}`);
const [filename, setFilename] = useState(getInitialFilename());
const [abortHandlers, setAbortHandlers] = useState(null);

const pairedServer = useSelector((state) => state.pairedServer);
Expand All @@ -40,6 +42,7 @@ const DataExportScreen = ({ show, onClose }) => {
const openDialog = (dialog) => dispatch(dialogActions.openDialog(dialog));

const reset = () => {
setFilename(getInitialFilename());
setSelectedSessions([]);
setStep(1);
};
Expand Down
26 changes: 19 additions & 7 deletions src/utils/protocol/downloadProtocol.js
Expand Up @@ -2,7 +2,7 @@
/* global FileTransfer */
import uuid from 'uuid/v4';
import environments from '../environments';
import inEnvironment from '../Environment';
import inEnvironment, { isIOS } from '../Environment';
import { writeFile, tempDataPath } from '../filesystem';
import friendlyErrorMessage from '../../utils/friendlyErrorMessage';
import ApiClient from '../../utils/ApiClient';
Expand Down Expand Up @@ -36,8 +36,8 @@ const downloadProtocol = inEnvironment((environment) => {
if (environment === environments.ELECTRON) {
const request = require('request-promise-native');
const destination = path.join(tempDataPath(), getProtocolName());

return (uri, pairedServer = false) => {

let promisedResponse;
if (pairedServer) {
promisedResponse = new ApiClient(pairedServer).downloadProtocol(uri);
Expand All @@ -56,29 +56,41 @@ const downloadProtocol = inEnvironment((environment) => {
}

if (environment === environments.CORDOVA) {
const destination = `${tempDataPath()}${getProtocolName()}`
return (uri, pairedServer) => {
let promisedResponse;

if (pairedServer) {
// on iOS, the cordova-plugin-network-canvas-client wants the destination
// to be a folder, not a file. It assigns a temp filename itself.
//
// however, on android it needs to be a file.
const destination = isIOS() ? tempDataPath() : `${tempDataPath()}${getProtocolName()}`;

promisedResponse = new ApiClient(pairedServer)
// .addTrustedCert() is not required, assuming we've just fetched the protocol list
.downloadProtocol(uri, destination)
.then(() => destination);
.then((result) => {
// Result is a FileEntry object
return result.nativeURL;
})
} else {
promisedResponse = getURL(uri)
.then(url => url.href)
.catch(urlError)
.then(href => new Promise((resolve, reject) => {
// The filetransfer plugin requires a folder to write to
const destinationWithFolder = `${tempDataPath()}${getProtocolName()}`;

const fileTransfer = new FileTransfer();
console.log('fileTransfer', destination);
fileTransfer.download(
href,
destination,
() => resolve(destination),
destinationWithFolder,
() => resolve(destinationWithFolder),
error => reject(error),
);
}));
}

return promisedResponse
.catch((error) => {
const getErrorMessage = ({ code }) => {
Expand Down

0 comments on commit a15d1a6

Please sign in to comment.