feat: Introduce multi-platform architecture for Electron and Web clients with shared UI components, Convex backend for messaging, and integrated search functionality.
Some checks failed
Build and Release / build-and-release (push) Has been cancelled
Some checks failed
Build and Release / build-and-release (push) Has been cancelled
This commit is contained in:
@@ -6,6 +6,10 @@ import crypto from './crypto.js';
|
||||
import session from './session.js';
|
||||
import settings from './settings.js';
|
||||
import idle from './idle.js';
|
||||
import searchStorage from './searchStorage.js';
|
||||
import SearchDatabase from '@discord-clone/shared/src/utils/SearchDatabase';
|
||||
|
||||
const searchDB = new SearchDatabase(searchStorage, crypto);
|
||||
|
||||
const webPlatform = {
|
||||
crypto,
|
||||
@@ -31,10 +35,12 @@ const webPlatform = {
|
||||
},
|
||||
windowControls: null,
|
||||
updates: null,
|
||||
searchDB,
|
||||
features: {
|
||||
hasWindowControls: false,
|
||||
hasScreenCapture: true,
|
||||
hasNativeUpdates: false,
|
||||
hasSearch: true,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
54
packages/platform-web/src/searchStorage.js
Normal file
54
packages/platform-web/src/searchStorage.js
Normal file
@@ -0,0 +1,54 @@
|
||||
const DB_NAME = 'discord-clone-search';
|
||||
const STORE_NAME = 'databases';
|
||||
const DB_VERSION = 1;
|
||||
|
||||
function openIDB() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = indexedDB.open(DB_NAME, DB_VERSION);
|
||||
req.onupgradeneeded = () => {
|
||||
const db = req.result;
|
||||
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
||||
db.createObjectStore(STORE_NAME);
|
||||
}
|
||||
};
|
||||
req.onsuccess = () => resolve(req.result);
|
||||
req.onerror = () => reject(req.error);
|
||||
});
|
||||
}
|
||||
|
||||
const searchStorage = {
|
||||
async load(userId) {
|
||||
const db = await openIDB();
|
||||
return new Promise((resolve, reject) => {
|
||||
const tx = db.transaction(STORE_NAME, 'readonly');
|
||||
const store = tx.objectStore(STORE_NAME);
|
||||
const req = store.get(`search-db-${userId}`);
|
||||
req.onsuccess = () => resolve(req.result || null);
|
||||
req.onerror = () => reject(req.error);
|
||||
});
|
||||
},
|
||||
|
||||
async save(userId, bytes) {
|
||||
const db = await openIDB();
|
||||
return new Promise((resolve, reject) => {
|
||||
const tx = db.transaction(STORE_NAME, 'readwrite');
|
||||
const store = tx.objectStore(STORE_NAME);
|
||||
const req = store.put(bytes, `search-db-${userId}`);
|
||||
req.onsuccess = () => resolve();
|
||||
req.onerror = () => reject(req.error);
|
||||
});
|
||||
},
|
||||
|
||||
async clear(userId) {
|
||||
const db = await openIDB();
|
||||
return new Promise((resolve, reject) => {
|
||||
const tx = db.transaction(STORE_NAME, 'readwrite');
|
||||
const store = tx.objectStore(STORE_NAME);
|
||||
const req = store.delete(`search-db-${userId}`);
|
||||
req.onsuccess = () => resolve();
|
||||
req.onerror = () => reject(req.error);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default searchStorage;
|
||||
Reference in New Issue
Block a user