Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement experimental workaround for Android Server pairing #1256

Merged
merged 17 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions config.xml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading