--   This file is part of Reno desktop.
--
--  Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
--
--  Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
--
--  You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>. 
-- XFCE style autostart system
local awful = require("awful")
local gears = require("gears")
local gfs = gears.filesystem
local menu_utils = require("menubar.utils")
local stdir = "/tmp/.awesome_startup/"
gfs.make_directories(stdir)
awful.spawn.with_line_callback("find "..gfs.get_xdg_config_home().."autostart/ -name *.desktop",{
    stdout = function(line)
        local data = menu_utils.parse_desktop_file(line)
        if (data.RunHook == "0") or (data.RunHook == nil) then
            if not gfs.file_readable(stdir..line:match("[^/]*$")) then
                io.open(stdir..line:match("[^/]*$"),"w"):close()
                awful.spawn(data.Exec)
            end
        end
    end
})
