Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Updater bundled now :)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadoum committed Dec 30, 2019
1 parent 17515da commit b84972a
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 7 deletions.
31 changes: 31 additions & 0 deletions PackIntoAppImageOutsideOfPipeline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
rm -rf ./AppDir
rm appimagetool-x86_64.AppImage
dotnet publish --configuration Debug -r linux-x64 --self-contained true

mkdir -p ./AppDir/usr/bin
cp -r ./bin/Debug/netcoreapp3.0/linux-x64/* ./AppDir/usr/bin/
touch ./AppDir/AppRun
echo "#!/bin/sh" >> ./AppDir/AppRun
echo "HERE=\"\$(dirname \"\$(readlink -f \"\${0}\")\")\"" >> ./AppDir/AppRun
echo "export PATH=\"\${HERE}\"/usr/bin/:\"\${PATH}\"" >> ./AppDir/AppRun
echo "EXEC=\$(grep -e '^Exec=.*' \"\${HERE}\"/*.desktop | head -n 1 | cut -d \"=\" -f 2 | cut -d \" \" -f 1)" >> ./AppDir/AppRun
echo "exec \"\${EXEC}\" \$@" >> ./AppDir/AppRun
chmod 755 ./AppDir/AppRun
chmod +x ./AppDir/AppRun
touch ./AppDir/iCode.desktop
echo "# Desktop Entry Specification: https://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html" >> ./AppDir/iCode.desktop
echo "[Desktop Entry]" >> ./AppDir/iCode.desktop
echo "Type=Application" >> ./AppDir/iCode.desktop
echo "Name=iCode" >> ./AppDir/iCode.desktop
echo "Comment=iOS Development Environement" >> ./AppDir/iCode.desktop
echo "Icon=iCode" >> ./AppDir/iCode.desktop
echo "Exec=iCode" >> ./AppDir/iCode.desktop
echo "Path=~" >> ./AppDir/iCode.desktop
echo "Terminal=true" >> ./AppDir/iCode.desktop
echo "Categories=Development;" >> ./AppDir/iCode.desktop
cp ./resources/images/icon.png ./AppDir/iCode.png
wget "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage"
chmod a+x appimagetool-x86_64.AppImage
./appimagetool-x86_64.AppImage ./AppDir -u "gh-releases-zsync|Dadoum|iCode|latest|iCode-*x86_64.AppImage.zsync"
chmod +x iCode-x86_64.AppImage
47 changes: 47 additions & 0 deletions Source/iCode/GUI/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Xml.Linq;
using Gdk;
Expand Down Expand Up @@ -72,6 +73,8 @@ public OutputWidget Output
[UI]
private global::Gtk.MenuItem _layoutAction;
[UI]
private global::Gtk.MenuBar _menuBar;
[UI]
private global::Gtk.Button _button6;
[UI]
private global::Gtk.Button _button7;
Expand Down Expand Up @@ -223,6 +226,50 @@ public MainWindow(Builder builder, IntPtr handle) : base(handle)

_layoutAction.Submenu = menu;

if (Program.UpdateAvailable)
{
var updateMenu = new MenuItem();
var itemMenu = new Menu();
var item = new MenuItem();

updateMenu.Label = "Update iCode in background";
updateMenu.Activated += (sender, args) =>
{
Gtk.Application.Invoke((o, a) =>
{
itemMenu.Remove(updateMenu);
item.Label = "Update in progress...";
});
Task.Factory.StartNew(() =>
{
var outp = iCode.Utils.Extensions.LaunchProcess(
System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"Updater"), $"\"{Program.AppImagePath}\"", out int ret);
if (ret == 0)
{
Gtk.Application.Invoke((o, a) =>
{
item.Label = "Update completed.";
});
}
else
{
Gtk.Application.Invoke((o, a) =>
{
item.Label = "Update failed.";
});
}
});
};

itemMenu.Append(updateMenu);
item.Label = "Update available";

item.Submenu = itemMenu;
_menuBar.Append(item);
}

_statusBox.ButtonPressEvent += (o, args) =>
{
// Here it will redirect to the future error pane, but I need to fix signing first
Expand Down
35 changes: 31 additions & 4 deletions Source/iCode/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Gdl;
using GLib;
using Gtk;
using iCode.GUI;
using iCode.Utils;
using iMobileDevice;
using Newtonsoft.Json.Linq;
using Extensions = iCode.Utils.Extensions;

namespace iCode
{
Expand All @@ -19,16 +20,20 @@ public static void Main(string[] args)
Console.WriteLine("Initialized output.");
try
{
if (string.IsNullOrWhiteSpace(AppImagePath))
Console.WriteLine("iCode is running outside of an AppImage.");

Directory.CreateDirectory(ConfigPath);
Directory.CreateDirectory(SDKPath);
Directory.CreateDirectory(DeveloperPath);
Directory.CreateDirectory(UserDefinedTemplatesPath);
Directory.CreateDirectory(ConfigPath);

Gtk.Application.Init();

Log.SetDefaultHandler(new LogFunc((domain, level, message) =>
GLib.Log.SetDefaultHandler(new GLib.LogFunc((domain, level, message) =>
{
if (level != LogLevelFlags.Error && level != LogLevelFlags.FlagFatal)
if (level != GLib.LogLevelFlags.Error && level != GLib.LogLevelFlags.FlagFatal)
return;
Console.WriteLine($"Gtk error: {message} ({domain})");
Expand All @@ -47,6 +52,25 @@ public static void Main(string[] args)
File.WriteAllText(SettingsPath, jobj.ToString());
Console.WriteLine("Initialized settings file.");
}
else
{
if (!string.IsNullOrWhiteSpace(AppImagePath))
{
var settings = JObject.Parse(File.ReadAllText(SettingsPath));
if ((bool) settings["updateConsent"])
{
var outp = Extensions.LaunchProcess(
Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"Updater"), $"--check-for-update \"{AppImagePath}\"", out int ret);
// TODO Updater
if (ret == 1)
{
Console.WriteLine("Update available.");
UpdateAvailable = true;
}
}
}
}

NativeLibraries.Load(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tools/libs/"));
Console.WriteLine("Initialized libimobiledevice.");
Expand All @@ -66,7 +90,10 @@ public static void Main(string[] args)
public static readonly string DeveloperPath = System.IO.Path.Combine(Program.ConfigPath, "Developer/");
public static readonly string UserDefinedTemplatesPath = System.IO.Path.Combine(Program.ConfigPath, "Templates/");
public static readonly string SettingsPath = System.IO.Path.Combine(Program.ConfigPath, "Settings.json");
public static readonly string AppImagePath = Environment.GetEnvironmentVariable("APPIMAGE");

public static bool UpdateAvailable = false;

public static MainWindow WinInstance;
}
}
6 changes: 4 additions & 2 deletions Source/iCode/Utils/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ public static Process GetProcess(string process, string arguments)
return proc;
}

public static string LaunchProcess(string process, string arguments)
public static string LaunchProcess(string process, string arguments) => LaunchProcess(process, arguments, out _);

public static string LaunchProcess(string process, string arguments, out int ret)
{
var proc = new Process();
proc.StartInfo.Arguments = arguments;
Expand All @@ -191,7 +193,7 @@ public static string LaunchProcess(string process, string arguments)
proc.BeginOutputReadLine();
proc.WaitForExit();
proc.CancelOutputRead();
ret = proc.ExitCode;
var str = outputBuilder.ToString();
// Console.WriteLine($"process:{process} args:{arguments} stdout:\n{str}");

Expand Down
Binary file added Updater
Binary file not shown.
Binary file removed iCode-x86_64.AppImage.part
Binary file not shown.
Binary file removed iCode-x86_64.AppImage.zsync
Binary file not shown.
10 changes: 10 additions & 0 deletions iCode.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<Reference Include="gdl-sharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>lib\gdl-sharp.dll</HintPath>
</Reference>
<Reference Include="generated, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\Téléchargements\generated.dll</HintPath>
</Reference>
<Reference Include="gio-sharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>lib\gio-sharp.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -78,6 +81,13 @@
<None Remove=".gitattributes" />
<None Remove="readme.md" />
<None Remove="iCode.csproj.DotSettings" />
<None Remove="iCode-x86_64.AppImage.zsync" />
<None Update="Updater-old">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Updater">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="imobiledevice-net" Version="1.2.186" />
Expand Down
2 changes: 1 addition & 1 deletion resources/forms/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkMenuBar">
<object class="GtkMenuBar" id="_menuBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
Expand Down

0 comments on commit b84972a

Please sign in to comment.