-
Notifications
You must be signed in to change notification settings - Fork 355
WASM Improvements #5838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Marcel-Nordeck
wants to merge
4
commits into
matrix-org:main
Choose a base branch
from
Marcel-Nordeck:MTRNord/wasm-improvements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−51
Open
WASM Improvements #5838
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
463589e
fix(matrix-sdk-ffi): remove bundled-sqlite from default features
MTRNord b87c179
fix(matrix-sdk-ffi): fix depenendencies for the wasm bindings
MTRNord a964f09
fix(matrix-sdk-ffi): add missing wasm stubs
MTRNord fd93a0f
chore: remove return keywords as per clippy warnings
MTRNord File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -928,7 +928,6 @@ impl Client { | |
| } | ||
| } | ||
|
|
||
| #[cfg(not(target_family = "wasm"))] | ||
| #[matrix_sdk_ffi_macros::export] | ||
| impl Client { | ||
| /// Retrieves a media file from the media source | ||
|
|
@@ -942,22 +941,54 @@ impl Client { | |
| use_cache: bool, | ||
| temp_dir: Option<String>, | ||
| ) -> Result<Arc<MediaFileHandle>, ClientError> { | ||
| let source = (*media_source).clone(); | ||
| let mime_type: mime::Mime = mime_type.parse()?; | ||
| #[cfg(not(target_family = "wasm"))] | ||
| { | ||
| let source = (*media_source).clone(); | ||
| let mime_type: mime::Mime = mime_type.parse()?; | ||
|
|
||
| let handle = self | ||
| .inner | ||
| .media() | ||
| .get_media_file( | ||
| &MediaRequestParameters { source: source.media_source, format: MediaFormat::File }, | ||
| filename, | ||
| &mime_type, | ||
| use_cache, | ||
| temp_dir, | ||
| ) | ||
| .await?; | ||
| let handle = self | ||
| .inner | ||
| .media() | ||
| .get_media_file( | ||
| &MediaRequestParameters { | ||
| source: source.media_source, | ||
| format: MediaFormat::File, | ||
| }, | ||
| filename, | ||
| &mime_type, | ||
| use_cache, | ||
| temp_dir, | ||
| ) | ||
| .await?; | ||
|
Comment on lines
+949
to
+962
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A comment explaining why this doesn't work would be nice. I guess it's because of the usage of the temp dir. |
||
|
|
||
| Ok(Arc::new(MediaFileHandle::new(handle))) | ||
| } | ||
|
|
||
| Ok(Arc::new(MediaFileHandle::new(handle))) | ||
| #[cfg(target_family = "wasm")] | ||
| Err(ClientError::Generic { | ||
| msg: "get_media_file is not supported on wasm platforms".to_owned(), | ||
| details: None, | ||
| }) | ||
| } | ||
|
|
||
| pub async fn set_display_name(&self, name: String) -> Result<(), ClientError> { | ||
| #[cfg(not(target_family = "wasm"))] | ||
| { | ||
| self.inner | ||
| .account() | ||
| .set_display_name(Some(name.as_str())) | ||
| .await | ||
| .context("Unable to set display name")?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[cfg(target_family = "wasm")] | ||
| { | ||
| Err(ClientError::Generic { | ||
| msg: "set_display_name is not supported on wasm platforms".to_owned(), | ||
| details: None, | ||
| }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1093,15 +1124,6 @@ impl Client { | |
| Ok(display_name) | ||
| } | ||
|
|
||
| pub async fn set_display_name(&self, name: String) -> Result<(), ClientError> { | ||
| self.inner | ||
| .account() | ||
| .set_display_name(Some(name.as_str())) | ||
| .await | ||
| .context("Unable to set display name")?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub async fn upload_avatar(&self, mime_type: String, data: Vec<u8>) -> Result<(), ClientError> { | ||
| let mime: Mime = mime_type.parse()?; | ||
| self.inner.account().upload_avatar(&mime, data).await?; | ||
|
|
@@ -2453,25 +2475,25 @@ fn gen_transaction_id() -> String { | |
|
|
||
| /// A file handle that takes ownership of a media file on disk. When the handle | ||
| /// is dropped, the file will be removed from the disk. | ||
| #[cfg(not(target_family = "wasm"))] | ||
| #[derive(uniffi::Object)] | ||
| pub struct MediaFileHandle { | ||
| #[cfg(not(target_family = "wasm"))] | ||
| inner: std::sync::RwLock<Option<SdkMediaFileHandle>>, | ||
| } | ||
|
|
||
| #[cfg(not(target_family = "wasm"))] | ||
| impl MediaFileHandle { | ||
| #[cfg(not(target_family = "wasm"))] | ||
| fn new(handle: SdkMediaFileHandle) -> Self { | ||
| Self { inner: std::sync::RwLock::new(Some(handle)) } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(not(target_family = "wasm"))] | ||
| #[matrix_sdk_ffi_macros::export] | ||
| impl MediaFileHandle { | ||
| /// Get the media file's path. | ||
| pub fn path(&self) -> Result<String, ClientError> { | ||
| Ok(self | ||
| #[cfg(not(target_family = "wasm"))] | ||
| return Ok(self | ||
| .inner | ||
| .read() | ||
| .unwrap() | ||
|
|
@@ -2480,24 +2502,37 @@ impl MediaFileHandle { | |
| .path() | ||
| .to_str() | ||
| .unwrap() | ||
| .to_owned()) | ||
| .to_owned()); | ||
| #[cfg(target_family = "wasm")] | ||
| Err(ClientError::Generic { | ||
| msg: "MediaFileHandle.path() is not supported on WASM targets".to_string(), | ||
| details: None, | ||
| }) | ||
| } | ||
|
|
||
| pub fn persist(&self, path: String) -> Result<bool, ClientError> { | ||
| let mut guard = self.inner.write().unwrap(); | ||
| Ok( | ||
| match guard | ||
| .take() | ||
| .context("MediaFileHandle was already persisted")? | ||
| .persist(path.as_ref()) | ||
| { | ||
| Ok(_) => true, | ||
| Err(e) => { | ||
| *guard = Some(e.file); | ||
| false | ||
| } | ||
| }, | ||
| ) | ||
| #[cfg(not(target_family = "wasm"))] | ||
| { | ||
| let mut guard = self.inner.write().unwrap(); | ||
| Ok( | ||
| match guard | ||
| .take() | ||
| .context("MediaFileHandle was already persisted")? | ||
| .persist(path.as_ref()) | ||
| { | ||
| Ok(_) => true, | ||
| Err(e) => { | ||
| *guard = Some(e.file); | ||
| false | ||
| } | ||
| }, | ||
| ) | ||
| } | ||
| #[cfg(target_family = "wasm")] | ||
| Err(ClientError::Generic { | ||
| msg: "MediaFileHandle.persist() is not supported on WASM targets".to_string(), | ||
| details: None, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary? Can't you use
--no-default-featuresto get the feature set you'd want/need on Wasm?Why not? The defaults are here to serve the most common use-case. Having only the memory store by default seems like a worse situation.
The
matrix-sdkcrate also enables SQLite support by default, even though it ~always supported IndexedDB.