#Tauri #Rust
## 📚ドキュメント
- [Slackのmessage.search API](https://api.slack.com/methods/search.messages/test)
- [Carbon Componentsのドキュメント](https://carbon-components-svelte.onrender.com/)
## やりたいことリスト
- [x] [[🦉Owlelia]]のインストール
- [x] 時刻をJSTにする
- [x] 設定ファイルをローカルで管理する
- [x] [[Tauri]]のStoreを実装する
- [x] 自分へのメンションを表示
- [x] ログインユーザー取得APIの作成
- [x] [[Slack Web API]]で取得する方法の調査
- [x] [[Slack Web API]]の調査
- [x] [[Rust]]に実装
- [x] エゴサーチ画面
- [x] 検索の並列化
- [x] textを[[Slack]]のようにフォーマットする (絵文字、リンク、etc)
- [x] `text`ではなく別のプロパティを使うのでその調査
- [x] [[Svelte]]のテンプレートで条件分岐するコンポーネント作成
- [x] ユーザー一覧APIの作成
- [x] [[Slack Web API]]の調査
- [x] [[Rust]]に実装
- [x] [[Svelte]]でユーザー表示に対応
- [x] 絵文字一覧APIの作成
- [x] [[Slack Web API]]の調査
- [x] [[Rust]]に実装
- [x] [[TypeScript]]で起動時に取得
- [x] [[Svelte]]で絵文字表示に対応
- [x] 定期実行でエゴサーチした結果を表示する
- [x] Notificationの追加
- [ ] 認証情報の管理
- [ ] attachment
- [ ] 既読・未読管理
- [ ] [[Slack Web API]]で既読にさせられるか確認 (できたらそれで)
## メモ
- [[Tauri]]もhome_dir関数を持っている
- 今回は[[BFF]]に徹してみるか.. [[Rust]]の勉強がモチベでもあるし
### Stateの書き込みについて
https://github.com/tauri-apps/tauri/discussions/1336#discussioncomment-1936523
MutextとFutureの相性が悪くてまずそう。。
```
future cannot be sent between threads safely Help: within `impl std::future::Future<Output = std::result::Result<(), std::string::String>>`, the trait `std::marker::Send` is not implemented for `std::sync::MutexGuard<'_, InnerPolarisState>` Note: future is not `Send` as this value is used across an await Note: `state.0.lock().unwrap()` is later dropped here Note: required by a bound in `tauri::command::private::ResultFutureTag::future`
```
Issueはある
https://github.com/tauri-apps/tauri/issues/2891
`tauri::async_runtime::block_on`を使えたと。
```rust
#[tauri::command]
async fn search_messages(
state: tauri::State<'_, PolarisState>,
query: String,
) -> Result<action::search_messages::Response, String> {
action::search_messages::exec(
state.0.lock().unwrap().config.slack_token.as_str(), query
)
.await
.map_err(|e| e.to_string())
}
```
↓
```rust
#[tauri::command]
async fn search_messages(
state: tauri::State<'_, PolarisState>,
query: String,
) -> Result<action::search_messages::Response, String> {
tauri::async_runtime::block_on(
action::search_messages::exec(
state.0.lock().unwrap().config.slack_token.as_str(), query
)
)
.map_err(|e| e.to_string())
}
```
実行
```
thread 'tokio-runtime-worker' panicked at 'Cannot start a runtime from within a runtime. This happens because a function (like `block_on`) attempted to block the current thread while the thread is being used to drive asynchronous tasks.', C:\Users\tadashi-aikawa\scoop\persist\rustup\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.17.0\src\runtime\enter.rs:39:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
`async`の外し忘れだ。。`async fn`を`fn`にする。
通信したまま固まってしまう。。
```rust
#[tauri::command]
fn get_by_name_mentioned_messages(
state: tauri::State<'_, PolarisState>,
) -> Result<action::search_messages::Response, String> {
let state_guard = state.0.lock().unwrap();
let current_user: Option<&User> = state_guard.current_user.as_ref();
let query = format!("@{}", current_user.unwrap().display_name);
tauri::async_runtime::block_on(
action::search_messages::exec(
state.0.lock().unwrap().config.slack_token.as_str(), query
)
)
.map_err(|e| e.to_string())
}
```
↓ `state_guard`を束縛したあと、`async_runtime::block_on`の中で呼び出していたのが原因ぽい。(詳細は分からん。。)
```rust
#[tauri::command]
fn get_by_name_mentioned_messages(
state: tauri::State<'_, PolarisState>,
) -> Result<action::search_messages::Response, String> {
let state_guard = state.0.lock().unwrap();
let current_user: Option<&User> = state_guard.current_user.as_ref();
let query = format!("@{}", current_user.unwrap().display_name);
let token = state_guard.config.slack_token.as_str();
tauri::async_runtime::block_on(action::search_messages::exec(token, query))
.map_err(|e| e.to_string())
}
```
## blocks解析
- type: `rich_text`
- block_id
- elements: []
- その1
- type: `rich_text_section` の場合
- elements: []
- type: `emoji`
name: `hina`
- type: `text`
text: `ほげほげ`
style?:
code?: `true` (コードブロック)
bold?: `true` (太字)
- type: `link`
url: `....`
- type: `channel`
channel_id: `AB.....`
style?: ...
- その2
- type: `rich_text_list` の場合
- style: `bullet`
- indent: `0` (1ずつ増える)
- elements: []
- type: `rich_text_section`
elements: []
- その3
- type: `rich_text_preformatted` の場合
- elements: []
- type: `text`
text: `.........`
- border: `0`
## [[Tauri]]をrc5 -> rc10へバージョンアップ
https://tauri.studio/release-notes
### 問題1
```
`tauri.conf.json` error on `tauri > bundle > deb`: Additional property 'useBootstrapper' is not allowed
`tauri.conf.json` error on `tauri > bundle > macOS`: Additional property 'useBootstrapper' is not allowed
```
該当プロパティを消してみる。
### 問題2
```
thread 'main' panicked at 'error found during tauri-build: unknown field `tsp`, expected one of `digestAlgorithm`, `certificateThumbprint`, `timestampUrl`, `webviewFixedRuntimePath`, `wix` at line 1 column 888', C:\Users\tadashi-aikawa\scoop\persist\rustup\.cargo\registry\src\github.com-1ecc6299db9ec823\tauri-build-1.0.0-rc.3\src\lib.rs:146:5
```
[[Cargo.toml]]で`tauri`のバージョンを変更していなかった(`rc.3`のままだった)。それぞれ最新に変更。
```toml
[build-dependencies]
tauri-build = { version = "1.0.0-rc.5", features = [] }
[dependencies]
tauri = { version = "1.0.0-rc.6", features = ["notification-all", "shell-open"] }
```
## OAuth対応
- [[📜TauriでOAuth2.0認証を実現する]]
- [[📜SlackでOAuth2.0認証してみる]]