Skip to content

Commit 52bbd8c

Browse files
authored
Merge pull request #7272 from vector-im/dbkr/mobileguide
Instructions for installing mobile apps
2 parents 1c5f16c + e23195f commit 52bbd8c

File tree

5 files changed

+491
-32
lines changed

5 files changed

+491
-32
lines changed

src/vector/getconfig.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright 2018 New Vector Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import Promise from 'bluebird';
18+
import request from 'browser-request';
19+
20+
export async function getVectorConfig(relativeLocation) {
21+
if (relativeLocation === undefined) relativeLocation = '';
22+
if (relativeLocation !== '' && !relativeLocation.endsWith('/')) relativeLocation += '/';
23+
try {
24+
const configJson = await getConfig(`${relativeLocation}config.${document.domain}.json`);
25+
// 404s succeed with an empty json config, so check that there are keys
26+
if (Object.keys(configJson).length === 0) {
27+
throw new Error(); // throw to enter the catch
28+
}
29+
return configJson;
30+
} catch (e) {
31+
return await getConfig(relativeLocation + "config.json");
32+
}
33+
}
34+
35+
function getConfig(configJsonFilename) {
36+
let deferred = Promise.defer();
37+
38+
request(
39+
{ method: "GET", url: configJsonFilename },
40+
(err, response, body) => {
41+
if (err || response.status < 200 || response.status >= 300) {
42+
// Lack of a config isn't an error, we should
43+
// just use the defaults.
44+
// Also treat a blank config as no config, assuming
45+
// the status code is 0, because we don't get 404s
46+
// from file: URIs so this is the only way we can
47+
// not fail if the file doesn't exist when loading
48+
// from a file:// URI.
49+
if (response) {
50+
if (response.status == 404 || (response.status == 0 && body == '')) {
51+
deferred.resolve({});
52+
}
53+
}
54+
deferred.reject({err: err, response: response});
55+
return;
56+
}
57+
58+
// We parse the JSON ourselves rather than use the JSON
59+
// parameter, since this throws a parse error on empty
60+
// which breaks if there's no config.json and we're
61+
// loading from the filesystem (see above).
62+
deferred.resolve(JSON.parse(body));
63+
}
64+
);
65+
66+
return deferred.promise;
67+
}

src/vector/index.js

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ import rageshake from "matrix-react-sdk/lib/rageshake/rageshake";
5858

5959
import CallHandler from 'matrix-react-sdk/lib/CallHandler';
6060

61+
import {getVectorConfig} from './getconfig';
62+
6163
let lastLocationHashSet = null;
6264

6365
function initRageshake() {
@@ -238,15 +240,7 @@ async function loadApp() {
238240
let configJson;
239241
let configError;
240242
try {
241-
try {
242-
configJson = await getConfig(`config.${document.domain}.json`);
243-
// 404s succeed with an empty json config, so check that there are keys
244-
if (Object.keys(configJson).length === 0) {
245-
throw new Error(); // throw to enter the catch
246-
}
247-
} catch (e) {
248-
configJson = await getConfig("config.json");
249-
}
243+
configJson = getVectorConfig();
250244
} catch (e) {
251245
configError = e;
252246
}
@@ -260,31 +254,13 @@ async function loadApp() {
260254
const preventRedirect = Boolean(fragparts.params.client_secret);
261255

262256
if (!preventRedirect) {
263-
if (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream) {
264-
// FIXME: ugly status hardcoding
265-
if (SettingsStore.getValue("theme") === 'status') {
266-
window.location = "https://status.im/join-riot.html";
267-
return;
268-
}
269-
else {
270-
if (confirm(_t("Riot is not supported on mobile web. Install the app?"))) {
271-
window.location = "https://itunes.apple.com/us/app/vector.im/id1083446067";
272-
return;
273-
}
274-
}
275-
}
276-
else if (/Android/.test(navigator.userAgent)) {
277-
// FIXME: ugly status hardcoding
278-
if (SettingsStore.getValue("theme") === 'status') {
279-
window.location = "https://status.im/join-riot.html";
257+
const isIos = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
258+
const isAndroid = /Android/.test(navigator.userAgent);
259+
if (isIos || isAndroid) {
260+
if (!document.cookie.split(';').some((c) => c.startsWith('mobile_redirect_to_guide'))) {
261+
window.location = "mobile_guide/";
280262
return;
281263
}
282-
else {
283-
if (confirm(_t("Riot is not supported on mobile web. Install the app?"))) {
284-
window.location = "https://play.google.com/store/apps/details?id=im.vector.alpha";
285-
return;
286-
}
287-
}
288264
}
289265
}
290266

0 commit comments

Comments
 (0)