fireDesktopFile - multiple declarations

Function fireDesktopFile

Read the desktop file and run application or open link depending on the type of the given desktop file.

void fireDesktopFile(IniLikeReader) (
  IniLikeReader reader,
  string fileName = null,
  FireOptions options = FireOptions.init
);

Parameters

NameDescription
reader IniLikeReader returned by iniLikeRangeReader or similar function.
fileName file name of desktop file where data read from. Can be used in field code expanding, should be set to the file name from which contents IniLikeReader was constructed.
options options that set behavior of the function. Use this function to execute desktop file fast, without creating of DesktopFile instance.

Throws

ProcessException on failure to start the process. DesktopExecException if exec string is invalid. Exception on other errors.

See Also

FireOptions, spawnApplication, getTerminalCommand

Example

string contents;
FireOptions options;

contents = "[Desktop Entry]\nURL=testurl";
options.flags = FireOptions.FollowLink;
assertThrown(fireDesktopFile(iniLikeStringReader(contents), null, options));

contents = "[Group]\nKey=Value";
options = FireOptions.init;
assertThrown(fireDesktopFile(iniLikeStringReader(contents), null, options));

contents = "[Desktop Entry]\nURL=testurl";
options = FireOptions.init;
bool wasCalled;
options.opener = delegate void (string url) {
    assert(url == "testurl");
    wasCalled = true;
};

fireDesktopFile(iniLikeStringReader(contents), null, options);
assert(wasCalled);

contents = "[Desktop Entry]";
options = FireOptions.init;
assertThrown(fireDesktopFile(iniLikeStringReader(contents), null, options));

contents = "[Desktop Entry]\nURL=testurl";
options.flags = FireOptions.Exec;
assertThrown(fireDesktopFile(iniLikeStringReader(contents), null, options));

contents = "[Desktop Entry]\nExec=whoami";
options.flags = FireOptions.Link;
assertThrown(fireDesktopFile(iniLikeStringReader(contents), null, options));

version(desktopfileFileTest) static if (isFreedesktop) {
    try {
        contents = "[Desktop Entry]\nExec=whoami\nTerminal=true";
        options.flags = FireOptions.Exec;
        wasCalled = false;
        options.terminalDetector = delegate string[] () {wasCalled = true; return null;};
        fireDesktopFile(iniLikeStringReader(contents), null, options);
        assert(wasCalled);

        string tempPath = buildPath(tempDir(), "desktopfile-unittest-tempdir");
        if (!tempPath.exists) {
            mkdir(tempPath);
        }
        scope(exit) rmdir(tempPath);

        string tempDesktopFile = buildPath(tempPath, "followtest.desktop");
        auto f = File(tempDesktopFile, "w");
        scope(exit) remove(tempDesktopFile);
        f.rawWrite("[Desktop Entry]\nURL=testurl");
        f.flush();

        contents = "[Desktop Entry]\nURL=" ~ tempDesktopFile;
        options.flags = FireOptions.Link | FireOptions.FollowLink;
        options.opener = delegate void (string url) {
            assert(url == "testurl");
            wasCalled = true;
        };

        fireDesktopFile(iniLikeStringReader(contents), null, options);
        assert(wasCalled);
    } catch(Exception e) {

    }
}

Function fireDesktopFile

ditto, but automatically create IniLikeReader from the file.

void fireDesktopFile (
  string fileName,
  FireOptions options = FireOptions(7, null, null, null, null, true)
) @trusted;