diff --git a/app/controllers/application.ts b/app/controllers/application.ts new file mode 100644 index 0000000..cc0f088 --- /dev/null +++ b/app/controllers/application.ts @@ -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; + } +} diff --git a/app/routes/application.ts b/app/routes/application.ts new file mode 100644 index 0000000..3fc46e9 --- /dev/null +++ b/app/routes/application.ts @@ -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(); + } +} diff --git a/app/services/storage.ts b/app/services/storage.ts new file mode 100644 index 0000000..3afe166 --- /dev/null +++ b/app/services/storage.ts @@ -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(); + (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; + } +} diff --git a/app/templates/application.hbs b/app/templates/application.hbs index e2147ca..aba4375 100644 --- a/app/templates/application.hbs +++ b/app/templates/application.hbs @@ -1 +1,8 @@ +

Dashtab

+ +

+ RS connecting: {{this.storage.connecting}}
+ RS connected: {{this.storage.connected}} +

+ {{outlet}} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 0ab198d..c35cf5b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 47b6126..51a9464 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/tests/unit/controllers/application-test.ts b/tests/unit/controllers/application-test.ts new file mode 100644 index 0000000..93d19ce --- /dev/null +++ b/tests/unit/controllers/application-test.ts @@ -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); + }); +}); diff --git a/tests/unit/routes/application-test.ts b/tests/unit/routes/application-test.ts new file mode 100644 index 0000000..21e9fb3 --- /dev/null +++ b/tests/unit/routes/application-test.ts @@ -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); + }); +}); diff --git a/tests/unit/services/storage-test.ts b/tests/unit/services/storage-test.ts new file mode 100644 index 0000000..3ebda79 --- /dev/null +++ b/tests/unit/services/storage-test.ts @@ -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); + }); +}); +