fireDesktopFile

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

  1. void fireDesktopFile(IniLikeReader reader, string fileName, FireOptions options)
    void
    fireDesktopFile
    (
    IniLikeReader
    )
    (
    IniLikeReader reader
    ,
    string fileName = null
    ,)
  2. void fireDesktopFile(string fileName, FireOptions options)

Parameters

reader IniLikeReader

inilike.range.IniLikeReader returned by inilike.range.iniLikeRangeReader or similar function.

fileName string

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 inilike.range.IniLikeReader was constructed.

options FireOptions

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.

Examples

1 string contents;
2 FireOptions options;
3 
4 contents = "[Desktop Entry]\nURL=testurl";
5 options.flags = FireOptions.FollowLink;
6 assertThrown(fireDesktopFile(iniLikeStringReader(contents), null, options));
7 
8 contents = "[Group]\nKey=Value";
9 options = FireOptions.init;
10 assertThrown(fireDesktopFile(iniLikeStringReader(contents), null, options));
11 
12 contents = "[Desktop Entry]\nURL=testurl";
13 options = FireOptions.init;
14 bool wasCalled;
15 options.opener = delegate void (string url) {
16     assert(url == "testurl");
17     wasCalled = true;
18 };
19 
20 fireDesktopFile(iniLikeStringReader(contents), null, options);
21 assert(wasCalled);
22 
23 contents = "[Desktop Entry]";
24 options = FireOptions.init;
25 assertThrown(fireDesktopFile(iniLikeStringReader(contents), null, options));
26 
27 contents = "[Desktop Entry]\nURL=testurl";
28 options.flags = FireOptions.Exec;
29 assertThrown(fireDesktopFile(iniLikeStringReader(contents), null, options));
30 
31 contents = "[Desktop Entry]\nExec=whoami";
32 options.flags = FireOptions.Link;
33 assertThrown(fireDesktopFile(iniLikeStringReader(contents), null, options));
34 
35 version(desktopfileFileTest) static if (isFreedesktop) {
36     try {
37         contents = "[Desktop Entry]\nExec=whoami\nTerminal=true";
38         options.flags = FireOptions.Exec;
39         wasCalled = false;
40         options.terminalDetector = delegate string[] () {wasCalled = true; return null;};
41         fireDesktopFile(iniLikeStringReader(contents), null, options);
42         assert(wasCalled);
43 
44         string tempPath = buildPath(tempDir(), "desktopfile-unittest-tempdir");
45         if (!tempPath.exists) {
46             mkdir(tempPath);
47         }
48         scope(exit) rmdir(tempPath);
49 
50         string tempDesktopFile = buildPath(tempPath, "followtest.desktop");
51         auto f = File(tempDesktopFile, "w");
52         scope(exit) remove(tempDesktopFile);
53         f.rawWrite("[Desktop Entry]\nURL=testurl");
54         f.flush();
55 
56         contents = "[Desktop Entry]\nURL=" ~ tempDesktopFile;
57         options.flags = FireOptions.Link | FireOptions.FollowLink;
58         options.opener = delegate void (string url) {
59             assert(url == "testurl");
60             wasCalled = true;
61         };
62 
63         fireDesktopFile(iniLikeStringReader(contents), null, options);
64         assert(wasCalled);
65     } catch(Exception e) {
66 
67     }
68 }

See Also

Meta