Skip to content

Conversation

@BharatAtbrat
Copy link
Contributor

@BharatAtbrat BharatAtbrat commented Jun 11, 2024

Added Vala code for File Monitor

Issues:

  • File.replace_contents_async does not work well and inserts non-readable text inside the workbench.txt file, it also shows an additional error stating that I don't have permission to open the the file.
  • Using File.replace_contents instead seems to work correctly.
  • The Python demo also has the same effect and uses the async method.

Screengrab of the error attached:

Screenshot from 2024-06-11 19-14-28

Note: The Javascript demo works normally and it uses the replace_contents_async

  • Using switch case gives a warning that causes the checks to fail, Js and Python demos both use switch case.

Let me know if there are any other issues with the code :)

Add Vala code for File Monitor
@Diego-Ivan
Copy link
Contributor

File.replace_contents_async does not work well and inserts non-readable text inside the workbench.txt file, it also shows an additional error stating that I don't have permission to open the the file

I tested the async method and it worked fine, and the error doesn't sound related to the async/not async method. Could you share the piece of code where the async method fails, please?

@BharatAtbrat
Copy link
Contributor Author

File.replace_contents_async does not work well and inserts non-readable text inside the workbench.txt file, it also shows an additional error stating that I don't have permission to open the the file

I tested the async method and it worked fine, and the error doesn't sound related to the async/not async method. Could you share the piece of code where the async method fails, please?

This is the code:

    edit_file.clicked.connect (() => {
        string byte_string = buffer.text;
        uint8[] bytes = byte_string.data;
        file.replace_contents_async.begin (
                                           bytes, // contents
                                           null, // etag
                                           false, // make_backup
                                           FileCreateFlags.REPLACE_DESTINATION, // flags
                                           null, // new_etag
                                           null // cancellable
        );
    });

and a screengrab of what the text editor says:

2024-06-13.11-53-34.1.mp4

There is no warning/error in the console, and the operation is completed successfully.

Use property for TextBuffer
Add default case to switch (Fixes compiler warnings)
Use file.replace_contents_async instead of replace_contents
@BharatAtbrat BharatAtbrat requested a review from Diego-Ivan June 14, 2024 06:51
@Diego-Ivan
Copy link
Contributor

Move the handler to a separate async method and call file.replace_contents_async using yield. That worked for me, but I'm not sure why using .begin fails.

@BharatAtbrat
Copy link
Contributor Author

BharatAtbrat commented Jun 14, 2024

Move the handler to a separate async method and call file.replace_contents_async using yield. That worked for me, but I'm not sure why using .begin fails.

@Diego-Ivan Works with your approach, added the commit! I am also not sure about why .begin doesn't work either

@sonnyp
Copy link
Contributor

sonnyp commented Jun 24, 2024

What's the status here?

@BharatAtbrat BharatAtbrat requested a review from Diego-Ivan June 25, 2024 16:03
Copy link
Contributor

@Diego-Ivan Diego-Ivan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sonnyp sonnyp merged commit 644fb6b into workbenchdev:main Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants