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

notes@schorschii: Warning when adding desklet: "This desklet contains function calls that could potentially cause Cinnamon to crash or freeze" #428

Closed
jeremy21212121 opened this issue May 11, 2019 · 2 comments

Comments

@jeremy21212121
Copy link

After installing notes@schorschii, there is a warning in the Desklets UI: "This desklet contains function calls that could potentially cause Cinnamon to crash or freeze".

I found the function calls that trigger that warning here. The specific function call triggering this warning in notes is Cinnamon.get_file_contents_utf8_sync().

I changed two instances of that function call to String(GLib.file_get_contents("/path/to/yourFile")[1]), and that removed the error.

But then it dawned on me, perhaps that warning is there because a synchronous file read, in general, has the potential to crash Cinnamon (ie. if the file is really large). If that were the case, then using GLib.file_get_contents() instead of Cinnamon.get_file_contents_utf8_sync() would just be working around the warning but not actually fixing the underlying reason for the warning. Reading the commit message here confirmed my suspicion that synchronous file reads are the issue.

Reading the source code for Cinnamon.get_file_contents_utf8_sync(), it appears to just be using Glib's file_get_contents under the hood, combined with a few sanity checks.

So, if I wanted to actually fix the underlying reason for that warning, do I need to use an asynchronous file read function? I think that would not be practical, as the whole desklet seems to be inherently synchronous. Or would it suffice to just check the size of the text file before attempting to load it?

Thanks in advance. I'm a JS dev, but this is my first time diving into desklet/applet dev.

@Odyseus
Copy link
Contributor

Odyseus commented May 12, 2019

Hello, @jeremy21212121.

That message that you see is a warning, not an error. It's mostly there so, in the case of a Cinnamon crash/freeze/lock, you start looking the xlets that have that warning as possible culprits.

Using a synchronous file read function isn't inherently bad and not always is possible to replace with an asynchronous call. In fact, Cinnamon.get_file_contents_utf8_sync() is used by Cinnamon itself in several places.

Replacing the call to Cinnamon.get_file_contents_utf8_sync() with a call to GLib.file_get_contents() as you did might have removed the warning, but the possible problem that that message was warning you about is still there (a call to a synchronous file read function).

If you actually want to "fix" the issue, you could just use an asynchronous file read function. I have been using Gio.File.load_contents_async() in all my xlets for years now. Basic example usage:

let file = Gio.file_new_for_path("/path/to/file");
file.load_contents_async(null, (aFile, aResponce) => {
    let success,
        contents,
        tag;

    try {
        [success, contents, tag] = aFile.load_contents_finish(aResponce);
    } catch (aErr) {
        global.logError(aErr.message);
        return;
    }

    if (!success) {
        global.logError("Error reading file.");
        return;
    }

    global.log(contents);
});

@NikoKrause
Copy link
Member

ping author @schorschii

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

No branches or pull requests

3 participants