From 0125bae4e5e832ac61391674f1683406a2c1ae17 Mon Sep 17 00:00:00 2001 From: chopster44 Date: Sat, 15 Nov 2025 18:59:01 +0000 Subject: [PATCH] (1.0.10) attempt add bluetooth --- dist/index.cjs.js | 56 +++++++++++++++++++++++++++++++++++++++++++++-- dist/index.d.ts | 11 +++++++++- dist/index.es.js | 56 +++++++++++++++++++++++++++++++++++++++++++++-- package.json | 2 +- 4 files changed, 119 insertions(+), 6 deletions(-) diff --git a/dist/index.cjs.js b/dist/index.cjs.js index bde5d44..75986b6 100644 --- a/dist/index.cjs.js +++ b/dist/index.cjs.js @@ -2,13 +2,24 @@ var parseXml = require('@rgrove/parse-xml'); +/// class Updater { archiveURL; feedType; - constructor(archiveURL = "/", feedType = "atom") { + bleObject; + bleDeviceId; + _updaterServiceUUID = "71a4438e-fd52-4b15-b3d2-ec0e3e56193b"; + _updaterVersionCharactersiticUUID = "1978a3df-c009-4837-b295-57ef429dde8c"; + constructor(archiveURL = "/", feedType = "atom", bleObject) { this.archiveURL = archiveURL; this.feedType = feedType; + if (bleObject) { + this.bleObject = bleObject; + } } + /* + FEEDS + */ async getRawArchive() { const res = await fetch(`http://cors.emaker.limited/?url=${this.archiveURL}.${this.feedType}`, { // "mode": "cors" @@ -79,7 +90,7 @@ class Updater { if (elm.type == "element") { const element = elm; if (element.name == "item") { - output.push(this.atomGetVersionDetails(element)); + output.push(this.rssGetVersionDetails(element)); } } }); @@ -93,6 +104,47 @@ class Updater { return this.rssGetArchive(); } } + /* + BLUETOOTH + */ + setDeviceId(id) { + this.bleDeviceId = id; + } + bytesToString(buffer) { + return String.fromCharCode.apply(null, new Uint8Array(buffer)); + } + async readVersionNumber() { + return new Promise((resolve, reject) => { + this.bleObject.read(this.bleDeviceId, this._updaterServiceUUID, this._updaterVersionCharactersiticUUID, (rawData) => { + resolve(this.bytesToString(rawData)); + }, (error) => { + reject(`Error: ${error}`); + }); + }); + } + async getLatestVersion() { + let feed = await this.getArchive(); + let newestDate = feed[0].date; + let i = 0; + feed.forEach((item, index) => { + if (item.date > newestDate) { + newestDate = item.date; + i = index; + } + }); + return feed[i].title; + } + async checkForUpdate() { + // read device value + const deviceVersion = await this.readVersionNumber(); + // compare with latest version + const latestVersion = await this.getLatestVersion(); + if (deviceVersion != latestVersion) { + return true; + } + // update + return false; + } } module.exports = Updater; diff --git a/dist/index.d.ts b/dist/index.d.ts index f054354..ea2f66d 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -7,11 +7,20 @@ export type versionNotes = { export default class Updater { archiveURL: string; feedType: string; - constructor(archiveURL?: string, feedType?: string); + bleObject: BLECentralPlugin.BLECentralPluginStatic; + protected bleDeviceId: string; + private readonly _updaterServiceUUID; + private readonly _updaterVersionCharactersiticUUID; + constructor(archiveURL?: string, feedType?: string, bleObject?: BLECentralPlugin.BLECentralPluginStatic); private getRawArchive; private atomGetVersionDetails; private atomGetArchive; private rssGetVersionDetails; private rssGetArchive; getArchive(): Promise; + setDeviceId(id: string): void; + private bytesToString; + private readVersionNumber; + private getLatestVersion; + checkForUpdate(): Promise; } diff --git a/dist/index.es.js b/dist/index.es.js index 4884f21..31645a1 100644 --- a/dist/index.es.js +++ b/dist/index.es.js @@ -1,12 +1,23 @@ import { parseXml } from '@rgrove/parse-xml'; +/// class Updater { archiveURL; feedType; - constructor(archiveURL = "/", feedType = "atom") { + bleObject; + bleDeviceId; + _updaterServiceUUID = "71a4438e-fd52-4b15-b3d2-ec0e3e56193b"; + _updaterVersionCharactersiticUUID = "1978a3df-c009-4837-b295-57ef429dde8c"; + constructor(archiveURL = "/", feedType = "atom", bleObject) { this.archiveURL = archiveURL; this.feedType = feedType; + if (bleObject) { + this.bleObject = bleObject; + } } + /* + FEEDS + */ async getRawArchive() { const res = await fetch(`http://cors.emaker.limited/?url=${this.archiveURL}.${this.feedType}`, { // "mode": "cors" @@ -77,7 +88,7 @@ class Updater { if (elm.type == "element") { const element = elm; if (element.name == "item") { - output.push(this.atomGetVersionDetails(element)); + output.push(this.rssGetVersionDetails(element)); } } }); @@ -91,6 +102,47 @@ class Updater { return this.rssGetArchive(); } } + /* + BLUETOOTH + */ + setDeviceId(id) { + this.bleDeviceId = id; + } + bytesToString(buffer) { + return String.fromCharCode.apply(null, new Uint8Array(buffer)); + } + async readVersionNumber() { + return new Promise((resolve, reject) => { + this.bleObject.read(this.bleDeviceId, this._updaterServiceUUID, this._updaterVersionCharactersiticUUID, (rawData) => { + resolve(this.bytesToString(rawData)); + }, (error) => { + reject(`Error: ${error}`); + }); + }); + } + async getLatestVersion() { + let feed = await this.getArchive(); + let newestDate = feed[0].date; + let i = 0; + feed.forEach((item, index) => { + if (item.date > newestDate) { + newestDate = item.date; + i = index; + } + }); + return feed[i].title; + } + async checkForUpdate() { + // read device value + const deviceVersion = await this.readVersionNumber(); + // compare with latest version + const latestVersion = await this.getLatestVersion(); + if (deviceVersion != latestVersion) { + return true; + } + // update + return false; + } } export { Updater as default }; diff --git a/package.json b/package.json index 0bac6fe..a37a3f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "updaterweblibrary", - "version": "1.0.9", + "version": "1.0.10", "description": "OTA Updater App frontend library", "repository": { "type": "git",