Big rewrite part 1
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
local lgi = require('lgi')
|
||||
local GLib = lgi.GLib
|
||||
local Gio = lgi.Gio
|
||||
local assert = assert
|
||||
local error = error
|
||||
local io = io
|
||||
local pairs = pairs
|
||||
|
||||
-- Awesome libs
|
||||
local aspawn = require('awful.spawn')
|
||||
local gfilesystem = require('gears.filesystem')
|
||||
local gobject = require('gears.object')
|
||||
local gtable = require('gears.table')
|
||||
local gfilesystem = require('gears.filesystem')
|
||||
local aspawn = require('awful.spawn')
|
||||
|
||||
-- Third party libs
|
||||
local json = require('src.lib.json-lua.json-lua')
|
||||
|
||||
local config = {}
|
||||
|
||||
local instance
|
||||
|
||||
---Takes a file path and puts the content into the callback
|
||||
---@param path string file path, caller has to make sure it exists
|
||||
---@return string|nil file_content
|
||||
@@ -58,30 +60,31 @@ config.write_json = function(path, content)
|
||||
handler:close()
|
||||
end
|
||||
|
||||
local function new()
|
||||
local ret = gobject {}
|
||||
|
||||
gtable.crush(ret, config, true)
|
||||
|
||||
-- Create config files if they don't exist
|
||||
for _, file in pairs { 'floating.json', 'dock.json', 'desktop.json', 'applications.json' } do
|
||||
if not gfilesystem.file_readable(gfilesystem.get_configuration_dir() .. 'src/config/' .. file) then
|
||||
aspawn('touch ' .. gfilesystem.get_configuration_dir() .. 'src/config/' .. file)
|
||||
end
|
||||
end
|
||||
|
||||
-- Create config directories if they don't exist
|
||||
for _, dir in pairs { 'files/desktop/icons' } do
|
||||
if not gfilesystem.dir_readable(gfilesystem.get_configuration_dir() .. 'src/config/' .. dir) then
|
||||
gfilesystem.make_directories(gfilesystem.get_configuration_dir() .. 'src/config/' .. dir)
|
||||
end
|
||||
end
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
local instance = nil
|
||||
if not instance then
|
||||
instance = new()
|
||||
instance = setmetatable(config, {
|
||||
__call = function()
|
||||
local ret = gobject {}
|
||||
|
||||
gtable.crush(ret, config, true)
|
||||
|
||||
-- Create config files if they don't exist
|
||||
for _, file in pairs { 'floating.json', 'dock.json', 'desktop.json', 'applications.json' } do
|
||||
if not gfilesystem.file_readable(gfilesystem.get_configuration_dir() .. 'src/config/' .. file) then
|
||||
aspawn('touch ' .. gfilesystem.get_configuration_dir() .. 'src/config/' .. file)
|
||||
end
|
||||
end
|
||||
|
||||
-- Create config directories if they don't exist
|
||||
for _, dir in pairs { 'files/desktop/icons' } do
|
||||
if not gfilesystem.dir_readable(gfilesystem.get_configuration_dir() .. 'src/config/' .. dir) then
|
||||
gfilesystem.make_directories(gfilesystem.get_configuration_dir() .. 'src/config/' .. dir)
|
||||
end
|
||||
end
|
||||
|
||||
return ret
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
return instance
|
||||
|
||||
Reference in New Issue
Block a user