Skip to content

Commit

Permalink
Made link handler stuff a little easier to understand.
Browse files Browse the repository at this point in the history
  • Loading branch information
TauAkiou committed Nov 3, 2020
1 parent b70ef2a commit 0522022
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 29 deletions.
2 changes: 1 addition & 1 deletion AmongUsCapture/ClientSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Init()
socket.EmitAsync("connectCode", ConnectCode).ContinueWith((_) =>
{
Settings.conInterface.WriteModuleTextColored("ClientSocket", Color.Cyan,
$"Connection code ({Color.Red.ToTextColor()}{ConnectCode}) sent to server.");
$"Connection code ({Color.Red.ToTextColorPango(ConnectCode)}) sent to server.");
GameMemReader.getInstance().ForceUpdatePlayers();
GameMemReader.getInstance().ForceTransmitState();
GameMemReader.getInstance().ForceTransmitLobby();
Expand Down
47 changes: 47 additions & 0 deletions AmongUsCapture/IPC/DBus/IPCadapterDBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Castle.Core.Internal;
using Mono.Unix;
using Tmds.DBus;
using Color = System.Drawing.Color;
Expand Down Expand Up @@ -178,6 +179,52 @@ private static void RegisterProtocol()
}
}

public override void RemoveHandler()
{
var xdg_path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"applications");
var xdg_file = Path.Join(xdg_path, "aucapture-opener.desktop");

if(File.Exists(xdg_file))
{
File.Delete(xdg_file);
}

var xdgproc = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "/usr/bin/xdg-mime",
Arguments = $"query defualt x-scheme-handler/aucapture",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};

xdgproc.Start();
string result = xdgproc.StandardOutput.ReadToEnd();
xdgproc.WaitForExit();

if (!result.IsNullOrEmpty())
{
xdgproc = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "/usr/bin/xdg-mime",
Arguments = $"uninstall x-scheme-handler/aucapture",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};

xdgproc.Start();
xdgproc.WaitForExit();
}
}

