Skip to content

Commit

Permalink
add settings window
Browse files Browse the repository at this point in the history
  • Loading branch information
L4Ph committed Dec 28, 2024
1 parent b9f1741 commit a87c835
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 540 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
"@tauri-apps/api": "^2.1.1",
"@tauri-apps/plugin-dialog": "^2.2.0",
"@tauri-apps/plugin-fs": "^2.2.0",
"@tauri-apps/plugin-process": "~2",
"@tauri-apps/plugin-shell": "~2",
"@tauri-apps/plugin-updater": "~2",
"@tauri-apps/plugin-process": "~2.2.0",
"@tauri-apps/plugin-shell": "~2.2.0",
"@tauri-apps/plugin-store": "~2",
"@tauri-apps/plugin-updater": "~2.3.0",
"bits-ui": "1.0.0-next.74",
"clsx": "^2.1.1",
"lucide-svelte": "^0.469.0",
Expand All @@ -31,14 +32,14 @@
"svelte-sonner": "^0.3.28",
"tailwind-merge": "^2.6.0",
"tailwind-variants": "^0.3.0",
"unstorage": "^1.14.1",
"unstorage": "^1.14.4",
"web-novel-parser": "^0.1.6"
},
"devDependencies": {
"@biomejs/biome": "1.9.2",
"@svelte-put/shortcut": "^4.1.0",
"@sveltejs/adapter-static": "^3.0.8",
"@sveltejs/kit": "^2.15.0",
"@sveltejs/kit": "^2.15.1",
"@sveltejs/vite-plugin-svelte": "^5.0.3",
"@tailwindcss/typography": "^0.5.15",
"@tauri-apps/cli": "^2.1.0",
Expand All @@ -54,7 +55,7 @@
"tailwindcss-animate": "^1.0.7",
"tslib": "^2.8.1",
"typescript": "^5.7.2",
"vite": "^6.0.5"
"vite": "^6.0.6"
},
"packageManager": "[email protected]",
"module": "index.ts"
Expand Down
678 changes: 159 additions & 519 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tauri-plugin-fs = "2.2.0"
tauri-plugin-dialog = "2.2.0"
tauri-plugin-shell = "2"
tauri-plugin-process = "2"
tauri-plugin-store = "2"

[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-updater = "2"
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"shell:allow-open",
"fs:default",
"fs:allow-write-text-file",
"dialog:default"
"dialog:default",
"core:webview:allow-create-webview-window"
]
}
9 changes: 8 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fn greet(name: &str) -> String {
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::new().build())
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_dialog::init())
Expand All @@ -19,8 +20,9 @@ pub fn run() {
let open_file = MenuItemBuilder::with_id("open_file", "開く").build(app)?;
let save_file = MenuItemBuilder::with_id("save_file", "保存").build(app)?;
let save_as = MenuItemBuilder::with_id("save_as", "名前を付けて保存").build(app)?;
let open_settings = MenuItemBuilder::with_id("open_settings", "設定").build(app)?;
let file_menu = SubmenuBuilder::with_id(app, "file_menu", "ファイル")
.items(&[&open_file, &save_file, &save_as])
.items(&[&open_file, &save_file, &save_as, &open_settings])
.build()?;
let menu = MenuBuilder::new(app).items(&[&file_menu]).build()?;

Expand All @@ -41,6 +43,11 @@ pub fn run() {
"save_as" => {
let _ = window.emit("save_as", "");
}

"open_settings" => {
let _ = window.emit("open_settings", "");
}

_ => {}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"productName": "tawri",
"version": "0.2.3",
"version": "0.2.4",
"identifier": "moe.l4ph.tawri",
"build": {
"beforeDevCommand": "pnpm run dev",
Expand Down
43 changes: 31 additions & 12 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ import { createStorage } from "unstorage";
import localStorageDriver from "unstorage/drivers/localstorage";
import { onMount } from "svelte";
import { runUpdater } from "./utils/run-updater";
import { Window } from "@tauri-apps/api/window";
import { Webview } from "@tauri-apps/api/webview";
runUpdater()
runUpdater();
const storage = createStorage({
driver: localStorageDriver({ base: "tawri:" }),
driver: localStorageDriver({ base: "tawri:" }),
});
let inputText = $state("");
let unsavedText = $derived(inputText)
let unsavedText = $derived(inputText);
let textarea: Textarea;
let open = $state(true);
let fileInput = $state<HTMLInputElement | null>(null);
Expand All @@ -37,19 +39,18 @@ let preview = $derived.by(() => {
});
onMount(async () => {
const unsavedText = await storage.getItem("tawri:unsavedText");
if (typeof unsavedText === "string" && !inputText) {
inputText = unsavedText;
}
const unsavedText = await storage.getItem("tawri:unsavedText");
if (typeof unsavedText === "string" && !inputText) {
inputText = unsavedText;
}
});
$effect(() =>{
storage.setItem("tawri:unsavedText", unsavedText)
})
$effect(() => {
storage.setItem("tawri:unsavedText", unsavedText);
});
async function handleFileChange(event: Event) {
try {
try {
const filePath = await openDialog({
multiple: false,
directory: false,
Expand Down Expand Up @@ -116,6 +117,24 @@ listen("save_as", async () => {
toast.error("ファイルの保存に失敗しました。");
}
});
listen("open_settings", async () => {
try {
const appWindow = new Window("app-settings");
const webview = new Webview(appWindow, "app-settings", {
x: 800,
y: 600,
width: 600,
height: 800,
url: "https://github.com/tauri-apps/tauri",
});
webview.once("tauri://created", () => {
// webview successfully created
});
} catch (error) {
toast.error("設定画面が開けませんでした。");
}
});
</script>

<svelte:window
Expand Down
1 change: 1 addition & 0 deletions src/routes/settings/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>test</p>
15 changes: 15 additions & 0 deletions src/routes/settings/utils/load-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { load } from "@tauri-apps/plugin-store";
import { join, resourceDir } from "@tauri-apps/api/path";

export async function loadConfig() {
//resourceDirを使えば実行パスでストア作成も可能
const configDir = await join(await resourceDir(), "settings.json");

//渡されたパスでストアの読み込み設定を確立
//(ファイルには直接アクセスしないため、config.jsonが無くてもエラーになりません。)
const store = await load(configDir, { autoSave: false });

//getでキー値を渡して値を取得する
//jsonが無いか、キーが存在しない場合はundefinedが返ってくる。
const data = await store.get<string>("data");
}

0 comments on commit a87c835

Please sign in to comment.