Skip to content

Commit 331d42d

Browse files
committed
hsmodule: add compatibility code to upgrade the jumpstart script
1 parent 47af7bd commit 331d42d

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

extensions/les/LESmain.lua

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,79 @@
66
-- Distributed under the MIT software license, see the accompanying
77
-- file COPYING.txt or visit https://opensource.org/license/mit/
88

9+
-- Compatibility code used to upgrade LES's jumpstart routine if we're upgrading from
10+
-- older versions. To be retained for a maximum of two releases, after which it should
11+
-- be removed. We will not be including any modules defined by LES so we're going to be
12+
-- pretending the routines we defined don't exist.
13+
14+
-- CODE START
15+
function launchBashScript(script)
16+
local handle = io.popen(
17+
[[/bin/bash -c ']] .. script .. [[']]
18+
)
19+
local retcode = {handle:close()}
20+
return tonumber(retcode[3])
21+
end
22+
23+
function shouldMigrate()
24+
local fileHdl = io.open(os.getenv("HOME") .. "/.les/init.lua", "r")
25+
if fileHdl ~= nil then
26+
fileHdl:close()
27+
return launchBashScript(
28+
[[cmp "${HOME}/.les/init.lua" "]] .. hs.processInfo["bundlePath"] .. [[/Contents/Resources/extensions/hs/les/jumpstart.lua"]]
29+
) > 0
30+
else
31+
return false
32+
end
33+
end
34+
35+
if shouldMigrate() == true then
36+
if
37+
hs.dialog.blockAlert(
38+
"Live Enhancement Suite",
39+
[[
40+
LES has detected a mismatched jumpstart script.
41+
42+
This may be because you're upgrading from an older version of LES, if so, this is normal. Would you like to repair your jumpstart script?
43+
]],
44+
"Yes",
45+
"No"
46+
) == "Yes"
47+
then
48+
-- User has accepted repair
49+
if launchBashScript(
50+
[[
51+
#!/usr/bin/env bash
52+
set -eux
53+
mv "${HOME}/.les/init.lua" "${HOME}/.les/init.lua.bak";
54+
cp "]] .. hs.processInfo["bundlePath"] .. [[/Contents/Resources/extensions/hs/les/jumpstart.lua" "${HOME}/.les/init.lua";
55+
exit 0;
56+
]]
57+
) == 0 then
58+
-- Repair has succeeded
59+
hs.dialog.blockAlert("Live Enhancement Suite", "LES has successfully repaired the jumpstart script. Please restart LES for these changes to apply.", "Ok", "")
60+
os.exit()
61+
else
62+
-- Repair has failed
63+
hs.dialog.blockAlert("Live Enhancement Suite", "LES was unable to repair the jumpstart script. Please check permissions for ~/.les or clear the directory and try again.", "Ok", "")
64+
os.exit()
65+
end
66+
else
67+
-- User has refused repair, prompt for application exit
68+
if hs.dialog.blockAlert("Live Enhancement Suite", "LES cannot guarantee that it will behave as tested. Would you like to exit LES?", "Yes", "No") == "Yes" then
69+
-- User has chosen to exit
70+
os.exit()
71+
end
72+
-- User has chosen to continue despite warnings, unsupported
73+
end
74+
end
75+
76+
-- Un-define functions and free up variables
77+
launchBashScript = nil
78+
shouldMigrate = nil
79+
-- CODE END
80+
81+
-- Actual LESmain code
982
require("module")
1083
require("helpers")
1184
require("menus.bar")

extensions/les/jumpstart.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
-- Distributed under the MIT software license, see the accompanying
77
-- file COPYING.txt or visit https://opensource.org/license/mit/
88

9+
-- !!! DO NOT EDIT THIS FILE !!
10+
-- IT WILL CAUSE LES TO FLAG THE FILE AS MISMATCHED AGAINST THE COPY BUNDLED
11+
-- WITH IT. IF YOU'RE GOING TO CHANGE THIS FILE THEN COMMENT OUT COMPATIBILITY
12+
-- CODE IN LESMAIN.LUA
13+
914
bundlePath = hs.processInfo["bundlePath"]
1015
package.path = package.path .. ";" .. bundlePath .. [[/Contents/Resources/extensions/hs/les/?.lua]]
1116
dofile(bundlePath .. [[/Contents/Resources/extensions/hs/les/LESmain.lua]])

0 commit comments

Comments
 (0)