1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Merge pull request #770 from Artemis-RGB/feature/linux-icons

Linux update script
This commit is contained in:
RobertBeekman 2023-04-07 16:16:54 +02:00 committed by GitHub
commit 69c623bc8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 92 additions and 0 deletions

View File

@ -29,6 +29,7 @@ public class ApplicationStateManager
Core.Utilities.ShutdownRequested += UtilitiesOnShutdownRequested; Core.Utilities.ShutdownRequested += UtilitiesOnShutdownRequested;
Core.Utilities.RestartRequested += UtilitiesOnRestartRequested; Core.Utilities.RestartRequested += UtilitiesOnRestartRequested;
Core.Utilities.UpdateRequested += UtilitiesOnUpdateRequested;
// On OS shutdown dispose the IOC container just so device providers get a chance to clean up // On OS shutdown dispose the IOC container just so device providers get a chance to clean up
if (Application.Current?.ApplicationLifetime is IControlledApplicationLifetime controlledApplicationLifetime) if (Application.Current?.ApplicationLifetime is IControlledApplicationLifetime controlledApplicationLifetime)
@ -138,4 +139,35 @@ public class ApplicationStateManager
//todo //todo
} }
private void UtilitiesOnUpdateRequested(object? sender, UpdateEventArgs e)
{
List<string> argsList = new(StartupArguments);
if (e.Silent && !argsList.Contains("--minimized"))
argsList.Add("--minimized");
// Retain startup arguments after update by providing them to the script
string script = Path.Combine(Constants.UpdatingFolder, "installing", "Scripts", "update.sh");
string source = $"\"{Path.Combine(Constants.UpdatingFolder, "installing")}\"";
string destination = $"\"{Constants.ApplicationFolder}\"";
string args = argsList.Any() ? string.Join(' ', argsList) : "";
RunScriptWithOutputFile(script, $"{source} {destination} {args}", Path.Combine(Constants.DataFolder, "update-log.txt"));
// Lets try a graceful shutdown, the script will kill if needed
if (Application.Current?.ApplicationLifetime is IControlledApplicationLifetime controlledApplicationLifetime)
Dispatcher.UIThread.Post(() => controlledApplicationLifetime.Shutdown());
}
private static void RunScriptWithOutputFile(string script, string arguments, string outputFile)
{
ProcessStartInfo info = new()
{
Arguments = $"\"{script}\" {arguments} > \"{outputFile}\"",
FileName = "/bin/bash",
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true,
};
Process.Start(info);
}
} }

View File

@ -27,4 +27,8 @@
<ProjectReference Include="..\Artemis.Core\Artemis.Core.csproj" /> <ProjectReference Include="..\Artemis.Core\Artemis.Core.csproj" />
<ProjectReference Include="..\Artemis.UI\Artemis.UI.csproj" /> <ProjectReference Include="..\Artemis.UI\Artemis.UI.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="Icons/**" CopyToOutputDirectory="PreserveNewest" />
<Content Include="Scripts/**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project> </Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -0,0 +1,56 @@
#!/bin/bash
sourceDirectory=$1
destinationDirectory=$2
artemisArgs=$3
# Wait for up to 10 seconds for the Artemis process to exit
i=0
while [ $i -le 10 ]
do
if ! pgrep -x "Artemis.UI.Linux" > /dev/null
then
break
fi
sleep 1
i=$((i+1))
done
# If the Artemis process is still running, kill it
if pgrep -x "Artemis.UI.Linux" > /dev/null
then
pkill -x "Artemis.UI.Linux"
fi
# Check if the destination directory exists
if [ ! -d "$destinationDirectory" ]
then
echo "Destination directory does not exist"
exit 1
fi
# Clear the destination directory but don't remove it
echo "Cleaning up old version where needed"
rm -rf "${destinationDirectory:?}/"*
# Move the contents of the source directory to the destination directory
echo "Installing new files"
mv "$sourceDirectory"/* "$destinationDirectory"
# Remove the now empty source directory
rmdir "$sourceDirectory"
# Ensure the executable is executable
chmod +x "$destinationDirectory/Artemis.UI.Linux"
echo "Finished! Restarting Artemis"
sleep 1
# When finished, start Artemis again
# quoting here breaks stuff, all arguments count as 1
# shellcheck disable=SC2086
"$destinationDirectory/Artemis.UI.Linux" $artemisArgs &