mirror of
https://github.com/SECTL/SecScore.git
synced 2026-07-19 19:04:23 +08:00
e83f17af56
feat(theme): 增强侧边栏选中项样式配置 style: 优化主题变量和样式覆盖逻辑 chore: 清理未使用的依赖和配置文件
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { Service } from '../../shared/kernel'
|
|
import { MainContext } from '../context'
|
|
import { DataBackupRepository } from '../db/backup/DataBackupRepository'
|
|
|
|
declare module '../../shared/kernel' {
|
|
interface Context {
|
|
data: DataService
|
|
}
|
|
}
|
|
|
|
export class DataService extends Service {
|
|
constructor(ctx: MainContext) {
|
|
super(ctx, 'data')
|
|
this.registerIpc()
|
|
}
|
|
|
|
private get mainCtx() {
|
|
return this.ctx as MainContext
|
|
}
|
|
|
|
private registerIpc() {
|
|
this.mainCtx.handle('data:exportJson', async (event) => {
|
|
if (!this.mainCtx.permissions.requirePermission(event, 'admin'))
|
|
return { success: false, message: 'Permission denied' }
|
|
|
|
const backup = new DataBackupRepository(this.mainCtx.db.dataSource)
|
|
return {
|
|
success: true,
|
|
data: await backup.exportJson()
|
|
}
|
|
})
|
|
|
|
this.mainCtx.handle('data:importJson', async (event, jsonText: string) => {
|
|
if (!this.mainCtx.permissions.requirePermission(event, 'admin'))
|
|
return { success: false, message: 'Permission denied' }
|
|
|
|
const backup = new DataBackupRepository(this.mainCtx.db.dataSource)
|
|
const result = await backup.importJson(jsonText)
|
|
if (!result.success) return result
|
|
|
|
await this.mainCtx.settings.reloadFromDb()
|
|
return { success: true }
|
|
})
|
|
}
|
|
}
|