A Tauri application with global state management. The local state for individual frontend windows is managed using Zustand, while the global state is managed and synced across all frontend windows using the Rust backend.
Project Root
├── scripts
│ └── generate-macros.py
├── src
│ ├── assets
│ ├── constants
│ │ ├── events.ts
│ │ ├── global.ts
│ │ └── index.ts
│ ├── states
│ │ └── global-state.ts
│ ├── types
│ │ └── state.ts
│ ├── App.tsx
│ ├── App.css
│ ├── main.tsx
│ ├── styles.css
│ └── vite-env.d.ts
├── src-tauri
│ ├── src
│ │ ├── autogen
│ │ │ └── constants.rs
│ │ ├── states
│ │ │ └── states.rs
│ │ └── main.rs
│ └── ... other files and folders
└── ... other files and folders
Clone the repository:
git clone https://github.com/robosushie/tauri-global-state-management.git
Navigate into the project directory:
cd tauri-global-state-management
Install the dependencies:
pnpm install
Generate the Rust constants and enums:
pnpm run autogen
Start the Tauri application in development mode:
pnpm run dev
You can interact with the frontend by clicking the increment, decrement, and toggle buttons. The global state should be updated and synced across all frontend windows.
-
Add a STATE_FETCH event to fetch the state when different frontend windows come up at different times. This will also be useful when a webview window comes up after a crash.
-
Convert this into a single plugin with most of the backend state management code written with autogeneration.
This project is licensed under the MIT License.