Originally posted by **shadow3aaa** June 11, 2024
I'm writing an rust ide on android.
Since tauri(2.0-beta) doesn't yet support mobile to use sidecar/resources, I use `rust_embed crate` to embed resources directly into the library.
Then I need to extract some resources(like proot, rootfs, prebuilted rust-analyzer, etc.) when the program starts and put them in a place like `/data/data/package_name/res`.
I want users to see the progress of resource extraction, So I do this(vue3):
- frontend
```typescript
import { ref, onMounted, onUnmounted } from "vue";
import { useRouter } from "vue-router";
import { VList, VListItem, VIcon } from "vuetify/components";
import { listen, UnlistenFn } from "@tauri-apps/api/event";
import { invoke } from "@tauri-apps/api/core";
interface Payload {
message: string;
}
let unlisten: UnlistenFn | null = null;
const router = useRouter();
const setupProcess = ref("Waiting until setup process complete...");
const setupCompleted = ref(false);
onMounted(async () => {
invoke("init_resources").then(() => {
setupCompleted.value = true;
});
unlisten = await listen("setup-process", (event) => {
const { message } = event.payload;
setupProcess.value += `\n${message}`;
});
});
onUnmounted(() => {
unlisten?.();
});
function routeToProjectView() {
router.push("/project");
}
```
- backend
`payload.rs`
```rust
#[derive(Clone, serde::Serialize)]
pub struct Payload {
message: String,
}
impl Payload {
pub fn new(message: String) -> Self {
Self { message }
}
}
```
`lib.rs`
```rust
#[tauri::command]
fn init_resources(app: AppHandle) {
app.emit("setup-process", Payload::new("Checking resources".into()))
.unwrap();
async_runtime::block_on(Resources::auto_update()).unwrap();
app.emit(
"setup-process",
Payload::new("Checking proot rootfs".into()),
)
.unwrap();
setup_rootfs().unwrap();
app.emit("setup-process", Payload::new("All done.".into()))
.unwrap();
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![init_resources])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```
However, when I was testing it, I found that no events were received, and if I tried to await listen, it just kept blocking current thread.
Discussed in https://github.com/tauri-apps/tauri/discussions/10033