Skip to content

Commit 53d1018

Browse files
committed
update client view when clicking "change client" link
it would just stay what it was before, so it was hard/impossible to switch between web and native.
1 parent 1c520a6 commit 53d1018

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/open/ClientViewModel.js

+27-13
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,21 @@ export class ClientViewModel extends ViewModel {
3535
this._pickClient = pickClient;
3636
// to provide "choose other client" button after calling pick()
3737
this._clientListViewModel = null;
38+
this._update();
39+
}
3840

39-
const matchingPlatforms = getMatchingPlatforms(client, this.platforms);
40-
const nativePlatform = matchingPlatforms.find(p => !isWebPlatform(p));
41+
_update() {
42+
const matchingPlatforms = getMatchingPlatforms(this._client, this.platforms);
4143
const webPlatform = matchingPlatforms.find(p => isWebPlatform(p));
42-
43-
this._proposedPlatform = this.preferences.platform || nativePlatform || webPlatform;
44-
this._nativePlatform = nativePlatform || this._proposedPlatform;
44+
this._nativePlatform = matchingPlatforms.find(p => !isWebPlatform(p));
45+
this._proposedPlatform = this.preferences.platform || this._nativePlatform || webPlatform;
4546

46-
this.actions = this._createActions(client, link, nativePlatform, webPlatform);
47-
this._clientCanIntercept = !!(nativePlatform && client.canInterceptMatrixToLinks(nativePlatform));
47+
this.actions = this._createActions(this._client, this._link, this._nativePlatform, webPlatform);
48+
this._clientCanIntercept = !!(this._nativePlatform && this._client.canInterceptMatrixToLinks(this._nativePlatform));
4849
this._showOpen = this.deepLink && !this._clientCanIntercept;
49-
}
50+
}
5051

52+
// these are only shown in the install stage
5153
_createActions(client, link, nativePlatform, webPlatform) {
5254
let actions = [];
5355
if (nativePlatform) {
@@ -117,7 +119,8 @@ export class ClientViewModel extends ViewModel {
117119
}
118120

119121
get showDeepLinkInInstall() {
120-
return this._clientCanIntercept && this.deepLink;
122+
// we can assume this._nativePlatform as this._clientCanIntercept already checks it
123+
return this._clientCanIntercept && !!this._client.getDeepLink(this._nativePlatform, this._link);
121124
}
122125

123126
get availableOnPlatformNames() {
@@ -142,14 +145,20 @@ export class ClientViewModel extends ViewModel {
142145
return textPlatforms;
143146
}
144147

148+
get _deepLinkPlatform() {
149+
// in install stage, always show the native link in the small "open it here" link, independent of preference.
150+
return this._showOpen ? this._proposedPlatform : this._nativePlatform;
151+
}
152+
153+
// both used for big "Continue" button in open stage,
154+
// and for small "open it here" link in the install stage.
145155
get deepLink() {
146-
const platform = this.showBack ? this._proposedPlatform : this._nativePlatform;
147-
return this._client.getDeepLink(platform, this._link);
156+
return this._client.getDeepLink(this._deepLinkPlatform, this._link);
148157
}
149158

150159
deepLinkActivated() {
151160
this._pickClient(this._client);
152-
this.preferences.setClient(this._client.id, this._proposedPlatform);
161+
this.preferences.setClient(this._client.id, this._deepLinkPlatform);
153162
if (this._showOpen) {
154163
this._showOpen = false;
155164
this.emitChange();
@@ -161,15 +170,20 @@ export class ClientViewModel extends ViewModel {
161170
this.emitChange();
162171
}
163172

173+
// whether or not we are only showing this client (in open or install stage)
164174
get showBack() {
165-
// if we're not only showing this client, don't show back (see pick())
166175
return !!this._clientListViewModel;
167176
}
168177

169178
back() {
170179
if (this._clientListViewModel) {
171180
const vm = this._clientListViewModel;
172181
this._clientListViewModel = null;
182+
// clear the client preference so we default back to to native link if any
183+
// in the list with all clients, and also if we refresh, we get the list with
184+
// all clients rather than having our "change client" click reverted.
185+
this.preferences.setClient(undefined, undefined);
186+
this._update();
173187
this.emitChange();
174188
vm.showAll();
175189
}

0 commit comments

Comments
 (0)