Rust

独学書

TextDateStatus
パーフェクトRust2024/01/05finished ->コード

コンテンツ

ContentsDateStatus
Webアプリ実装で学ぶ、現場で役立つRust入門2025/10/07finished ->コード

環境

  1. Windows 11

    MachineEnv / FWLast Updated
    Windows InsiderRust 1.94.12026/03/28
    - cargo-generate 0.23.52025/10/06
    - wasm-pack 0.13.12025/10/06
    Tauri 2.10.32026/03/15
    - Svelte 5.55.02026/03/28
    - Bun 1.3.112026/03/28
    - Vite 8.0.32026/03/28
    Dioxus 0.7.32026/01/23
    - Visual Studio Community 2022 17.14.222025/12/10
    WindowsRust 1.932026/01/23
    - Visual Studio Community 2022 17.14.212025/12/13
    RustRover 2025.3.32026/02/01
    Bevy 0.18.02026/01/23
    Slint 1.14.12026/01/23
  2. Ubuntu 24.04.4 on Windows 11

    MachineEnv / FWLast Updated
    Windows InsiderRust 1.94.12026/03/28
    Tauri 2.10.32026/03/28
    - React 19.2.42026/03/28
    - Bun 1.3.112026/03/28
    - Vite 7.3.12026/01/23
  3. ChromeOS Flex 145.0.7632.216 (Official Build)

    MachineEnv / FWLast Updated
    ChromeOSRust 1.94.12026/03/28
    Node.js 25.0.02025/10/18
    Tauri 2.10.32026/03/08
    - React 19.2.42026/03/08
    - Bun 1.3.102026/03/08
    - Vite 7.3.12026/01/24
  4. macOS Tahoe 26.4

    MachineEnv / FWLast Updated
    macOSRust 1.94.12026/03/28
    Node 22.6.02024/08/17
    Tauri 2.10.32026/03/16
    - React 19.2.42026/03/16
    - Bun 1.3.112026/03/28
    - Vite 8.0.32026/03/28

ノウハウ

Rust

WASM

RustRover

Visual Studio Code

クレート

セッション管理

SSL

Tauri(Desktop Framework)

Slint

Dioxus(Cross Platform Library)

Game Engine

Tauri Documents

Splashscreen

Webページが読み込みに時間がかかったり、メインウィンドウを表示する前に初期処理を実行する必要がある場合、スプラッシュスクリーンによって、ユーザの起動体験を改善できる。

Setup

まず、実行環境のディレクトリにsplashscreen.html(スプラッシュスクリーンのためのHTMLコード)を作る。

"windows": [
    {
        "title": "Tauri App",
        "width": 800,
        "height": 600,
        "resizable": true,
        "fullscreen": false,
    +   "visible": false // Hide the main window by default
    },
    // Add the splashscreen window
    + {
    +   "width": 400,
    +   "height": 200,
    +   "decorations": false,
    +   "url": "splashscreen.html",
    +   "label": "splashscreen"
    + }
]

さて、アプリケーション起動時には、メインウィンドウを非表示にして、スプラッシュスクリーンを表示するようにします。続けて、メインウィンドウが準備できたら、スプラッシュスクリーンを閉じる手段を準備する必要があります。何を待っているかによって、スプラッシュスクリーンを閉じる手段は決まる。

Waiting for Webpage

Webコンテンツを待っているのであれば、フロントエンドからスプラッシュスクリーンを閉じるコマンドを準備したいでしょう。

use tauri::Manager;
// Create the command:
// This command must be async so that it doesn't run on the main thread.
#[tauri::command]
async fn close_splashscreen(window: tauri::Window) {
  // Close splashscreen
  if let Some(splashscreen) = window.get_window("splashscreen") {
    splashscreen.close().unwrap();
  }
  // Show main window
  window.get_window("main").unwrap().show().unwrap();
}

// Register the command:
fn main() {
  tauri::Builder::default()
    // Add this line
    .invoke_handler(tauri::generate_handler![close_splashscreen])
    .run(tauri::generate_context!())
    .expect("failed to run app");
}

2つの方法のうち、いずれかでプロジェクトへインポートできる。

// With the Tauri API npm package:
import { invoke } from '@tauri-apps/api/tauri'

または

// With the Tauri global script:
const invoke = window.__TAURI__.invoke

最後にイベントリスナに追加する。(または閉じたいときにinvokeを使って呼び出すだけです):)

document.addEventListener('DOMContentLoaded', () => {
  // This will wait for the window to load, but you could
  // run this function on whatever trigger you want
  invoke('close_splashscreen')
})

Waiting for Rust

サーバサイドでのRustコードの実行を待っているのであれば、setup関数ハンドラに置いて、Appインスタンスからアクセスできるようにする。

use tauri::Manager;
fn main() {
  tauri::Builder::default()
    .setup(|app| {
      let splashscreen_window = app.get_window("splashscreen").unwrap();
      let main_window = app.get_window("main").unwrap();
      // we perform the initialization code on a new task so the app doesn't freeze
      tauri::async_runtime::spawn(async move {
        // initialize your app here instead of sleeping :)
        println!("Initializing...");
        std::thread::sleep(std::time::Duration::from_secs(2));
        println!("Done initializing.");

        // After it's done, close the splashscreen and display the main window
        splashscreen_window.close().unwrap();
        main_window.show().unwrap();
      });
      Ok(())
    })
    .run(tauri::generate_context!())
    .expect("failed to run app");
}