Skip to content

Commit

Permalink
Also check for Maple updates when checking for Ahorn updates
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 committed Oct 4, 2023
1 parent c400bd9 commit e0d3e8f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 36 deletions.
3 changes: 1 addition & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ and only contains the latest changes.
Its purpose is to be shown in Olympus when updating.

#changelog#
∙ Added the ground work for the future Flatpak package
∙ Fixed 1-click installing on Linux
∙ Also check for Maple updates when checking for Ahorn updates
18 changes: 9 additions & 9 deletions sharp/AhornHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,25 +323,25 @@ public static string GetJuliaVersion() {
return GetJuliaOutput(@"println(VERSION)", out _);
}

public static string GetAhornPkgVersion() {
return GetJuliaOutput(PrefixPkgActivate + @"
public static string GetPkgVersion(string package) {
return GetJuliaOutput(PrefixPkgActivate + $@"
if !(""Ahorn"" ∈ keys(Pkg.installed()))
return
end
try
local ctx = Pkg.Types.Context()
println(string(ctx.env.manifest[ctx.env.project.deps[""Ahorn""]].tree_hash))
println(string(ctx.env.manifest[ctx.env.project.deps[""{package}""]].tree_hash))
catch e
println(""?"")
end
", out _);
}

public static string GetAhornVersion() {
public static string GetVersion(string package) {
string path = AhornPath;
if (string.IsNullOrEmpty(path) || !File.Exists(path))
return GetAhornPkgVersion() + " (pkg)";
return GetPkgVersion(package) + " (pkg)";

// julia-depot/packages/Ahorn/*/src/Ahorn.jl
path = Path.GetDirectoryName(path); // julia-depot/packages/Ahorn/*/src
Expand All @@ -350,11 +350,11 @@ public static string GetAhornVersion() {
path = Path.GetDirectoryName(path); // julia-depot/packages
path = Path.GetDirectoryName(path); // julia-depot
if (string.IsNullOrEmpty(path) || !Directory.Exists(path))
return GetAhornPkgVersion() + " (pkg)";
return GetPkgVersion(package) + " (pkg)";

path = Path.Combine(path, "clones");
if (!Directory.Exists(path))
return GetAhornPkgVersion() + " (pkg)";
return GetPkgVersion(package) + " (pkg)";

foreach (string clone in Directory.EnumerateDirectories(path)) {
string config = Path.Combine(clone, "config");
Expand All @@ -364,7 +364,7 @@ public static string GetAhornVersion() {
using (StreamReader reader = new StreamReader(stream)) {
if (!reader.ReadLineUntil("[remote \"origin\"]"))
continue;
if (reader.ReadLine()?.Trim() != "url = https://github.com/CelestialCartographers/Ahorn.git")
if (reader.ReadLine()?.Trim() != $"url = https://github.com/CelestialCartographers/{package}.git")
continue;
}

Expand All @@ -383,7 +383,7 @@ public static string GetAhornVersion() {
}
}

return GetAhornPkgVersion() + " (pkg)";
return GetPkgVersion(package) + " (pkg)";
}

}
Expand Down
4 changes: 3 additions & 1 deletion sharp/CmdAhornGetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public class Info {
public string AhornEnvPath = AhornHelper.AhornEnvPath;
public string AhornPath = AhornHelper.AhornPath;
public bool AhornIsLocal = AhornHelper.AhornIsLocal;
public string AhornVersion = AhornHelper.GetAhornVersion();
public string AhornVersion = AhornHelper.GetVersion("Ahorn");

public string MapleVersion = AhornHelper.GetVersion("Maple");

}

Expand Down
60 changes: 36 additions & 24 deletions src/scenes/ahornsetup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,18 @@ If you really need to cancel the installation process:
})
end

function scene.updateAhornAlert(installed, found)
function scene.updateAhornAlert(installedAhorn, installedMaple, foundAhorn, foundMaple)
alert({
body = string.format([[
Olympus has found a possibly newer version of Ahorn.
Olympus has found a possibly newer version of Ahorn and/or Maple.
Detected installed version:
%s
Detected installed versions:
Ahorn: %s
Maple: %s
Latest available version:
%s
Latest available versions:
Ahorn: %s
Maple: %s
Just like installing Ahorn, IT WILL TAKE A LONG TIME.
Olympus will detect hangs and abort too slow installation processes.
Expand All @@ -425,7 +427,7 @@ If you really need to cancel the installation process:
(love.system.getOS() == "OS X" and "Open the Activity Monitor and force-close the Julia process.") or
(love.system.getOS() == "Linux" and "You probably know your way around htop and kill.") or
("... Good luck killing the Julia process.")),
installed, found),
installedAhorn, foundAhorn, installedMaple, foundMaple),
buttons = {
{
"Install updates",
Expand Down Expand Up @@ -784,36 +786,44 @@ Olympus can download Ahorn and start the installation process for you.
uie.label(string.format([[
Found installation path:
%s
Found version: %s]],
tostring(info.AhornPath), tostring(info.AhornVersion)
Found Ahorn version: %s
Found Maple version: %s]],
tostring(info.AhornPath), tostring(info.AhornVersion), tostring(info.MapleVersion)
)),
btnRow("check", {
{ "mainmenu/ahorn", "Launch Ahorn", scene.launchAhorn },
{ "update", "Force update", scene.forceUpdateAhornAlert }
}):with(function(row)
local btn = row.children[2]
scene.latestGet:calls(function(thread, latest)
local installedHash, installedHashType = tostring(info.AhornVersion or ""):match("(.*) %((.*)%)")

if installedHashType == "git" then
latest = latest and latest.sha
elseif installedHashType == "pkg" then
latest = latest and latest.commit
latest = latest and latest.tree
latest = latest and latest.sha
else
latest = nil
local function getLatest(latest, installedHashType)
if installedHashType == "git" then
latest = latest and latest.sha
elseif installedHashType == "pkg" then
latest = latest and latest.commit
latest = latest and latest.tree
latest = latest and latest.sha
else
latest = nil
end
return latest
end

if not installedHash or not latest then
local installedAhornHash, installedAhornHashType = tostring(info.AhornVersion or ""):match("(.*) %((.*)%)")
local installedMapleHash, installedMapleHashType = tostring(info.MapleVersion or ""):match("(.*) %((.*)%)")

local latestAhorn = getLatest(latest.ahorn, installedAhornHashType)
local latestMaple = getLatest(latest.maple, installedMapleHashType)

if not installedAhornHash or not installedMapleHash or not latestAhorn or not latestMaple then
return
end

if installedHash ~= latest then
if installedAhornHash ~= latestAhorn or installedMapleHash ~= latestMaple then
btn.children[1].children[1].image = uiu.image("download")
btn.children[1].children[2].text = "Install updates"
btn.cb = function()
scene.updateAhornAlert(installedHash, latest)
scene.updateAhornAlert(installedAhornHash, latestAhorn, installedMapleHash, latestMaple)
end
btn:with(utils.important(24))
end
Expand All @@ -836,8 +846,10 @@ end

function scene.load()
scene.latestGet = threader.routine(function()
scene.latest = threader.wrap("utils").downloadJSON("https://api.github.com/repos/CelestialCartographers/Ahorn/commits/master"):result()
return scene.latest
return {
ahorn = threader.wrap("utils").downloadJSON("https://api.github.com/repos/CelestialCartographers/Ahorn/commits/master"):result(),
maple = threader.wrap("utils").downloadJSON("https://api.github.com/repos/CelestialCartographers/Maple/commits/master"):result()
}
end)
end

Expand Down

0 comments on commit e0d3e8f

Please sign in to comment.