Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Vue3/Electronで自作したマークダウンエディタをVue3/Tauriにリプレイスした話

yud0uhu
October 27, 2023

 Vue3/Electronで自作したマークダウンエディタをVue3/Tauriにリプレイスした話

Vue Fes Japan 2023 LT登壇資料です
https://vuefes.jp/2023/sessions/yud0uhu

yud0uhu

October 27, 2023
Tweet

More Decks by yud0uhu

Other Decks in Technology

Transcript

  1. 4

  2. 7

  3. 10

  4. プロセス間通信:具体例 26 // … #[tauri::command] fn generate_mermaid_img(code: String) -> String

    { let encoded_code = encode_to_base64(&code); let response = ApiResponse { img: format!("https://mermaid.ink/img/{}", encoded_code), }; format!("{}", response.img) }
  5. プロセス間通信:具体例 29 import { invoke } from "@tauri-apps/api"; // …

    const generateMermaidImg = async (code: string) => { try { const response = await invoke("generate_mermaid_img", { code: code }); return response; } catch (error) { // …
  6. tauri/allowlist:具体例 "tauri": { "allowlist": { "all": false, ... "dialog": {

    "open": true, "save": true }, "fs": { "all": true, "writeFile": true }, ... }, 32
  7. tauri/allowlist:具体例 <script setup lang="ts"> import Header from "./components/Header.vue"; import MarkdownEditor

    from "./components/MarkdownEditor.vue"; import { ref } from "vue"; import { open, save } from "@tauri-apps/api/dialog"; import { readTextFile, writeFile } from "@tauri-apps/api/fs"; import { appDir } from "@tauri-apps/api/path"; 33
  8. tauri/allowlist:具体例 const openFile = async () => { try {

    const selected = await open({ directory: false, multiple: false, defaultPath: await appDir(), filters: [{ name: "Markdown and Text Files", extensions: ["md", "txt"] }], }); 34
  9. tauri/allowlist:具体例 if (selected !== null) { if (!Array.isArray(selected)) { const

    filePath = selected; const contents = await readTextFile(filePath); onMarkdownUpdate(contents); } } } catch (error) { // … 35
  10. tauri/allowlist:具体例 const saveFile = async () => { try {

    const result = await save({ defaultPath: "untitled.txt", filters: [{ name: "Markdown and Text Files", extensions: ["md", "txt"] }], }); if (result) { const fileContents = markdownText.value; await writeFile({ path: result, contents: fileContents ? fileContents : "", }); 36