Bare-bones RS client

This commit is contained in:
Basti 2020-09-08 16:50:01 +02:00
parent 00156c8d70
commit a48d74608f
Signed by untrusted user: basti
GPG Key ID: 9F88009D31D99C72
9 changed files with 178 additions and 4 deletions

View File

@ -0,0 +1,16 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import Storage from 'dashtab/services/storage';
export default class Application extends Controller.extend({
// anything which *must* be merged to prototype here
}) {
@service storage!: Storage;
}
// DO NOT DELETE: this is how TypeScript knows how to look up your controllers.
declare module '@ember/controller' {
interface Registry {
'application': Application;
}
}

13
app/routes/application.ts Normal file
View File

@ -0,0 +1,13 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import Storage from 'dashtab/services/storage';
export default class Application extends Route.extend({
// anything which *must* be merged to prototype here
}) {
@service storage!: Storage;
beforeModel() {
this.storage.initialize();
}
}

55
app/services/storage.ts Normal file
View File

@ -0,0 +1,55 @@
import Service from '@ember/service';
import RemoteStorage from 'remotestoragejs';
import { tracked } from '@glimmer/tracking';
export default class Storage extends Service.extend({
// anything which *must* be merged to prototype here
}) {
remoteStorage: RemoteStorage;
@tracked connecting = true;
@tracked connected = false;
initialize() {
this.remoteStorage = new RemoteStorage();
(<any>window).remoteStorage = this.remoteStorage;
console.log('rs:', this.remoteStorage);
this.remoteStorage.access.claim('myfavoritedrinks', 'rw');
this.remoteStorage.caching.enable('/myfavoritedrinks/');
this.setupEventHandlers();
}
setupEventHandlers () {
this.remoteStorage.on('ready', () => {
console.log('rs ready');
});
this.remoteStorage.on('connected', () => {
this.connecting = false;
this.connected = true;
console.log('rs connected');
});
this.remoteStorage.on('not-connected', () => {
this.connecting = false;
this.connected = false;
console.log('rs not connected');
});
this.remoteStorage.on('disconnected', () => {
this.connected = false;
console.log('rs disconnected');
});
this.remoteStorage.on('connecting', () => {
this.connecting = true;
console.log('rs connecting');
});
this.remoteStorage.on('sync-done', () => {
console.log('rs sync done');
});
}
}
// DO NOT DELETE: this is how TypeScript knows how to look up your services.
declare module '@ember/service' {
interface Registry {
'storage': Storage;
}
}

View File

@ -1 +1,8 @@
<h1>Dashtab</h1>
<p>
RS connecting: {{this.storage.connecting}}<br>
RS connected: {{this.storage.connected}}
</p>
{{outlet}}

51
package-lock.json generated
View File

@ -17283,6 +17283,22 @@
}
}
},
"remotestorage-widget": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/remotestorage-widget/-/remotestorage-widget-1.5.2.tgz",
"integrity": "sha512-zJjk7q8LQuSRe0yzKYOKGPeBmqUPGlerusobfznlzJ+N9FOgS7/yaTcK7bMmZhEeFB0e3wy5615IUfFAEuzsTQ==",
"dev": true
},
"remotestoragejs": {
"version": "github:remotestorage/remotestorage.js#041cc09a4856c9bf939114a391e4bee10bb15fca",
"from": "github:remotestorage/remotestorage.js#dev/type_definitions",
"dev": true,
"requires": {
"tv4": "^1.3.0",
"webfinger.js": "^2.7.0",
"xhr2": "^0.2.0"
}
},
"remove-trailing-separator": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz",
@ -19364,6 +19380,12 @@
"safe-buffer": "^5.0.1"
}
},
"tv4": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/tv4/-/tv4-1.3.0.tgz",
"integrity": "sha1-0CDIRvrdUMhVq7JeuuzGj8EPeWM=",
"dev": true
},
"tweetnacl": {
"version": "0.14.5",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
@ -19411,9 +19433,9 @@
}
},
"typescript": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.2.tgz",
"integrity": "sha512-e4ERvRV2wb+rRZ/IQeb3jm2VxBsirQLpQhdxplZ2MEzGvDkkMmPglecnNDfSUBivMjP93vRbngYYDQqQ/78bcQ==",
"version": "3.7.5",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz",
"integrity": "sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==",
"dev": true
},
"typescript-memoize": {
@ -19972,6 +19994,23 @@
"defaults": "^1.0.3"
}
},
"webfinger.js": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/webfinger.js/-/webfinger.js-2.7.0.tgz",
"integrity": "sha512-l+UtsuV4zrBKyVAj9VCtwWgscTgadCsdGgL1OvbV102cvydWwJCGXlFIXauzWLzfheIDHfPNRWfgMuwyC6ZfIA==",
"dev": true,
"requires": {
"xhr2": "^0.1.4"
},
"dependencies": {
"xhr2": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/xhr2/-/xhr2-0.1.4.tgz",
"integrity": "sha1-f4dliEdxbbUCYyOBL4GMras4el8=",
"dev": true
}
}
},
"webidl-conversions": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz",
@ -20305,6 +20344,12 @@
"integrity": "sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==",
"dev": true
},
"xhr2": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/xhr2/-/xhr2-0.2.0.tgz",
"integrity": "sha512-BDtiD0i2iKPK/S8OAZfpk6tyzEDnKKSjxWHcMBVmh+LuqJ8A32qXTyOx+TVOg2dKvq6zGBq2sgKPkEeRs1qTRA==",
"dev": true
},
"xml-name-validator": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz",

View File

@ -57,7 +57,9 @@
"loader.js": "^4.7.0",
"npm-run-all": "^4.1.5",
"qunit-dom": "^1.4.0",
"typescript": "^4.0.2"
"remotestorage-widget": "^1.5.2",
"remotestoragejs": "github:remotestorage/remotestorage.js#dev/type_definitions",
"typescript": "~3.7.5"
},
"engines": {
"node": "10.* || >= 12"

View File

@ -0,0 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Controller | application', function(hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function(assert) {
let controller = this.owner.lookup('controller:application');
assert.ok(controller);
});
});

View File

@ -0,0 +1,11 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Route | application', function(hooks) {
setupTest(hooks);
test('it exists', function(assert) {
let route = this.owner.lookup('route:application');
assert.ok(route);
});
});

View File

@ -0,0 +1,13 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Service | storage', function(hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function(assert) {
let service = this.owner.lookup('service:storage');
assert.ok(service);
});
});