mirror of
https://github.com/open-webui/assistant
synced 2025-05-11 23:40:33 +00:00
feat: config versioning
This commit is contained in:
parent
4e31e7c468
commit
94866399f8
13
src/App.vue
13
src/App.vue
@ -64,7 +64,7 @@ onBeforeMount(async () => {
|
||||
|
||||
<template>
|
||||
<div class=" h-screen w-screen p-3 flex justify-center">
|
||||
<div class=" my-auto w-full flex flex-col gap-2">
|
||||
<form class=" my-auto w-full flex flex-col gap-2" @submit.prevent="saveHandler">
|
||||
<div class="flex justify-between items-center">
|
||||
<div class=" text-sm font-semibold">Open WebUI Assistant</div>
|
||||
|
||||
@ -77,7 +77,7 @@ onBeforeMount(async () => {
|
||||
<div v-else>
|
||||
<button
|
||||
class="bg-neutral-700 hover:bg-neutral-800 transition text-white text-xs px-3 py-1 rounded-lg"
|
||||
@click="saveHandler">Connect</button>
|
||||
type="submit">Connect</button>
|
||||
</div>
|
||||
|
||||
|
||||
@ -87,10 +87,10 @@ onBeforeMount(async () => {
|
||||
|
||||
<input v-model="url"
|
||||
class=" w-full bg-gray-100 hover:bg-gray-200 transition rounded-lg py-1 px-2 text-xs outline-none disabled:bg-gray-100 disabled:text-gray-500 dark:disabled:text-gray-500"
|
||||
placeholder="Open WebUI URL" :disabled='connected' />
|
||||
placeholder="Open WebUI URL" :disabled='connected' required />
|
||||
<input v-model="token"
|
||||
class=" w-full bg-gray-100 hover:bg-gray-200 transition rounded-lg py-1 px-2 text-xs outline-none disabled:bg-gray-100 disabled:text-gray-500 dark:disabled:text-gray-500"
|
||||
placeholder="Open WebUI Token" :disabled='connected' />
|
||||
placeholder="Open WebUI Token" :disabled='connected' required />
|
||||
|
||||
<hr />
|
||||
|
||||
@ -103,7 +103,8 @@ onBeforeMount(async () => {
|
||||
<option v-for="model in models" v-bind:value="model.name">{{ model.name }}</option>
|
||||
</select>
|
||||
|
||||
<button class="p-1 bg-gray-100 hover:bg-gray-200 transition rounded-lg" @click="selectModelHandler">
|
||||
<button class="p-1 bg-gray-100 hover:bg-gray-200 transition rounded-lg" type="button"
|
||||
@click="selectModelHandler">
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" class="w-4 h-4">
|
||||
<path fill-rule="evenodd"
|
||||
@ -118,7 +119,7 @@ onBeforeMount(async () => {
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
</div>
|
||||
|
34
src/main.ts
34
src/main.ts
@ -15,6 +15,8 @@ import { default as fs } from "fs";
|
||||
|
||||
keyboard.config.autoDelayMs = 0;
|
||||
|
||||
const configPath = app.getPath("userData") + "/config.json";
|
||||
|
||||
let WEBUI_VERSION: string | null = null;
|
||||
let models: object[] = [];
|
||||
|
||||
@ -235,7 +237,7 @@ const selectModel = async (modelId) => {
|
||||
};
|
||||
|
||||
const loadConfig = async () => {
|
||||
fs.readFile("config.json", "utf8", (err, data) => {
|
||||
fs.readFile(configPath, "utf8", (err, data) => {
|
||||
if (err) {
|
||||
console.error("Error reading config file:", err);
|
||||
return;
|
||||
@ -248,16 +250,24 @@ const loadConfig = async () => {
|
||||
// Do something with the config object
|
||||
console.log("Config:", _config);
|
||||
|
||||
if (_config.url) {
|
||||
config.url = _config.url;
|
||||
}
|
||||
if (_config.version === 1) {
|
||||
console.log("Config loaded successfully:", config);
|
||||
// Use the loaded configuration
|
||||
|
||||
if (_config.token) {
|
||||
config.token = _config.token;
|
||||
}
|
||||
if (_config.url) {
|
||||
config.url = _config.url;
|
||||
}
|
||||
|
||||
if (_config.model) {
|
||||
selectedModel = _config.model;
|
||||
if (_config.token) {
|
||||
config.token = _config.token;
|
||||
}
|
||||
|
||||
if (_config.model) {
|
||||
selectedModel = _config.model;
|
||||
}
|
||||
} else {
|
||||
console.error("Incompatible configuration version.");
|
||||
// Handle incompatible version gracefully
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error parsing JSON:", error);
|
||||
@ -267,8 +277,9 @@ const loadConfig = async () => {
|
||||
|
||||
const saveConfigToFile = async () => {
|
||||
fs.writeFileSync(
|
||||
"config.json",
|
||||
configPath,
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
...config,
|
||||
model: selectModel,
|
||||
})
|
||||
@ -282,6 +293,9 @@ app
|
||||
.then(() => {
|
||||
loadConfig();
|
||||
|
||||
console.log(process.cwd());
|
||||
console.log(app.getPath("userData"));
|
||||
|
||||
ipcMain.handle("check-connection", async (event, arg) => {
|
||||
await getVersion();
|
||||
return WEBUI_VERSION !== null;
|
||||
|
Loading…
Reference in New Issue
Block a user