Skip to content

Commit d5bd778

Browse files
committed
Work-around for connectivity issues
1 parent e070f7f commit d5bd778

4 files changed

Lines changed: 38 additions & 44 deletions

File tree

.sandstorm/sandstorm-pkgdef.capnp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const pkgdef :Spk.PackageDefinition = (
1919

2020
appTitle = (defaultText = "TextEditor"),
2121

22-
appVersion = 2, # Increment this for every release.
22+
appVersion = 4, # Increment this for every release.
2323

24-
appMarketingVersion = (defaultText = "0.0.3"),
24+
appMarketingVersion = (defaultText = "0.0.4"),
2525
# Human-readable representation of appVersion. Should match the way you
2626
# identify versions of your app in documentation and marketing.
2727

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.0.4
2+
* There are issues with localStorage within the Sandstorm iframe. This affects
3+
reconnecting to a document. A work-around is in place.
4+
15
# 0.0.3
26
* Add document settings drawer with themes and css editor
37
* Switch to Polymer for UI

index.html

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,5 @@
1010
</head>
1111

1212
<body class="fullbleed layout vertical">
13-
<!-- <x-main /> -->
14-
<script>
15-
console.log(window.localStorage);
16-
if (window.localStorage.getItem('foo') === null) {
17-
window.localStorage.setItem('foo', 'this value was stored in localStorage');
18-
document.write('No value found in localStorage. Calling set.');
19-
} else {
20-
document.write(window.localStorage.getItem('foo'));
21-
}
22-
</script>
13+
<x-main />
2314
</body>

public/components/x-main.html

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@
9696
<script>
9797
Polymer({
9898
is: 'x-main',
99-
10099
hasPermission: false,
101100
connectedStatus: false,
102101
cssVals: {},
@@ -214,41 +213,37 @@
214213
* page.
215214
*/
216215
initUserSession: function () {
217-
this.userId = window.localStorage.getItem("userId");
218216
this.uuid = window.localStorage.getItem("uuid");
219-
console.log(this.userId);
220217
console.log(this.uuid);
221218

222-
var handleUserReady = function () {
223-
this.updateUserHeaderPermissions(function () {
224-
this.updatePermission();
225-
}.bind(this));
226-
}.bind(this);
227-
228-
// Create user
229-
if ( ! this.userId || ! this.uuid) {
219+
// Get or create user
220+
if ( ! this.uuid) {
230221
this.uuid = Meteor.uuid();
231222
Meteor.call("createUser", {
232-
username: this.uuid,
233-
password: this.uuid,
234-
login: true
235-
}, function (error, result) {
236-
console.log(result);
237-
if (error) {
238-
console.log(error);
239-
}
240-
this.userId = result.id;
241-
window.localStorage.setItem("userId", this.userId);
242-
window.localStorage.setItem("uuid", this.uuid);
243-
handleUserReady()
244-
}.bind(this)
245-
);
246-
} else {
247-
Meteor.loginWithPassword(this.uuid, this.uuid, function () {
248-
handleUserReady()
223+
username: this.uuid,
224+
password: this.uuid,
225+
login: true
226+
}, function (error, result) {
227+
if (error) {
228+
console.log(error);
229+
}
230+
window.localStorage.setItem("uuid", this.uuid);
231+
// There's an issue where `login: true` isn't doing the trick
232+
// When running in Sandstorm iframe, so we force a login.
233+
if ( ! Meteor.userId()) {
234+
Meteor.loginWithPassword(this.uuid, this.uuid)
235+
}
249236
}.bind(this));
237+
} else {
238+
Meteor.loginWithPassword(this.uuid, this.uuid)
250239
}
251240

241+
var self = this;
242+
Tracker.autorun(function () {
243+
var userId = Meteor.userId();
244+
self.handleUserReady();
245+
});
246+
252247
Tracker.autorun(function () {
253248
if (Meteor.status().connected) {
254249
console.log("connected");
@@ -257,8 +252,14 @@
257252
console.log("disconnected");
258253
console.log(Meteor.userId());
259254
}
260-
}.bind(this));
255+
});
256+
},
261257

258+
handleUserReady: function () {
259+
console.log('handleUserReady');
260+
this.updateUserHeaderPermissions(function () {
261+
this.updatePermission();
262+
}.bind(this));
262263
},
263264

264265
/**
@@ -274,14 +275,12 @@
274275
* Makes a call to server to update this.hasPermission
275276
*/
276277
updatePermission: function () {
277-
Meteor.call("checkUserPermissions", this.userId, ["owner", "modify"], function (error, result) {
278+
Meteor.call("checkUserPermissions", Meteor.userId(), ["owner", "modify"], function (error, result) {
278279
this.hasPermission = result;
279280
}.bind(this));
280281
},
281282

282283
/*********************************************************************/
283-
284-
285284
});
286285

287286
</script>

0 commit comments

Comments
 (0)