Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add autostart toggle setting
  • Loading branch information
0PandaDEV committed Jan 2, 2025
commit 3bfd72b638b4de1a78ea869653ed3da056d4ed8b
9 changes: 8 additions & 1 deletion app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
<script setup lang="ts">
import { listen } from "@tauri-apps/api/event";
import { app, window } from "@tauri-apps/api";
import { disable, enable } from "@tauri-apps/plugin-autostart";
import { onMounted } from "vue";

const keyboard = useKeyboard();
const { $settings } = useNuxtApp();

onMounted(async () => {
await listen("settings", async () => {
Expand All @@ -19,6 +21,12 @@ onMounted(async () => {
await window.getCurrentWindow().show();
});

if ((await $settings.getSetting("autostart")) === "true") {
await enable();
} else {
await disable();
}

await listen("main_route", async () => {
await navigateTo("/");
});
Expand Down Expand Up @@ -54,7 +62,6 @@ onMounted(async () => {
margin: 0;
padding: 0;
box-sizing: border-box;
color: #e5dfd5;
text-decoration: none;
font-family: SFRoundedRegular;
scroll-behavior: smooth;
Expand Down
5 changes: 0 additions & 5 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ import { OverlayScrollbarsComponent } from "overlayscrollbars-vue";
import "overlayscrollbars/overlayscrollbars.css";
import { app, window } from "@tauri-apps/api";
import { platform } from "@tauri-apps/plugin-os";
import { enable, isEnabled } from "@tauri-apps/plugin-autostart";
import { listen } from "@tauri-apps/api/event";
import { useNuxtApp } from "#app";
import { invoke } from "@tauri-apps/api/core";
Expand Down Expand Up @@ -666,10 +665,6 @@ onMounted(async () => {
?.viewport?.addEventListener("scroll", handleScroll);

await setupEventListeners();

if (!(await isEnabled())) {
await enable();
}
} catch (error) {
console.error("Error during onMounted:", error);
}
Expand Down
8 changes: 0 additions & 8 deletions plugins/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ export default defineNuxtPlugin(() => {
async saveSetting(key: string, value: string): Promise<void> {
await invoke<void>("save_setting", { key, value });
},

async getKeybind(): Promise<string[]> {
return await invoke<string[]>("get_keybind");
},

async saveKeybind(keybind: string[]): Promise<void> {
await invoke<void>("save_keybind", { keybind });
},
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/db/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ async fn apply_migrations(pool: &SqlitePool) -> Result<(), Box<dyn std::error::E
.files()
.filter_map(|file| {
let file_name = file.path().file_name()?.to_str()?;
if file_name.ends_with(".sql") && file_name.starts_with("migration") {
if file_name.ends_with(".sql") && file_name.starts_with("v") {
let version: i64 = file_name
.trim_start_matches("migration")
.trim_start_matches("v")
.trim_end_matches(".sql")
.parse()
.ok()?;
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/db/migrations/v3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO settings (key, value) VALUES ('autostart', 'true');