Skip to content
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

Port 'File Monitor' demo to Vala #175

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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
src/File Monitor/main.vala Outdated Show resolved Hide resolved
src/File Monitor/main.vala Show resolved Hide resolved
@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
@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

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.

None yet

2 participants