Skip to content

Commit

Permalink
hsmodule: add replacement logic for init.lua when upgrading
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed May 21, 2023
1 parent 60786ce commit bc26f2d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
34 changes: 0 additions & 34 deletions extensions/les/LESmain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ if console then
console:close()
end -- if the console is up, close the console. This workaround prevents hammerspoon from shoving the console in your face at startup.

testOrSetCurVersion()

----------------------
-- Initialisation --
----------------------
Expand Down Expand Up @@ -98,38 +96,6 @@ if testfirstrun() == false then -- stuff to do when you start the program for th
end
end

----------------
-- Updating --
----------------

-- updating LES using the installer basically only replaces the .app file in your applications folder with the new one.
-- this area of the script makes sure that the init.lua script file is replaced again if I ever make a change to it.
-- the init.lua file is not THIS file, it's the redirect that's dropped into ~/.les.

function testOrSetCurVersion(ver)
local ver = ver or nil
local filepath = GetDataPath("resources/version.txt")
local filehandle = io.open(filepath, "r")
if filehandle ~= nil or ver ~= nil then
local versionarr = {}
for line in filehandle:lines() do
table.insert(versionarr, line);
end
for i = 1, 1, 1 do
if string.match(versionarr[i], ver) then
return true
else
return false
end
end
io.close(filehandle)
return false
else
ShellOverwriteFile(programVersion, JoinPaths(ScriptUserResourcesPath, VersionFile))
return true
end
end

------------------------
-- Integrity checks --
------------------------
Expand Down
32 changes: 32 additions & 0 deletions extensions/les/modinit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require("helpers")
require("proccom")
require("globals.constants")
require("globals.filepaths")

-- TODO: Make them "global" within an app-specific context
-- We should try and do away with _true_ globals as much as we can
Expand Down Expand Up @@ -191,4 +192,35 @@ function initModule()
end
end)
end

-- Upgrade from previous version
function setCurVersion()
ShellOverwriteFile(programVersion, JoinPaths(ScriptUserResourcesPath, VersionFile))
end

function testCurVersion()
local filepath = GetDataPath("resources/version.txt")
local filehandle = io.open(filepath, "r")
if filehandle ~= nil then
local versionarr = {}
for line in filehandle:lines() do
table.insert(versionarr, line);
end
io.close(filehandle)
for i = 1, 1, 1 do
return string.match(versionarr[i], programVersion) ~= nil
end
else
setCurVersion()
return true
end
return false
end

if testCurVersion() == false then
ShellCopy(JoinPaths(BundleResourcePath, "jumpstart.lua"), GetDataPath("init.lua"))
setCurVersion()
print("initModule(): upgraded init.lua present in home directory")
hs.reload()
end
end

0 comments on commit bc26f2d

Please sign in to comment.