1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
using MediaBrowser.Controller;
using MediaBrowser.Model.Logging;
using System;
using System.Diagnostics;
namespace MediaBrowser.Server.Startup.Common.Browser
{
/// <summary>
/// Class BrowserLauncher
/// </summary>
public static class BrowserLauncher
{
/// <summary>
/// Opens the dashboard page.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="appHost">The app host.</param>
/// <param name="logger">The logger.</param>
public static void OpenDashboardPage(string page, IServerApplicationHost appHost, ILogger logger)
{
var url = appHost.GetLocalApiUrl("localhost") + "/web/" + page;
OpenUrl(url, logger);
}
/// <summary>
/// Opens the github.
/// </summary>
/// <param name="logger">The logger.</param>
public static void OpenGithub(ILogger logger)
{
OpenUrl("https://github.com/MediaBrowser/MediaBrowser", logger);
}
/// <summary>
/// Opens the community.
/// </summary>
/// <param name="logger">The logger.</param>
public static void OpenCommunity(ILogger logger)
{
OpenUrl("http://emby.media/community", logger);
}
/// <summary>
/// Opens the web client.
/// </summary>
/// <param name="appHost">The app host.</param>
/// <param name="logger">The logger.</param>
public static void OpenWebClient(IServerApplicationHost appHost, ILogger logger)
{
OpenDashboardPage("index.html", appHost, logger);
}
/// <summary>
/// Opens the dashboard.
/// </summary>
/// <param name="appHost">The app host.</param>
/// <param name="logger">The logger.</param>
public static void OpenDashboard(IServerApplicationHost appHost, ILogger logger)
{
OpenDashboardPage("dashboard.html", appHost, logger);
}
/// <summary>
/// Opens the swagger.
/// </summary>
/// <param name="appHost">The app host.</param>
/// <param name="logger">The logger.</param>
public static void OpenSwagger(IServerApplicationHost appHost, ILogger logger)
{
var url = appHost.GetLocalApiUrl("localhost") + "/swagger-ui/index.html";
OpenUrl(url, logger);
}
/// <summary>
/// Opens the URL.
/// </summary>
/// <param name="url">The URL.</param>
/// <param name="logger">The logger.</param>
private static void OpenUrl(string url, ILogger logger)
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = url
},
EnableRaisingEvents = true,
};
process.Exited += ProcessExited;
try
{
process.Start();
}
catch (Exception ex)
{
logger.ErrorException("Error launching url: {0}", ex, url);
Console.WriteLine("Error launching url: {0}", ex.Message);
Console.WriteLine(ex.Message);
//#if !__MonoCS__
// System.Windows.Forms.MessageBox.Show("There was an error launching your web browser. Please check your default browser settings.");
//#endif
}
}
/// <summary>
/// Processes the exited.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
private static void ProcessExited(object sender, EventArgs e)
{
((Process)sender).Dispose();
}
}
}
|