private void SetWindowState() { var win = this; win.WindowState = FormWindowState.Normal; win.StartPosition = FormStartPosition.CenterScreen; win.MinimumSize = new Size(720, 480); win.Width = 1280; win.Height = 720; FormBorderStyle = FormBorderStyle.None; RECT rect = new RECT(); var electronWindowHandle = _electronProcess.MainWindowHandle; NativeWindowMethods.GetWindowRect(electronWindowHandle, ref rect); if (win.WindowState == FormWindowState.Normal) { win.Top = rect.Top; win.Left = rect.Left; win.Width = Math.Abs(rect.Right - rect.Left); win.Height = Math.Abs(rect.Bottom - rect.Top); } }
static void Main() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; bool createdNew; _singleInstanceMutex = new Mutex(true, @"Local\" + typeof(Program).Assembly.GetName().Name, out createdNew); if (!createdNew) { _singleInstanceMutex = null; return; } var appPath = Process.GetCurrentProcess().MainModule.FileName; // Look for the existence of an update archive var appPaths = new ApplicationPaths(GetProgramDataPath(appPath), appPath); var logManager = new NlogManager(appPaths.LogDirectoryPath, "theater"); logManager.ReloadLogger(LogSeverity.Debug); var updateArchive = Path.Combine(appPaths.TempUpdatePath, UpdatePackageName); if (File.Exists(updateArchive)) { ReleaseMutex(); // Update is there - execute update try { new ApplicationUpdater().UpdateApplication(appPaths, updateArchive, logManager.GetLogger("ApplicationUpdater")); // And just let the app exit so it can update return; } catch (Exception e) { MessageBox.Show(string.Format("Error attempting to update application.\n\n{0}\n\n{1}", e.GetType().Name, e.Message)); } } _logger = logManager.GetLogger("App"); bool supportsTransparency; try { supportsTransparency = NativeWindowMethods.DwmIsCompositionEnabled(); } catch (Exception ex) { _logger.ErrorException("Error in DwmIsCompositionEnabled", ex); supportsTransparency = true; } _logger.Info("OS Supports window transparency?: {0}", supportsTransparency); try { var task = InstallVcredist2015IfNeeded(_appHost, _logger); Task.WaitAll(task); _appHost = new ApplicationHost(appPaths, logManager); var initTask = _appHost.Init(new Progress <Double>()); Task.WaitAll(initTask); task = InstallCecDriver(appPaths); Task.WaitAll(task); var electronTask = StartElectron(appPaths, supportsTransparency); Task.WaitAll(electronTask); var electronProcess = electronTask.Result; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); _mainForm = new MainForm(_logger, _appHost.TheaterConfigurationManager, _appHost, electronProcess); Application.Run(_mainForm); } catch (Exception ex) { _logger.ErrorException("Error launching application", ex); MessageBox.Show("There was an error launching Emby: " + ex.Message); // Shutdown the app with an error code Environment.Exit(1); } finally { ReleaseMutex(); } }