public override async Task<bool> SendToken(string jsonText)
{
// Delay the send until we know for certain the server is started.
Expand Down
4 changes: 4 additions & 0 deletions AmongUsCapture/IPC/IPCadapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public virtual void InstallHandler()
{
}

public virtual void RemoveHandler()
{
}

// This method is for implementations that might be cancelable - such as DBUS.
public virtual async Task<bool> Cancel()
{
Expand Down
89 changes: 62 additions & 27 deletions AmongUsCapture/UserForm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Metadata;
Expand All @@ -13,6 +14,8 @@
using Menu = Gtk.Menu;
using Window = Gtk.Window;
using AmongUsCapture.TextColorLibrary;
using Castle.Core.Internal;
using Process = System.Diagnostics.Process;

namespace AmongUsCapture
{
Expand Down Expand Up @@ -155,43 +158,75 @@ private void _primaryWindowInstallLinkWindow_Dialog(object o, EventArgs e) {
var xdg_file = System.IO.Path.Join(xdg_path, "aucapture-opener.desktop");
string info = String.Empty;

if(!File.Exists(xdg_file) && !Settings.PersistentSettings.skipHandlerInstall)
{
info +=
"This is your first time running the program, or you do not have the association for aucapture links installed.\n\n";
}

info +=
"This will allow you to use the automatic, link-based system for connecting to the AutoMuteUs discord bot.\n\n" +
"The following operations will be performed:\n\n" +
$"- The following .desktop file will be installed: {xdg_file}\n\n" +
"- The following command will be run to link the 'aucapture:' URI to the program:\n\n \'xdg-mime default aucapture-opener.desktop x-scheme-handler/aucapture\'" +
"\n\nNote that this will also replace the old version of the .desktop file if you already have it installed.";

var InstallLinkDialogBox = new MessageDialog(this,
DialogFlags.Modal,
MessageType.Question,
ButtonsType.None,
false,
info);

InstallLinkDialogBox.Title = "Install aucapture Link Association";
InstallLinkDialogBox.AddButton("Cancel", ResponseType.Reject);
InstallLinkDialogBox.AddButton("Install", ResponseType.Accept);
String.Empty);

InstallLinkDialogBox.Response += delegate(object o1, ResponseArgs responseArgs)
if(!File.Exists(xdg_file) && !Settings.PersistentSettings.skipHandlerInstall)
{
if (responseArgs.ResponseId == ResponseType.Reject)
info +=
"Would you like to enable support for AutoMuteUs one-click connection?" +
"This will allow you to use the links provided by AutoMuteUs to connect the capture to the bot automatically.\n\n" +
"The following operations will be performed:\n\n" +
$"- The following .desktop file will be installed: {xdg_file}\n\n" +
"- The following command will be run to link the 'aucapture:' URI to the program:\n\n \'xdg-mime default aucapture-opener.desktop x-scheme-handler/aucapture\'" +
"\n\nIf you decline, Discord connection links will not be functional." +
"\n\nYou can install or manage One-Click support by using the \"One-Click Connection Management\" link in the File menu.";

InstallLinkDialogBox.Text = info;
InstallLinkDialogBox.Title = "Enable One-Click Connection?";
InstallLinkDialogBox.AddButton("Cancel", ResponseType.Reject);
InstallLinkDialogBox.AddButton("Install", ResponseType.Accept);

InstallLinkDialogBox.Response += delegate(object o1, ResponseArgs responseArgs)
{
// Make sure we have the setting to ignore the dialog box set.
Settings.PersistentSettings.skipHandlerInstall = true;
}
if (responseArgs.ResponseId == ResponseType.Reject)
{
// Make sure we have the setting to ignore the dialog box set.
Settings.PersistentSettings.skipHandlerInstall = true;
}

if (responseArgs.ResponseId == ResponseType.Accept)
if (responseArgs.ResponseId == ResponseType.Accept)
{
IPCadapter.getInstance().InstallHandler();
}
};
}
else
{
info += "This menu manages the One-Click Connection link system.\n\n";

info += "One-Click Connection Status: ";
if (File.Exists(xdg_file)) info += "Enabled\n\n";
else info += "Disabled\n\n";

info += $"Runner (.desktop) Installation Path: ";
if (File.Exists(xdg_file)) info += xdg_file;
else info += "Not Found";

InstallLinkDialogBox.Text += info;
InstallLinkDialogBox.Title = "Manage One-Click Connection";
InstallLinkDialogBox.AddButton("Cancel", ResponseType.Close);
InstallLinkDialogBox.AddButton("Uninstall", ResponseType.Reject);
InstallLinkDialogBox.AddButton("Reinstall", ResponseType.Accept);

InstallLinkDialogBox.Response += delegate(object o1, ResponseArgs responseArgs)
{
IPCadapter.getInstance().InstallHandler();
}
};
if (responseArgs.ResponseId == ResponseType.Reject)
{
// Make sure we have the setting to ignore the dialog box set.
IPCadapter.getInstance().RemoveHandler();
}

if (responseArgs.ResponseId == ResponseType.Accept)
{
IPCadapter.getInstance().InstallHandler();
}
};
}

InstallLinkDialogBox.ShowAll();
InstallLinkDialogBox.Run();
Expand Down
2 changes: 1 addition & 1 deletion AmongUsCapture/Userform.Gtk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void InitializeWindow()
_primaryWindowMenuQuitItem.Activated += _primaryWindowMenuQuitItem_Activated;

_primaryWindowInstallLinkHandler.Name = "_primaryWindowInstallLinkHandler";
_primaryWindowInstallLinkHandler.Label = "Install Link Handler";
_primaryWindowInstallLinkHandler.Label = "One-Click Connection Management";
_primaryWindowInstallLinkHandler.Activated += _primaryWindowInstallLinkWindow_Dialog;

// _primaryWindowPane definition (splitContainer1)
Expand Down

0 comments on commit 0522022

Please sign in to comment.