Skip to content

Commit

Permalink
fix(connection):remember last opened connection
Browse files Browse the repository at this point in the history
  • Loading branch information
ni00 committed Jul 10, 2023
1 parent 8e49037 commit 130955b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/database/services/ConnectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Repository, MoreThan, LessThan } from 'typeorm'
import { DateUtils } from 'typeorm/util/DateUtils'
import time, { sqliteDateFormat } from '@/utils/time'
import useServices from '@/database/useServices'
const Store = require('electron-store')
const electronStore = new Store()

export const MoreThanDate = (date: string | Date) => MoreThan(DateUtils.mixedDateToUtcDatetimeString(date))
export const LessThanDate = (date: string | Date) => LessThan(DateUtils.mixedDateToUtcDatetimeString(date))
Expand Down Expand Up @@ -188,6 +190,7 @@ export default class ConnectionService {
if (query === undefined) {
return undefined
}
electronStore.set('leatestId', id)
return ConnectionService.entityToModel(query)
}

Expand Down Expand Up @@ -274,14 +277,15 @@ export default class ConnectionService {
}
res.will = savedWill
// TODO: refactor historyConnectionRepository field
await this.historyConnectionRepository.save({
const result = await this.historyConnectionRepository.save({
...res,
id: undefined,
lastWillTopic: res.will.lastWillPayload,
lastWillPayload: res.will.lastWillPayload,
lastWillQos: res.will.lastWillQos,
lastWillRetain: res.will.lastWillRetain,
} as HistoryConnectionEntity)
electronStore.set('leatestId', result.id)
return ConnectionService.entityToModel(
await this.connectionRepository.save(
ConnectionService.modelToEntity({
Expand Down Expand Up @@ -349,6 +353,9 @@ export default class ConnectionService {
}

public async getLeatestId(): Promise<string | undefined> {
if (electronStore.get('leatestId')) {
return electronStore.get('leatestId')
}
const leatest: ConnectionEntity | undefined = await this.connectionRepository
.createQueryBuilder('cn')
.addOrderBy('createAt', 'ASC')
Expand Down

0 comments on commit 130955b

Please sign in to comment.