11import { Context } from '@kit.AbilityKit'
22import { BusinessError, pasteboard } from '@kit.BasicServicesKit'
3- import sql from '@liushengyi/smartdb'
43import { PasteboardDao } from './PasteboardDao'
5- import { PasteboardDatabase } from './PasteboardDatabase'
4+ import { PasteboardDatabase, rdbStore } from './PasteboardDatabase'
65import { PasteboardEntry } from './PasteboardEntry'
76import { HashSet } from '@kit.ArkTS'
87import { StrUtil } from '../../../utils/StrUtil'
@@ -63,15 +62,18 @@ export class PasteboardController {
6362 }
6463
6564 async get(id: number): Promise<PasteboardEntry> {
66- return await this.psbDao!.getById(id)
65+ const entry = await this.psbDao!.getById(id)
66+ return entry
6767 }
6868
6969 async haveUnpinned(): Promise<boolean> {
70- return await this.psbDao!.haveUnpinned()
70+ const result = await this.psbDao!.haveUnpinned()
71+ return result
7172 }
7273
73- async allEntries(): Promise<Array<PasteboardEntry>> {
74- return await this.psbDao!.allEntries()
74+ async getEntries(offset: number, limit: number): Promise<Array<PasteboardEntry>> {
75+ const entries = await this.psbDao!.getEntries(offset, limit)
76+ return entries
7577 }
7678
7779 async pin(id: number) {
@@ -124,7 +126,6 @@ export class PasteboardController {
124126 await this.updateItemCount()
125127 }
126128
127- @sql.Transactional()
128129 private async insertEntry(entry: PasteboardEntry): Promise<PasteboardEntry> {
129130 const rowId = await this.psbDao!.insert(entry)
130131 if (!rowId) {
@@ -145,14 +146,20 @@ export class PasteboardController {
145146 return
146147 }
147148 try {
148- const existed = await pasteboardController .psbDao!.find(entry.text, entry.sensitive)
149+ const existed = await this .psbDao!.find(entry.text, entry.sensitive)
149150 if (existed) {
150151 const copy = existed
151152 copy.timestamp = entry.timestamp
152- pasteboardController .updateLastEntry(copy)
153- await pasteboardController .psbDao!.updateTime(existed.id, entry.timestamp)
153+ this .updateLastEntry(copy)
154+ await this .psbDao!.updateTime(existed.id, entry.timestamp)
154155 } else {
155- const insertedEntry = await pasteboardController.insertEntry(entry)
156+ let temp: PasteboardEntry | undefined = undefined
157+ rdbStore?.createTransaction().then(async () => {
158+ const rowId = await this.psbDao!.insert(entry)
159+ // TODO: removeOutdated()
160+ temp = await this.psbDao?.getByRowId(rowId)
161+ })
162+ const insertedEntry = temp ? temp : entry
156163 console.debug('get entry text: ' + insertedEntry.text)
157164 pasteboardController.updateLastEntry(insertedEntry)
158165 pasteboardController.updateItemCount()
0 commit comments