added settings page, cleanup

This commit is contained in:
Martin Drechsel
2025-05-19 12:29:37 +02:00
parent 6a1351752b
commit 0699dbef31
35 changed files with 889 additions and 653 deletions

View File

@ -46,6 +46,7 @@ export const useBrowserExtensionStore = defineStore(
const initializeAsync = async () => {
const { isInitialized } = storeToRefs(useBrowserExtensionStore());
return
if (isInitialized.value) return;
// Lade Erweiterungen aus dem Erweiterungsverzeichnis
@ -87,4 +88,4 @@ const processNavigation = (url: string) => {
return true;
};
const injectContentScripts = (t: string) => {};
const injectContentScripts = (t: string) => { };

View File

@ -285,12 +285,12 @@ export const useExtensionsStore = defineStore("extensionsStore", () => {
const extensionEntry = computedAsync(
async () => {
try {
console.log("extensionEntry start", currentExtension.value);
const regex = /((href|src)=["'])([^"']+)(["'])/g;
/* console.log("extensionEntry start", currentExtension.value);
const regex = /((href|src)=["'])([^"']+)(["'])/g; */
if (!currentExtension.value?.id || !currentExtension.value.version) {
console.log("extension id or entry missing", currentExtension.value);
return "no mani: " + currentExtension.value;
return ""// "no mani: " + currentExtension.value;
}
const extensionPath = await getExtensionPathAsync(
@ -304,7 +304,7 @@ export const useExtensionsStore = defineStore("extensionsStore", () => {
currentExtension.value.version
);
if (!manifest) return "no manifest readable";
if (!manifest) return ""//"no manifest readable";
const entryPath = await join(extensionPath, manifest.entry);
@ -322,12 +322,12 @@ export const useExtensionsStore = defineStore("extensionsStore", () => {
console.log("entryHtml", entryHtml);
const replacements = [];
let match;
while ((match = regex.exec(entryHtml)) !== null) {
/* while ((match = regex.exec(entryHtml)) !== null) {
const [fullMatch, prefix, attr, resource, suffix] = match;
if (!resource.startsWith("http")) {
replacements.push({ match: fullMatch, resource, prefix, suffix });
}
}
} */
for (const { match, resource, prefix, suffix } of replacements) {
const srcFile = convertFileSrc(await join(extensionPath, resource));

View File

@ -1,5 +1,6 @@
{
"light": "Hell",
"dark": "Dunkel",
"soft": "Soft"
"soft": "Soft",
"corporate": "Corporate"
}

View File

@ -1,5 +1,6 @@
{
"light": "Light",
"dark": "Dark",
"soft": "Soft"
"soft": "Soft",
"corporate": "Corporate"
}

View File

@ -2,6 +2,12 @@ import { breakpointsTailwind, useBreakpoints } from '@vueuse/core';
import de from './de.json';
import en from './en.json';
export interface ITheme {
value: string,
name: string,
icon: string
}
export const useUiStore = defineStore('uiStore', () => {
const breakpoints = useBreakpoints(breakpointsTailwind);
@ -28,14 +34,22 @@ export const useUiStore = defineStore('uiStore', () => {
icon: 'line-md:moon-to-sunny-outline-loop-transition',
},
{ value: 'soft', name: t('ui.soft'), icon: 'line-md:paint-drop' },
{
value: 'corporate',
name: t('ui.corporate'),
icon: 'hugeicons:corporate',
},
]);
const currentTheme = ref(availableThemes.value[0].value);
const defaultTheme = ref(availableThemes.value[0])
const currentTheme = ref(defaultTheme);
return {
availableThemes,
breakpoints,
currentScreenSize,
currentTheme,
availableThemes,
defaultTheme,
};
});

View File

@ -13,13 +13,6 @@ export const useSidebarStore = defineStore("sidebarStore", () => {
const isVisible = ref(true);
const menu = ref<ISidebarItem[]>([
{
id: "haex-browser",
name: "Haex Browser",
icon: "solar:global-outline",
to: { name: "haexBrowser" },
},
{
id: "haex-extensions-add",
name: "Haex Extensions",

View File

@ -1,11 +1,9 @@
//import Database from '@tauri-apps/plugin-sql';
import { drizzle, SqliteRemoteDatabase } from "drizzle-orm/sqlite-proxy";
//import Database from "tauri-plugin-sql-api";
import * as schema from "@/../src-tauri/database/schemas/vault";
import * as schema from "@/../src-tauri/database/schemas/vault";
import { invoke } from "@tauri-apps/api/core";
import { and, count, eq } from "drizzle-orm";
import { platform } from "@tauri-apps/plugin-os";
import { hostname, platform, type, version } from "@tauri-apps/plugin-os";
import { eq } from "drizzle-orm";
import { drizzle, SqliteRemoteDatabase } from "drizzle-orm/sqlite-proxy";
interface IVault {
name: string;
@ -16,6 +14,7 @@ interface IOpenVaults {
}
export const useVaultStore = defineStore("vaultStore", () => {
const currentVaultId = computed<string | undefined>({
get: () => getSingleRouteParam(useRouter().currentRoute.value.params.vaultId),
set: (newVaultId) => {
@ -23,6 +22,9 @@ export const useVaultStore = defineStore("vaultStore", () => {
},
});
const defaultVaultName = ref("HaexHub")
const currentVaultName = ref(defaultVaultName.value)
const read_only = computed<boolean>({
get: () => {
console.log("query showSidebar", useRouter().currentRoute.value.query.readonly);
@ -53,6 +55,8 @@ export const useVaultStore = defineStore("vaultStore", () => {
{ immediate: true }
);
const hostKey = computedAsync(async () => "".concat(type(), version(), await hostname() ?? ""))
const openAsync = async ({ path = "", password }: { path: string; password: string }) => {
try {
const result = await invoke<string>("open_encrypted_database", {
@ -102,7 +106,11 @@ export const useVaultStore = defineStore("vaultStore", () => {
};
const { addVaultAsync } = useLastVaultStore();
await addVaultAsync({ path });
addVaultAsync({ path });
syncLocaleAsync()
syncThemeAsync()
syncVaultNameAsync()
return vaultId;
} catch (error) {
@ -147,15 +155,86 @@ export const useVaultStore = defineStore("vaultStore", () => {
delete openVaults.value?.[currentVaultId.value];
};
const syncLocaleAsync = async () => {
try {
const app = useNuxtApp()
app.$i18n.availableLocales
//const { availableLocales, defaultLocale, setLocale, locale } = useI18n()
const currentLocaleRow = await currentVault.value?.drizzle
.select()
.from(schema.haexSettings)
.where(eq(schema.haexSettings.key, 'locale'))
if (currentLocaleRow?.[0]?.value) {
const currentLocale = app.$i18n.availableLocales.find(
(locale) => locale === currentLocaleRow[0].value
)
await app.$i18n.setLocale(currentLocale ?? app.$i18n.defaultLocale)
} else {
await currentVault.value?.drizzle
.insert(schema.haexSettings)
.values({ id: crypto.randomUUID(), key: 'locale', value: app.$i18n.locale.value })
}
} catch (error) {
console.log("ERROR syncLocaleAsync", error)
}
}
const syncThemeAsync = async () => {
const { availableThemes, defaultTheme, currentTheme } = storeToRefs(useUiStore())
const currentThemeRow = await currentVault.value?.drizzle
.select()
.from(schema.haexSettings)
.where(eq(schema.haexSettings.key, 'theme'))
if (currentThemeRow?.[0]?.value) {
const theme = availableThemes.value.find(
(theme) => theme.name === currentThemeRow[0].value
)
currentTheme.value = theme ?? defaultTheme.value
} else {
await currentVault.value?.drizzle.insert(schema.haexSettings).values({
id: crypto.randomUUID(),
key: 'theme',
value: currentTheme.value.name,
})
}
}
const syncVaultNameAsync = async () => {
const currentVaultNameRow = await currentVault.value?.drizzle
.select()
.from(schema.haexSettings)
.where(eq(schema.haexSettings.key, 'vaultName'))
if (currentVaultNameRow?.[0]?.value) {
currentVaultName.value = currentVaultNameRow.at(0)?.value ?? defaultVaultName.value
} else {
await currentVault.value?.drizzle.insert(schema.haexSettings).values({
id: crypto.randomUUID(),
key: 'vaultName',
value: currentVaultName.value,
})
}
}
const updateVaultNameAsync = async (newVaultName?: string | null) => {
return currentVault.value?.drizzle.update(schema.haexSettings).set({ value: newVaultName ?? defaultVaultName.value }).where(eq(schema.haexSettings.key, "vaultName"))
}
return {
closeAsync,
createAsync,
currentVault,
currentVaultId,
currentVaultName,
hostKey,
openAsync,
openVaults,
refreshDatabaseAsync,
read_only,
refreshDatabaseAsync,
updateVaultNameAsync,
};
});
@ -174,3 +253,6 @@ const isSelectQuery = (sql: string) => {
const selectRegex = /^\s*SELECT\b/i;
return selectRegex.test(sql);
};