aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.ServerApplication/App.xaml.cs
blob: 41fb8f24e7b3fd48953f2044f188df7592b6682a (plain)
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
using MediaBrowser.Common.Kernel;
using MediaBrowser.Common.UI;
using MediaBrowser.Controller;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;

namespace MediaBrowser.ServerApplication
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : BaseApplication, IApplication
    {
        [STAThread]
        public static void Main()
        {
            RunApplication<App>("MediaBrowserServer");
        }

        protected override void OnSecondInstanceLaunched(IList<string> args)
        {
            base.OnSecondInstanceLaunched(args);

            OpenDashboard();
            InitializeComponent();
        }

        public static void OpenDashboard()
        {
            OpenUrl("http://localhost:" + Kernel.Instance.Configuration.HttpServerPortNumber + "/mediabrowser/dashboard/index.html");
        }
        
        public static void OpenUrl(string url)
        {
            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = url
                },

                EnableRaisingEvents = true
            };

            process.Exited += ProcessExited;

            process.Start();
        }

        static void ProcessExited(object sender, EventArgs e)
        {
            (sender as Process).Dispose();
        }

        protected override IKernel InstantiateKernel()
        {
            return new Kernel();
        }

        protected override Window InstantiateMainWindow()
        {
            return new MainWindow();
        }
    }
}