diff --git a/package.json b/package.json index 93662af..aeb5729 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "start": "vite --host 0.0.0.0", "build": "tsc && vite build", "deploy": "sudo cp -r dist/* /var/www/html/", - "prettify": "prettier --config ./.prettierrc --write \"src/**/*{.ts,.html.scss}\"" + "prettify": "prettier --config ./.prettierrc --write \"src/**/*{.ts,.html,.css,.js}\"" }, "keywords": [], "author": "", diff --git a/src/components/header/header.html b/src/components/header/header.html index d9bc330..68f7596 100644 --- a/src/components/header/header.html +++ b/src/components/header/header.html @@ -1,28 +1,31 @@ - \ No newline at end of file + diff --git a/src/components/modal/confirmation-modal.html b/src/components/modal/confirmation-modal.html index 9356b8b..6c0f6c4 100644 --- a/src/components/modal/confirmation-modal.html +++ b/src/components/modal/confirmation-modal.html @@ -1,16 +1,16 @@ - + diff --git a/src/html/login-modal.html b/src/html/login-modal.html index a83dca2..d402de9 100644 --- a/src/html/login-modal.html +++ b/src/html/login-modal.html @@ -1,16 +1,14 @@ - \ No newline at end of file + diff --git a/src/html/login-modal.js b/src/html/login-modal.js index c47c7c2..d9c49d7 100644 --- a/src/html/login-modal.js +++ b/src/html/login-modal.js @@ -1,13 +1,13 @@ -import Routing from "/src/services/routing.service.ts"; - -const router = await Routing.getInstance(); -export async function confirmLogin() { - router.confirmLogin() -} - -export async function closeLoginModal() { - router.closeLoginModal() -} - -window.confirmLogin = confirmLogin; -window.closeLoginModal = closeLoginModal; \ No newline at end of file +import Routing from '/src/services/routing.service.ts'; + +const router = await Routing.getInstance(); +export async function confirmLogin() { + router.confirmLogin(); +} + +export async function closeLoginModal() { + router.closeLoginModal(); +} + +window.confirmLogin = confirmLogin; +window.closeLoginModal = closeLoginModal; diff --git a/src/pages/home/home.html b/src/pages/home/home.html index a89fbf3..84676b6 100644 --- a/src/pages/home/home.html +++ b/src/pages/home/home.html @@ -1,52 +1,37 @@ - -
-

Create Account / New Session

-
- -
-
-
Scan QR Code
-
Scan other device
-
-
- -
-
-
- Scan with your other device : -
-
-
- QR Code -
- -
-
-
-
-
- Scan your other device : -
-
- QR Code -
-
-
-
-
-

Or

- -
- -
- - - - -
- +
+

Create Account / New Session

+
+ +
+
+
Scan QR Code
+
Scan other device
+
+
+ +
+
+
Scan with your other device :
+
+
+ QR Code +
+ +
+
+
+
+
Scan your other device :
+
+ QR Code +
+
+
+
+
+

Or

+ +
+ +
+
diff --git a/src/pages/process-element/process-element.html b/src/pages/process-element/process-element.html index d4589ea..013cf4f 100644 --- a/src/pages/process-element/process-element.html +++ b/src/pages/process-element/process-element.html @@ -1,8 +1,5 @@ - -
-

Process {{processTitle}}

-
- -
-
- +
+

Process {{processTitle}}

+
+ +
diff --git a/src/pages/process/process.html b/src/pages/process/process.html index f57062c..691901e 100644 --- a/src/pages/process/process.html +++ b/src/pages/process/process.html @@ -1,22 +1,19 @@ - -
-

Process Selection

-
- -
-
-
-
- - -
-
-
-
-
-
- OK -
-
- +
+

Process Selection

