fix: database created at userData path, not bundled in release

This commit is contained in:
2026-07-16 05:30:03 +08:00
parent 41f8842c1d
commit 0532963aca
2 changed files with 3 additions and 6 deletions
+3 -2
View File
@@ -1,4 +1,4 @@
import { BrowserWindow, ipcMain, dialog as dialogBox } from 'electron' import { BrowserWindow, ipcMain, dialog as dialogBox, app } from 'electron'
import { captureScreen, closeScreenshot, getCapturedImage, getCapturedBase64, clearCapturedImage, startScreenshot } from './screenshot' import { captureScreen, closeScreenshot, getCapturedImage, getCapturedBase64, clearCapturedImage, startScreenshot } from './screenshot'
import { getMainWindow, openDialogWindow } from './window' import { getMainWindow, openDialogWindow } from './window'
import * as fs from 'fs' import * as fs from 'fs'
@@ -33,7 +33,8 @@ let db: any = null
function getDb() { function getDb() {
if (!db) { if (!db) {
const Database = require('better-sqlite3') const Database = require('better-sqlite3')
db = new Database('grading.db') const dbPath = require('path').join(app.getPath('userData'), 'grading.db')
db = new Database(dbPath)
db.prepare(`CREATE TABLE IF NOT EXISTS history ( db.prepare(`CREATE TABLE IF NOT EXISTS history (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
question_id INTEGER, question_id INTEGER,
-4
View File
@@ -27,12 +27,8 @@
"files": [ "files": [
"dist/**/*", "dist/**/*",
"dist-electron/**/*", "dist-electron/**/*",
"database/**/*",
"package.json" "package.json"
], ],
"extraResources": [
{ "from": "database/", "to": "database/" }
],
"win": { "win": {
"target": [ "target": [
{ {