Enhance clipboard and database management in initialization process

- Added logging to `cleanClipboard` to indicate the number of clipboard entries older than a specified number of days.
- Introduced a new utility function `vacuumSqlite` for database maintenance, which is now called during app initialization.
- Updated the `init` function to await the completion of `cleanClipboard` and `vacuumSqlite` for better error handling and flow control.
- Ensured that the console attachment in `onMount` is awaited for proper synchronization.
This commit is contained in:
Huakun Shen 2025-04-03 11:20:07 -04:00
parent 211b131efd
commit bd8a249b3c
No known key found for this signature in database
4 changed files with 19 additions and 3 deletions

View File

@ -24,6 +24,7 @@ export async function cleanClipboard() {
) )
) )
const nLinesToDelete = oldClipboardData.at(0)?.count ?? 0 const nLinesToDelete = oldClipboardData.at(0)?.count ?? 0
console.info(`Found ${nLinesToDelete} clipboard entries older than ${nDays} days to clean up`)
info(`Found ${nLinesToDelete} clipboard entries older than ${nDays} days to clean up`) info(`Found ${nLinesToDelete} clipboard entries older than ${nDays} days to clean up`)
// Now delete the old data // Now delete the old data

View File

@ -0,0 +1,13 @@
import { proxyDB } from "@kksh/drizzle"
import { error, info } from "@tauri-apps/plugin-log"
import { sql } from "drizzle-orm"
export async function vacuumSqlite() {
const statement = sql`VACUUM`
try {
await proxyDB.run(statement)
info("Vacuumed sqlite")
} catch (error) {
console.error(`Failed to vacuum sqlite: ${error}`)
}
}

View File

@ -3,13 +3,14 @@ import { getCurrentWindow } from "@tauri-apps/api/window"
import { error, info } from "@tauri-apps/plugin-log" import { error, info } from "@tauri-apps/plugin-log"
import { dev } from "$app/environment" import { dev } from "$app/environment"
import { cleanClipboard } from "./clipboard" import { cleanClipboard } from "./clipboard"
import { vacuumSqlite } from "./db"
import { mapKeyToTauriKey, registerAppHotkey } from "./hotkey" import { mapKeyToTauriKey, registerAppHotkey } from "./hotkey"
import { listenToReloadOneExtension } from "./tauri-events" import { listenToReloadOneExtension } from "./tauri-events"
/** /**
* Initialize the app * Initialize the app
*/ */
export function init() { export async function init() {
const window = getCurrentWindow() const window = getCurrentWindow()
if (window.label === "main") { if (window.label === "main") {
initMainWindow() initMainWindow()
@ -18,13 +19,14 @@ export function init() {
extensions.reloadExtension(extPath) extensions.reloadExtension(extPath)
}) })
} }
cleanClipboard() await cleanClipboard()
.then(() => { .then(() => {
info("Cleaned clipboard") info("Cleaned clipboard")
}) })
.catch((e) => { .catch((e) => {
error(`Failed to clean clipboard: ${e}`) error(`Failed to clean clipboard: ${e}`)
}) })
vacuumSqlite()
if (!dev) { if (!dev) {
// document.addEventListener("contextmenu", function (event) { // document.addEventListener("contextmenu", function (event) {
// event.preventDefault() // event.preventDefault()

View File

@ -53,7 +53,7 @@
unlisteners.forEach((unlistener) => unlistener()) unlisteners.forEach((unlistener) => unlistener())
}) })
onMount(async () => { onMount(async () => {
attachConsole().then((unlistener) => unlisteners.push(unlistener)) await attachConsole().then((unlistener) => unlisteners.push(unlistener))
initDeeplink().then((unlistener) => unlisteners.push(unlistener)) initDeeplink().then((unlistener) => unlisteners.push(unlistener))
shellx shellx
.fixPathEnv() .fixPathEnv()