Browse Source

Add a localdb to store localized information, such as uid, etc.

oldj 4 years ago
parent
commit
518c20b1e6
4 changed files with 19 additions and 6 deletions
  1. 4 4
      src/main/actions/checkUpdate.ts
  2. 13 1
      src/main/data/index.ts
  3. 1 0
      src/main/types.d.ts
  4. 1 1
      src/version.json

+ 4 - 4
src/main/actions/checkUpdate.ts

@@ -5,19 +5,19 @@
  */
 
 import { broadcast } from '@main/core/agent'
+import { localdb } from '@main/data'
 import { GET } from '@main/libs/request'
 import { server_url } from '@root/common/constants'
+import events from '@root/common/events'
 import version from '@root/version.json'
 import compareVersions from 'compare-versions'
-import { cfgdb } from '@main/data'
 import { v4 as uuid4 } from 'uuid'
-import events from '@root/common/events'
 
 const getUniqueId = async (): Promise<string> => {
-  let uid: string = await cfgdb.dict.local.get('uid', '')
+  let uid: string = await localdb.dict.local.get('uid', '')
   if (!uid) {
     uid = uuid4()
-    await cfgdb.dict.local.set('uid', uid)
+    await localdb.dict.local.set('uid', uid)
   }
   return uid
 }

+ 13 - 1
src/main/data/index.ts

@@ -5,11 +5,13 @@
  */
 
 import getDataFolder from '@main/libs/getDataFolder'
-import PotDb from 'potdb'
+import { app } from 'electron'
 import * as path from 'path'
+import PotDb from 'potdb'
 
 let swhdb: PotDb
 let cfgdb: PotDb
+let localdb: PotDb
 
 if (!global.swhdb) {
   let db_dir: string = path.join(getDataFolder(), 'data')
@@ -29,7 +31,17 @@ if (!global.cfgdb) {
   cfgdb = global.cfgdb
 }
 
+if (!global.localdb) {
+  let db_dir: string = path.join(app.getPath('userData'), 'swh_local')
+  localdb = new PotDb(db_dir)
+  console.log(`local db: ${localdb.dir}`)
+  global.localdb = localdb
+} else {
+  localdb = global.localdb
+}
+
 export {
   swhdb,
   cfgdb,
+  localdb,
 }

+ 1 - 0
src/main/types.d.ts

@@ -27,6 +27,7 @@ declare global {
       db_dir?: string;
       swhdb: SwhDb;
       cfgdb: SwhDb;
+      localdb: SwhDb;
       ua: string; // user agent
       session_id: string; // A random value, refreshed every time the app starts, used to identify different startup sessions.
       main_win: BrowserWindow;

+ 1 - 1
src/version.json

@@ -1 +1 @@
-[4, 0, 2, 6057]
+[4, 0, 3, 6057]