-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from trossr32/6-add_web_ui_launch_cmdlet
fixes #6 - add Invoke-TransmissionWeb cmdlet to open transmission in …
- Loading branch information
Showing
6 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Management.Automation; | ||
using System.Runtime.InteropServices; | ||
using Flurl; | ||
using PsTransmission.Core.Components; | ||
using Transmission.Base; | ||
|
||
namespace Transmission.System | ||
{ | ||
[Cmdlet(VerbsLifecycle.Invoke, "TransmissionWeb", HelpUri = "https://github.com/trossr32/ps-transmission-manager")] | ||
public class InvokeTransmissionWebCmdlet : BaseTransmissionCmdlet | ||
{ | ||
/// <summary> | ||
/// Implements the <see cref="BeginProcessing"/> method for <see cref="InvokeTransmissionWebCmdlet"/>. | ||
/// </summary> | ||
protected override void BeginProcessing() | ||
{ | ||
base.BeginProcessing(); | ||
} | ||
|
||
/// <summary> | ||
/// Implements the <see cref="ProcessRecord"/> method for <see cref="InvokeTransmissionWebCmdlet"/>. | ||
/// </summary> | ||
protected override void ProcessRecord() | ||
{ | ||
string url = new Url(TransmissionContext.Credentials.Host).Root; | ||
|
||
try | ||
{ | ||
Process.Start(url); | ||
|
||
WriteObject("Web UI launched"); | ||
} | ||
catch (Exception e) | ||
{ | ||
// hack because of this: https://github.com/dotnet/corefx/issues/10361 | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
url = url.Replace("&", "^&"); | ||
|
||
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true }); | ||
} | ||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
{ | ||
Process.Start("xdg-open", url); | ||
} | ||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
{ | ||
Process.Start("open", url); | ||
} | ||
else | ||
{ | ||
ThrowTerminatingError(new ErrorRecord(new Exception($"Failed to launch web UI. {e.Message}", e), null, ErrorCategory.OperationStopped, null)); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Implements the <see cref="EndProcessing"/> method for <see cref="InvokeTransmissionWebCmdlet"/>. | ||
/// Retrieve all torrents | ||
/// </summary> | ||
protected override void EndProcessing() | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters