1
1
import { Context } from '@kit.AbilityKit'
2
2
import { BusinessError, pasteboard } from '@kit.BasicServicesKit'
3
- import sql from '@liushengyi/smartdb'
4
3
import { PasteboardDao } from './PasteboardDao'
5
- import { PasteboardDatabase } from './PasteboardDatabase'
4
+ import { PasteboardDatabase, rdbStore } from './PasteboardDatabase'
6
5
import { PasteboardEntry } from './PasteboardEntry'
7
6
import { HashSet } from '@kit.ArkTS'
8
7
import { StrUtil } from '../../../utils/StrUtil'
@@ -63,15 +62,18 @@ export class PasteboardController {
63
62
}
64
63
65
64
async get(id: number): Promise<PasteboardEntry> {
66
- return await this.psbDao!.getById(id)
65
+ const entry = await this.psbDao!.getById(id)
66
+ return entry
67
67
}
68
68
69
69
async haveUnpinned(): Promise<boolean> {
70
- return await this.psbDao!.haveUnpinned()
70
+ const result = await this.psbDao!.haveUnpinned()
71
+ return result
71
72
}
72
73
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
75
77
}
76
78
77
79
async pin(id: number) {
@@ -124,7 +126,6 @@ export class PasteboardController {
124
126
await this.updateItemCount()
125
127
}
126
128
127
- @sql.Transactional()
128
129
private async insertEntry(entry: PasteboardEntry): Promise<PasteboardEntry> {
129
130
const rowId = await this.psbDao!.insert(entry)
130
131
if (!rowId) {
@@ -145,14 +146,20 @@ export class PasteboardController {
145
146
return
146
147
}
147
148
try {
148
- const existed = await pasteboardController .psbDao!.find(entry.text, entry.sensitive)
149
+ const existed = await this .psbDao!.find(entry.text, entry.sensitive)
149
150
if (existed) {
150
151
const copy = existed
151
152
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)
154
155
} 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
156
163
console.debug('get entry text: ' + insertedEntry.text)
157
164
pasteboardController.updateLastEntry(insertedEntry)
158
165
pasteboardController.updateItemCount()
0 commit comments