Skip to content

Commit

Permalink
fix: 优化
Browse files Browse the repository at this point in the history
  • Loading branch information
badspider7 committed Nov 14, 2024
1 parent 3758874 commit cb8242c
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 13 deletions.
10 changes: 6 additions & 4 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { setupHandle } from '../handle'
import { clearAllTimer, isComputerSleep, startRecord } from '../utils'
import logger from '../logger'
import { initDb } from '../db'
// import { initConfig } from '../utils/config'

const VUEJS3_DEVTOOLS = 'nhdogjmejiglipccpnnnanhbledajbpd'
const require = createRequire(import.meta.url)
Expand Down Expand Up @@ -86,16 +87,16 @@ export async function createWindow() {

win.once('ready-to-show', () => {
win?.show()
win.setMinimumSize(800, 600)
win?.setMinimumSize(800, 600)
})

win.webContents.on('did-finish-load', () => {
win.on('resized', () => {
win?.on('resized', () => {
win?.webContents.send('refresh-chart', '')
})
// 开始统计应用时间
startRecord()
isComputerSleep(win)
isComputerSleep(win!)
})

// Make all links open with the browser, not with the application
Expand All @@ -122,9 +123,10 @@ ipcMain.on('open-url', (e, args) => {
void shell.openExternal(args)
})
app.whenReady().then(async () => {
// initConfig()
initDb()
void createWindow()
setupHandle(win)
setupHandle(win!)
// if (process.env.VITE_DEV_SERVER_URL) {
// installExtension(VUEJS3_DEVTOOLS, { loadExtensionOptions: { allowFileAccess: true } })
// .then(name => logger.debug(`Added Extension: ${name}`))
Expand Down
56 changes: 56 additions & 0 deletions electron/utils/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// import path from 'node:path'
// import fs from 'node:fs'
// import { Conf } from 'electron-conf/main'
// import { app } from 'electron'
// import defaultConfigForAnyPlatform from '../const/defaultConfig'

// const schema = {
// type: 'object',
// properties: {
// version: {
// type: 'number',
// nullable: true,
// },
// common: {
// type: 'object',
// properties: {
// autoLaunch: {
// type: 'boolean',
// default: false,
// },
// keepWindowSize: {
// type: 'boolean',
// default: false,
// },
// lang: {
// type: 'string',
// default: 'zh-CN',
// },
// theme: {
// type: 'string',
// default: 'light',
// },
// },
// },
// actions: {
// type: 'object',
// properties: {},
// },
// data: {
// type: 'object',
// properties: {},
// },
// },
// }

// const configPath = path.join(app.getPath('userData'), 'config.json')
// const cofigObj = fs.readFileSync(configPath, 'utf-8')
// export function initConfig() {
// const conf = new Conf({ schema })

// if (!fs.existsSync(configPath) || conf.store.size === 0 || !conf.has('version')) {
// // 如果文件不存在或conf实例为空,则设置默认配置
// conf.set(defaultConfigForAnyPlatform)
// }
// conf.registerRendererListener()
// }
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"release:win": "vue-tsc --noEmit && vite build && electron-builder --win",
"rebuild": "electron rebuild.js",
"postinstall": "electron-builder install-app-deps",
"typecheck": "vue-tsc --noEmit",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"prepare": "husky",
Expand Down
1 change: 1 addition & 0 deletions src/components/CardGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function formatTime(second: number) {
}
// 当前的累计使用时间
// TODO: 优化 对小于1小时的显示分钟
const currentTotalTime = ref(0)
const currentAppCount = ref(0)
const mostTimeUsageApp = ref<AppData>({} as AppData)
Expand Down
10 changes: 5 additions & 5 deletions src/hooks/useAppDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ export function useAppDetail(TimeList: Array<DailyLogModels | HoursLogModels>) {
return map
}, {})

console.log('appInfo', appInfo)
console.log('appInfoMap===', appInfoMap)
// console.log('appInfo', appInfo)
// console.log('appInfoMap===', appInfoMap)

const appDataList: Array<AppData> = []
TimeList.forEach((item) => {
TimeList.forEach(async (item) => {
let appModel = appInfoMap[item.appModelId]
if (!appModel) {
// 如果当前appModelId不在appInfoMap中,则尝试从appStore中获取
const updatedAppInfo: any = appStore.getAppInfo()
console.log('updatedAppInfo===', updatedAppInfo)
const updatedAppInfo: any = await appStore.getAppInfo()
// console.log('updatedAppInfo===', updatedAppInfo)
// TODO: 这里会出现bug
// 更新appInfoMap
const updatedAppInfoMap = updatedAppInfo.reduce((map: Record<number, AppModel>, app: AppModel) => {
Expand Down
15 changes: 11 additions & 4 deletions src/pages/setting/components/Common.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang='ts'>
import { reactive } from 'vue'
import defaultConfig from '@@/const/defaultConfig'
import type { IConfig } from '@@/const/defaultConfig'
import { Switch } from '@/components/ui/switch'
import {
Select,
Expand All @@ -11,6 +12,10 @@ import {
} from '@/components/ui/select'
const config = reactive(defaultConfig)
async function changeConfig<K extends keyof IConfig['common']>(key: K, value: IConfig['common'][K]) {
config.common[key] = value
}
</script>

<template>
Expand All @@ -26,8 +31,9 @@ const config = reactive(defaultConfig)
</div>
<Select
v-model="config.common.lang"
@update:model-value="changeConfig('lang', config.common.lang)"
>
<SelectTrigger class="w-[100px]">
<SelectTrigger class="w-[100px] h-[35px] p-2">
<SelectValue placeholder="选择语言" />
</SelectTrigger>
<SelectContent>
Expand All @@ -48,7 +54,7 @@ const config = reactive(defaultConfig)
<Switch
class="mr-2"
:checked="config.common.autoLaunch"
@update:checked="config.common.autoLaunch = !config.common.autoLaunch"
@update:checked="changeConfig('autoLaunch', !config.common.autoLaunch)"
/>
<span>{{ config.common.autoLaunch ? '开' : '关' }}</span>
</div>
Expand All @@ -61,7 +67,7 @@ const config = reactive(defaultConfig)
<Switch
class="mr-2"
:checked="config.common.keepWindowSize"
@update:checked="config.common.keepWindowSize = !config.common.keepWindowSize"
@update:checked="changeConfig('keepWindowSize', !config.common.keepWindowSize)"
/>
<span>{{ config.common.keepWindowSize ? '开' : '关' }}</span>
</div>
Expand All @@ -79,8 +85,9 @@ const config = reactive(defaultConfig)
</div>
<Select
v-model="config.common.theme"
@update:checked="changeConfig('theme', config.common.theme)"
>
<SelectTrigger class="w-[100px]">
<SelectTrigger class="w-[100px] h-[35px] p-2">
<SelectValue placeholder="选择主题" />
</SelectTrigger>
<SelectContent>
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"resolveJsonModule": true,
"strict": true,
"noEmit": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"isolatedModules": true,
"skipLibCheck": true
Expand Down
1 change: 1 addition & 0 deletions tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
]
},
"resolveJsonModule": true,
"strictNullChecks": true,
"allowSyntheticDefaultImports": true
},
"include": [
Expand Down

0 comments on commit cb8242c

Please sign in to comment.