Skip to content

Commit

Permalink
add app menu
Browse files Browse the repository at this point in the history
  • Loading branch information
L4Ph committed Sep 17, 2024
1 parent e2faf64 commit fb302d6
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 49 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@fontsource-variable/m-plus-2": "^5.1.0",
"@l4ph/web-novel-parser": "npm:@jsr/l4ph__web-novel-parser",
"@tauri-apps/api": "^2.0.0-rc.4",
"@tauri-apps/plugin-fs": "^2.0.0-rc.2",
"bits-ui": "^0.21.13",
"clsx": "^2.1.1",
"mode-watcher": "^0.4.1",
Expand Down
22 changes: 22 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 @@ -19,4 +19,5 @@ tauri = { version = "2.0.0-rc", features = [] }
tauri-plugin-shell = "2.0.0-rc"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tauri-plugin-fs = "2.0.0-rc"

9 changes: 6 additions & 3 deletions src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"windows": [
"main"
],
"permissions": [
"core:default",
"shell:allow-open"
"shell:allow-open",
"fs:default"
]
}
}
38 changes: 37 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
use tauri::{
menu::{MenuBuilder, MenuItemBuilder, SubmenuBuilder},
Emitter, Manager,
};

#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
Expand All @@ -7,6 +11,38 @@ fn greet(name: &str) -> String {
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_fs::init())
.setup(|app| {
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 file_menu = SubmenuBuilder::with_id(app, "file_menu", "ファイル")
.items(&[&open_file, &save_file, &save_as])
.build()?;
let menu = MenuBuilder::new(app).items(&[&file_menu]).build()?;

app.set_menu(menu.clone())?;
app.on_menu_event(move |app, event| {
let window_list = app.webview_windows();
let window_tuple = window_list.iter().next().unwrap();
let window = window_tuple.1;
match event.id().0.as_str() {
"open_file" => {
window.emit("open_file", "").unwrap();
}

"save_file" => {
window.emit("save_file", "").unwrap();
}

"save_as" => {
window.emit("save_as", "").unwrap();
}
_ => {}
}
});
Ok(())
})
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
Expand Down
14 changes: 0 additions & 14 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import { parseNarouNovel } from "@l4ph/web-novel-parser";
import Dropzone from "svelte-file-dropzone";
import { shortcut, type ShortcutEventDetail } from "@svelte-put/shortcut";
import { handleFileSelect, files } from "./dropzone-handler";
import { insertRubyToTextarea, insertEmphasisToTextarea } from "./shortcuts";
import { isTauriApp } from "$lib/is-tauri-app";
let inputText = '';
let preview = '';
Expand All @@ -26,23 +24,11 @@
<main class="h-screen">
<div class="flex h-full bg-background">
<div class="w-1/2 p-4 flex flex-col">
{#if !inputText}
<Dropzone accept="text/plain" on:drop={(e) => handleFileSelect(e, inputText, textarea)} noClick windowDrop>
<Textarea
bind:value={inputText}
bind:this={textarea}
placeholder="ファイルをドロップするか、本文を入力してください。"
class="w-full h-full resize-none"
/>
</Dropzone>
{/if}
{#if inputText || isTauriApp()}
<Textarea
bind:value={inputText}
bind:this={textarea}
class="w-full h-full resize-none"
/>
{/if}
</div>
<div class="border-border border-r"></div>
<div class="w-1/2 p-4 overflow-auto">
Expand Down
31 changes: 0 additions & 31 deletions src/routes/dropzone-handler.ts

This file was deleted.

0 comments on commit fb302d6

Please sign in to comment.