mirror of
https://github.com/Difegue/Karen
synced 2025-01-08 11:58:02 +08:00
Kill linux processes properly + more fixes
This commit is contained in:
parent
3442212bc9
commit
650f543490
@ -22,6 +22,9 @@
|
||||
<setting name="NetworkPort" serializeAs="String">
|
||||
<value>3000</value>
|
||||
</setting>
|
||||
<setting name="FirstLaunch" serializeAs="String">
|
||||
<value>True</value>
|
||||
</setting>
|
||||
</Karen.Properties.Settings>
|
||||
</userSettings>
|
||||
</configuration>
|
@ -10,7 +10,12 @@ namespace Karen
|
||||
public partial class App : Application
|
||||
{
|
||||
private TaskbarIcon notifyIcon;
|
||||
public WslDistro Distro { get; private set; }
|
||||
public WslDistro Distro { get; set; }
|
||||
|
||||
public void ToastNotification(string text)
|
||||
{
|
||||
notifyIcon.ShowBalloonTip("LANraragi", text, notifyIcon.Icon);
|
||||
}
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
@ -22,11 +27,13 @@ namespace Karen
|
||||
Distro = new WslDistro();
|
||||
|
||||
//check if server starts with app
|
||||
if (Karen.Properties.Settings.Default.StartServerAutomatically)
|
||||
if (Karen.Properties.Settings.Default.StartServerAutomatically && Distro.Status == AppStatus.Stopped)
|
||||
{
|
||||
notifyIcon.ShowBalloonTip("LANraragi", "LANraragi is starting automagically...", notifyIcon.Icon);
|
||||
ToastNotification("LANraragi is starting automagically...");
|
||||
Distro.StartApp();
|
||||
}
|
||||
else
|
||||
ToastNotification("The Launcher is now running! Please click the icon in your Taskbar.");
|
||||
}
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
|
@ -19,7 +19,6 @@ namespace Karen.Interop
|
||||
/// </summary>
|
||||
public class WslDistro
|
||||
{
|
||||
const string DISTRO_NAME = "lanraragi";
|
||||
|
||||
public AppStatus Status { get; private set; }
|
||||
public String Version { get; private set; }
|
||||
@ -57,7 +56,7 @@ namespace Karen.Interop
|
||||
while (!proc.StandardOutput.EndOfStream)
|
||||
{
|
||||
string line = proc.StandardOutput.ReadLine();
|
||||
if (line.Replace("\0","").Contains(DISTRO_NAME))
|
||||
if (line.Replace("\0","").Contains(Properties.Resources.DISTRO_NAME))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -82,7 +81,7 @@ namespace Karen.Interop
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "wsl.exe",
|
||||
Arguments = "-d "+DISTRO_NAME+" --exec " + oneLiner,
|
||||
Arguments = "-d "+ Properties.Resources.DISTRO_NAME + " --exec " + oneLiner,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true,
|
||||
@ -148,7 +147,7 @@ namespace Karen.Interop
|
||||
// Start process in WSL and hook up handles
|
||||
// This will direct WSL output to the new console window, or to Visual Studio if running with the debugger attached.
|
||||
// See https://stackoverflow.com/questions/15604014/no-console-output-when-using-allocconsole-and-target-architecture-x86
|
||||
WslApi.WslLaunch(DISTRO_NAME, command, false, stdIn,stdOut,stdError, out _lrrHandle);
|
||||
WslApi.WslLaunch(Properties.Resources.DISTRO_NAME, command, false, stdIn,stdOut,stdError, out _lrrHandle);
|
||||
|
||||
// Get Process ID of the returned procHandle
|
||||
int lrrId = GetProcessId(_lrrHandle);
|
||||
@ -162,15 +161,27 @@ namespace Karen.Interop
|
||||
}
|
||||
|
||||
public bool? StopApp()
|
||||
{
|
||||
// Ensure child unix processes are killed as well
|
||||
|
||||
{
|
||||
// Kill WSL Process
|
||||
if (_lrrProc != null && !_lrrProc.HasExited)
|
||||
{
|
||||
_lrrProc.Kill();
|
||||
|
||||
// No need to remove the attached console here in case the app is restarted later down
|
||||
// Ensure child unix processes are killed as well by killing the distro. This is only possible on 1809 and up.
|
||||
new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "wslconfig.exe",
|
||||
Arguments = "/terminate " + Properties.Resources.DISTRO_NAME,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true,
|
||||
}
|
||||
}.Start();
|
||||
}
|
||||
|
||||
// No need to remove the attached console here in case the app is restarted later down
|
||||
Status = AppStatus.Stopped;
|
||||
return _lrrProc?.HasExited;
|
||||
}
|
||||
|
@ -4,23 +4,11 @@
|
||||
xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
|
||||
x:Class="Karen.MainWindow"
|
||||
xmlns:p="clr-namespace:Karen.Properties"
|
||||
Title="LANraragi Windows Settings" Height="650" Width="360"
|
||||
Title="LANraragi Windows Settings" Height="600" Width="360"
|
||||
Closing="OnClosing">
|
||||
<DockPanel LastChildFill="False" Margin="10">
|
||||
<StackPanel VerticalAlignment="Top" DockPanel.Dock="Top">
|
||||
|
||||
<emoji:TextBlock Text="📦 Package Installation" FontSize="16" FontWeight="Bold" Margin="0,0,0,5"/>
|
||||
<TextBlock FontSize="10" TextWrapping="Wrap">
|
||||
You can use those buttons to install a new LANraragi package on your machine, or uninstall the current one.
|
||||
</TextBlock>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="5">
|
||||
<Button Height="30" Content="Install Package" Click="PickFolder" Style="{StaticResource MDLButton}" Margin="0,0,10,0"/>
|
||||
<Button Height="30" Content="Uninstall Package" Click="PickFolder" Style="{StaticResource MDLButton}"/>
|
||||
</StackPanel>
|
||||
<TextBlock FontSize="14" TextWrapping="Wrap">
|
||||
<Run FontWeight="Bold">Currently installed:</Run> 0.6.0.BETA.1 - 'Sense of Doubt'.
|
||||
</TextBlock>
|
||||
<Separator Height="11.5" Margin="0"/>
|
||||
<emoji:TextBlock Text="🗃 Content Folder Location" FontSize="16" FontWeight="Bold" Margin="0,0,0,5"/>
|
||||
<TextBlock FontSize="10">Where LANraragi looks for archives on your machine.</TextBlock>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
|
@ -70,5 +70,6 @@ namespace Karen
|
||||
Regex regex = new Regex("[^0-9]+");
|
||||
e.Handled = regex.IsMatch(e.Text);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ using System.Windows;
|
||||
// Les informations générales relatives à un assembly dépendent de
|
||||
// l'ensemble d'attributs suivant. Pour modifier les informations
|
||||
// associées à un assembly.
|
||||
[assembly: AssemblyTitle("Karen")]
|
||||
[assembly: AssemblyTitle("LANraragi for Windows")]
|
||||
[assembly: AssemblyDescription("Windows Bootstrapper for LANraragi.")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
|
53
Karen/Properties/Resources.Designer.cs
generated
53
Karen/Properties/Resources.Designer.cs
generated
@ -8,10 +8,10 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Karen.Properties
|
||||
{
|
||||
|
||||
|
||||
namespace Karen.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées.
|
||||
/// </summary>
|
||||
@ -19,53 +19,54 @@ namespace Karen.Properties
|
||||
// à l'aide d'un outil, tel que ResGen ou Visual Studio.
|
||||
// Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen
|
||||
// avec l'option /str ou régénérez votre projet VS.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources
|
||||
{
|
||||
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources()
|
||||
{
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Retourne l'instance ResourceManager mise en cache utilisée par cette classe.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((resourceMan == null))
|
||||
{
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Karen.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Remplace la propriété CurrentUICulture du thread actuel pour toutes
|
||||
/// les recherches de ressources à l'aide de cette classe de ressource fortement typée.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set
|
||||
{
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recherche une chaîne localisée semblable à lanraragi.
|
||||
/// </summary>
|
||||
internal static string DISTRO_NAME {
|
||||
get {
|
||||
return ResourceManager.GetString("DISTRO_NAME", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
@ -60,6 +60,7 @@
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
@ -68,9 +69,10 @@
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
@ -85,9 +87,10 @@
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
@ -109,9 +112,12 @@
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="DISTRO_NAME" xml:space="preserve">
|
||||
<value>lanraragi</value>
|
||||
</data>
|
||||
</root>
|
12
Karen/Properties/Settings.Designer.cs
generated
12
Karen/Properties/Settings.Designer.cs
generated
@ -70,5 +70,17 @@ namespace Karen.Properties {
|
||||
this["NetworkPort"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("True")]
|
||||
public bool FirstLaunch {
|
||||
get {
|
||||
return ((bool)(this["FirstLaunch"]));
|
||||
}
|
||||
set {
|
||||
this["FirstLaunch"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,5 +14,8 @@
|
||||
<Setting Name="NetworkPort" Type="System.String" Scope="User">
|
||||
<Value Profile="(Default)">3000</Value>
|
||||
</Setting>
|
||||
<Setting Name="FirstLaunch" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
Loading…
Reference in New Issue
Block a user