|
6 | 6 | -- Distributed under the MIT software license, see the accompanying |
7 | 7 | -- file COPYING.txt or visit https://opensource.org/license/mit/ |
8 | 8 |
|
| 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 |
9 | 82 | require("module") |
10 | 83 | require("helpers") |
11 | 84 | require("menus.bar") |
|
0 commit comments