This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
go_to_native_app.jsx
107 lines (97 loc) · 3.74 KB
/
go_to_native_app.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import {FormattedMessage} from 'react-intl';
import safeOpenProtocol from 'custom-protocol-detection';
import MattermostLogoSvg from 'images/logo.svg';
export default class GoNativeApp extends PureComponent {
constructor(props) {
super(props);
this.state = {
protocolUnsupported: false,
browserUnsupported: false,
};
}
render() {
const {protocolUnsupported, browserUnsupported} = this.state;
let nativeLocation = window.location.href.replace('/vault#', '');
nativeLocation = nativeLocation.replace(/^(http|https)/, 'mattermost');
//***** TESTING PURPOSE - REMOVE BEFORE MERGE ****
nativeLocation = nativeLocation.replace(/\/\/[^/]+/, '//pre-release.mattermost.com');
safeOpenProtocol(nativeLocation,
() => this.setState({protocolUnsupported: true}),
() => setTimeout(redirectWeb, 3000),
() => this.setState({browserUnsupported: true})
);
let goNativeAppMessage = null;
if (protocolUnsupported) {
goNativeAppMessage = (
<FormattedMessage
id='get_app.protocolUnsupported'
defaultMessage='Unable to open Mattermost.'
/>
);
} else if (browserUnsupported) {
goNativeAppMessage = (
<FormattedMessage
id='get_app.browserUnsupported'
defaultMessage='This browser does not support opening applications.'
/>
);
} else {
goNativeAppMessage = (
<FormattedMessage
id='get_app.systemDialogMessage'
defaultMessage='Please click `Open Mattermost` if you see the system dialog.'
/>
);
}
// prompt user to download in case they don't have the mobile app.
return (
<div className='get-app get-app--android'>
<img
src={MattermostLogoSvg}
className='get-app__logo'
/>
<div className='get-app__launching'>
<FormattedMessage
id='get_app.launching'
defaultMessage='Launching...'
/>
</div>
<div className='get-app__status'>
{goNativeAppMessage}
</div>
<div>
<div className='get-app__alternative'>
<FormattedMessage
id='get_app.ifNothingPrompts'
defaultMessage='If nothing prompts from browser,'
/>
</div>
<a
href='/downloads'
className='btn btn-primary get-app__download'
>
<FormattedMessage
id='get_app.downloadMattermost'
defaultMessage='Download & run Mattermost'
/>
</a>
</div>
<a
href='/'
className='btn btn-secondary get-app__continue'
>
<FormattedMessage
id='get_app.continueToBrowser'
defaultMessage='Continue to web site'
/>
</a>
</div>
);
}
}
function redirectWeb() {
window.location = window.location.href.replace('/vault#', '');
}