+
+ +
+
+
+
+ + +
+
+
+
+
+ OK +
+
+
diff --git a/src/scanner.js b/src/scanner.js index fe4d1c2..ff048c0 100644 --- a/src/scanner.js +++ b/src/scanner.js @@ -1,16 +1,13 @@ -function onScanSuccess(decodedText, decodedResult) { - // handle the scanned code as you like, for example: - console.log(`Code matched = ${decodedText}`, decodedResult); - } - - function onScanFailure(error) { - // handle scan failure, usually better to ignore and keep scanning. - // for example: - console.warn(`Code scan error = ${error}`); - } - - let html5QrcodeScanner = new Html5QrcodeScanner( - "reader", - { fps: 10, qrbox: {width: 250, height: 250} }, - /* verbose= */ false); - html5QrcodeScanner.render(onScanSuccess, onScanFailure); \ No newline at end of file +function onScanSuccess(decodedText, decodedResult) { + // handle the scanned code as you like, for example: + console.log(`Code matched = ${decodedText}`, decodedResult); +} + +function onScanFailure(error) { + // handle scan failure, usually better to ignore and keep scanning. + // for example: + console.warn(`Code scan error = ${error}`); +} + +let html5QrcodeScanner = new Html5QrcodeScanner('reader', { fps: 10, qrbox: { width: 250, height: 250 } }, /* verbose= */ false); +html5QrcodeScanner.render(onScanSuccess, onScanFailure); diff --git a/src/service-workers/database.worker.js b/src/service-workers/database.worker.js index b956440..fa75692 100644 --- a/src/service-workers/database.worker.js +++ b/src/service-workers/database.worker.js @@ -1,58 +1,60 @@ -import Database from '../services/database.service'; - -self.addEventListener('install', (event) => { - event.waitUntil(self.skipWaiting()); // Activate worker immediately -}); - -self.addEventListener('activate', (event) => { - event.waitUntil(self.clients.claim()); // Become available to all pages -}); - -// Event listener for messages from clients -self.addEventListener('message', async (event) => { - const data = event.data; - const db = await Database.getInstance(); - - if (data.type === 'ADD_OBJECT') { - try { - const { storeName, object, key } = data.payload; - const db = await openDatabase(); - const tx = db.transaction(storeName, 'readwrite'); - const store = tx.objectStore(storeName); - console.log("🚀 ~ self.addEventListener ~ store:", store, storeName, key, object) - await store.put(object); - event.ports[0].postMessage({ status: 'success', message: 'Object added or replaced successfully' }); - } catch(error) { - event.ports[0].postMessage({ status: 'error', message: error.message }); - } - } - - if (data.type === 'GET_OBJECT') { - const { storeName, key } = data.payload; - const db = await openDatabase(); - const tx = db.transaction(storeName, 'readonly'); - const store = tx.objectStore(storeName); - const result = await store.get(key); - - event.ports[0].postMessage({ type: 'GET_OBJECT_RESULT', payload: result }); - } - -}); - -async function openDatabase() { - return new Promise((resolve, reject) => { - const request = indexedDB.open('4nk', 1); - request.onerror = (event) => { - reject(request.error); - }; - request.onsuccess = (event) => { - resolve(request.result); - }; - request.onupgradeneeded = (event) => { - const db = event.target.result; - if (!db.objectStoreNames.contains('wallet')) { - db.createObjectStore('wallet', { keyPath: 'pre_id' }); - } - }; - }); -} \ No newline at end of file +import Database from '../services/database.service'; + +self.addEventListener('install', (event) => { + event.waitUntil(self.skipWaiting()); // Activate worker immediately +}); + +self.addEventListener('activate', (event) => { + event.waitUntil(self.clients.claim()); // Become available to all pages +}); + +// Event listener for messages from clients +self.addEventListener('message', async (event) => { + const data = event.data; + const db = await Database.getInstance(); + + if (data.type === 'ADD_OBJECT') { + try { + const { storeName, object, key } = data.payload; + const db = await openDatabase(); + const tx = db.transaction(storeName, 'readwrite'); + const store = tx.objectStore(storeName); + await store.put(object); + event.ports[0].postMessage({ status: 'success', message: 'Object added or replaced successfully' }); + } catch (error) { + event.ports[0].postMessage({ status: 'error', message: error.message }); + } + } + + if (data.type === 'GET_OBJECT') { + const { storeName, key } = data.payload; + const db = await openDatabase(); + const tx = db.transaction(storeName, 'readonly'); + const store = tx.objectStore(storeName); + const result = await new Promise((resolve, reject) => { + const getRequest = store.get(key); + getRequest.onsuccess = (event) => resolve(getRequest.result); + getRequest.onerror = (event) => reject(getRequest.error); + }); + + event.ports[0].postMessage({ type: 'GET_OBJECT_RESULT', payload: result }); + } +}); + +async function openDatabase() { + return new Promise((resolve, reject) => { + const request = indexedDB.open('4nk', 1); + request.onerror = (event) => { + reject(request.error); + }; + request.onsuccess = (event) => { + resolve(request.result); + }; + request.onupgradeneeded = (event) => { + const db = event.target.result; + if (!db.objectStoreNames.contains('wallet')) { + db.createObjectStore('wallet', { keyPath: 'pre_id' }); + } + }; + }); +} diff --git a/src/services/database.service.ts b/src/services/database.service.ts index ad242a3..5749806 100644 --- a/src/services/database.service.ts +++ b/src/services/database.service.ts @@ -15,21 +15,18 @@ class Database { AnkProcess: { name: 'process', options: { keyPath: 'id' }, - indices: [ - { - name: 'by_name', - keyPath: 'name', - options: { - unique: true, - }, - }, - ], + indices: [], }, AnkMessages: { name: 'messages', options: { keyPath: 'id' }, indices: [], }, + AnkProcessData: { + name: 'process-data', + options: { keyPath: 'id' }, + indices: [], + }, }; // Private constructor to prevent direct instantiation from outside @@ -105,6 +102,8 @@ class Database { this.serviceWorkerRegistration = registration; + this.checkForUpdates(); + // Set up the message channels this.messageChannel.port1.onmessage = this.handleAddObjectResponse; this.messageChannelForGet.port1.onmessage = this.handleGetObjectResponse; @@ -115,6 +114,23 @@ class Database { } } } + + private async checkForUpdates() { + if (this.serviceWorkerRegistration) { + // Check for updates to the service worker + try { + await this.serviceWorkerRegistration.update(); + + // If there's a new worker waiting, activate it immediately + if (this.serviceWorkerRegistration.waiting) { + this.serviceWorkerRegistration.waiting.postMessage({ type: 'SKIP_WAITING' }); + } + } catch (error) { + console.error('Error checking for service worker updates:', error); + } + } + } + private handleAddObjectResponse = (event: MessageEvent) => { console.log('Received response from service worker (ADD_OBJECT):', event.data); }; diff --git a/src/services/service.ts b/src/services/service.ts index 4951bbb..edb9d56 100644 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -226,7 +226,7 @@ export default class Services { localStorage.setItem(msg.id.toString(), JSON.stringify(msg)); const db = await Database.getInstance(); db.addObject({ - storeName: 'process', + storeName: 'messages', object: { id: msg.id.toString(), msg }, key: msg.id.toString(), });