public MainWindow() { if (WpfUtil.IsInDesignMode) { return; } if (!NTMinerConsole.IsEnabled) { NTMinerConsole.Enable(); } this.Vm = new MainWindowViewModel(); this.DataContext = Vm; this.MinHeight = 430; this.MinWidth = 640; this.Width = AppRoot.MainWindowWidth; this.Height = AppRoot.MainWindowHeight; #if DEBUG NTStopwatch.Start(); #endif ConsoleWindow.Instance.MouseDown += (sender, e) => { MoveConsoleWindow(); }; SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; this.Loaded += (sender, e) => { ConsoleTabItemTopBorder.Margin = new Thickness(0, ConsoleTabItem.ActualHeight - 1, 0, 0); MoveConsoleWindow(); hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; hwndSource.AddHook(new HwndSourceHook(Win32Proc.WindowProc)); }; InitializeComponent(); _leftDrawerGripWidth = LeftDrawerGrip.Width; _btnOverClockBackground = BtnOverClock.Background; // 下面几行是为了看见设计视图 this.ResizeCursors.Visibility = Visibility.Visible; this.HideLeftDrawerGrid(); // 上面几行是为了看见设计视图 DateTime lastGetServerMessageOn = DateTime.MinValue; // 切换了主界面上的Tab时 this.MainTabControl.SelectionChanged += (sender, e) => { // 延迟创建,以加快主界面的启动 #region var selectedItem = MainTabControl.SelectedItem; if (selectedItem == TabItemSpeedTable) { if (SpeedTableContainer.Child == null) { SpeedTableContainer.Child = GetSpeedTable(); } } else if (selectedItem == TabItemMessage) { if (MessagesContainer.Child == null) { MessagesContainer.Child = new Messages(); } } else if (selectedItem == TabItemToolbox) { if (ToolboxContainer.Child == null) { ToolboxContainer.Child = new Toolbox(); } } else if (selectedItem == TabItemMinerProfileOption) { if (MinerProfileOptionContainer.Child == null) { MinerProfileOptionContainer.Child = new MinerProfileOption(); } } RpcRoot.SetIsServerMessagesVisible(selectedItem == TabItemMessage); if (selectedItem == TabItemMessage) { if (lastGetServerMessageOn.AddSeconds(10) < DateTime.Now) { lastGetServerMessageOn = DateTime.Now; VirtualRoot.Execute(new LoadNewServerMessageCommand()); } } if (selectedItem == ConsoleTabItem) { ConsoleTabItemTopBorder.Visibility = Visibility.Visible; } else { ConsoleTabItemTopBorder.Visibility = Visibility.Collapsed; } #endregion }; this.IsVisibleChanged += (sender, e) => { #region if (this.IsVisible) { NTMinerContext.IsUiVisible = true; } else { NTMinerContext.IsUiVisible = false; } MoveConsoleWindow(); #endregion }; this.StateChanged += (s, e) => { #region if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } if (WindowState == WindowState.Maximized) { ResizeCursors.Visibility = Visibility.Collapsed; } else { ResizeCursors.Visibility = Visibility.Visible; } MoveConsoleWindow(); #endregion }; bool isLeftClosed = false; this.ConsoleRectangle.IsVisibleChanged += (sender, e) => { if (this.ConsoleRectangle.IsVisible) { if (isLeftClosed != (LeftDrawerGrip.Width == _leftDrawerGripWidth)) { ConsoleWindowFit(); } } else { isLeftClosed = LeftDrawerGrip.Width == _leftDrawerGripWidth; } }; this.ConsoleRectangle.SizeChanged += (s, e) => { MoveConsoleWindow(); }; if (this.Width < 860) { NTMinerConsole.UserWarn("左侧面板已折叠,可点击侧边的'开始挖矿'按钮展开。"); } this.SizeChanged += (s, e) => { #region if (this.Width < 860) { this.CloseLeftDrawer(); this.BtnAboutNTMiner.Visibility = Visibility.Collapsed; } else { this.OpenLeftDrawer(isSizeChanged: true); this.BtnAboutNTMiner.Visibility = Visibility.Visible; } if (!this.ConsoleRectangle.IsVisible) { if (e.WidthChanged) { ConsoleWindow.Instance.Width = e.NewSize.Width; } if (e.HeightChanged) { ConsoleWindow.Instance.Height = e.NewSize.Height; } } #endregion }; NotiCenterWindow.Bind(this, ownerIsTopmost: true); this.LocationChanged += (sender, e) => { MoveConsoleWindow(); }; VirtualRoot.BuildCmdPath <TopmostCommand>(this.GetType(), LogEnum.DevConsole, path: message => { UIThread.Execute(() => { if (!this.Topmost) { this.Topmost = true; } }); }); VirtualRoot.BuildCmdPath <UnTopmostCommand>(this.GetType(), LogEnum.DevConsole, path: message => { UIThread.Execute(() => { if (this.Topmost) { this.Topmost = false; } }); }); VirtualRoot.BuildCmdPath <CloseMainWindowCommand>(location: this.GetType(), LogEnum.DevConsole, path: message => { UIThread.Execute(() => { if (message.IsAutoNoUi) { SwitchToNoUi(); } else { this.Close(); } }); }); this.BuildEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式", LogEnum.DevConsole, location: this.GetType(), PathPriority.Normal, path: message => { if (NTMinerContext.IsUiVisible && NTMinerContext.Instance.MinerProfile.IsAutoNoUi && NTMinerContext.Instance.IsMining) { if (NTMinerContext.MainWindowRendedOn.AddMinutes(NTMinerContext.Instance.MinerProfile.AutoNoUiMinutes) < message.BornOn) { VirtualRoot.ThisLocalInfo(nameof(MainWindow), $"挖矿中界面展示{NTMinerContext.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置"); VirtualRoot.Execute(new CloseMainWindowCommand(isAutoNoUi: true)); } } }); #if DEBUG var elapsedMilliseconds = NTStopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { NTMinerConsole.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }
public MainWindow() { InitializeComponent(); NotiCenterWindow.Bind(this); }
public MainWindow() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif UIThread.StartTimer(); InitializeComponent(); if (Design.IsInDesignMode) { return; } this.StateChanged += (s, e) => { if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } }; this.SizeChanged += (object sender, SizeChangedEventArgs e) => { if (e.WidthChanged) { const double width = 720; if (e.NewSize.Width < width) { foreach (var tabItem in this.MainTab.Items.OfType <MainTabItem>()) { tabItem.Margin = new Thickness(0); } } else if (e.NewSize.Width >= width) { foreach (var tabItem in this.MainTab.Items.OfType <MainTabItem>()) { tabItem.Margin = new Thickness(8, 0, 8, 0); } } } }; EventHandler changeNotiCenterWindowLocation = NotiCenterWindow.CreateNotiCenterWindowLocationManager(this); this.Activated += changeNotiCenterWindowLocation; this.LocationChanged += changeNotiCenterWindowLocation; if (DevMode.IsDevMode) { this.On <ServerJsonVersionChangedEvent>("开发者模式展示ServerJsonVersion", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.ServerJsonVersion = Vm.GetServerJsonVersion(); }); }); } this.On <PoolDelayPickedEvent>("从内核输出中提取了矿池延时时展示到界面", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { if (message.IsDual) { Vm.StateBarVm.DualPoolDelayText = message.PoolDelayText; } else { Vm.StateBarVm.PoolDelayText = message.PoolDelayText; } }); }); this.On <MineStartedEvent>("开始挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.On <MineStopedEvent>("停止挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
public MainWindow() { this.MinHeight = 430; this.MinWidth = 640; this.Width = AppStatic.MainWindowWidth; this.Height = AppStatic.MainWindowHeight; #if DEBUG Write.Stopwatch.Restart(); #endif UIThread.StartTimer(); ConsoleWindow.Instance.OnSplashHided = MoveConsoleWindow; this.Owner = ConsoleWindow.Instance; InitializeComponent(); this.MainArea.SelectionChanged += (sender, e) => { var selectedItem = MainArea.SelectedItem; if (selectedItem == TabItemToolbox) { if (ToolboxContainer.Child == null) { ToolboxContainer.Child = new Toolbox(); } } else if (selectedItem == TabItemMinerProfileOption) { if (MinerProfileOptionContainer.Child == null) { MinerProfileOptionContainer.Child = new MinerProfileOption(); } } }; _borderBrush = this.BorderBrush; NTMinerRoot.RefreshArgsAssembly.Invoke(); if (Design.IsInDesignMode) { return; } ToogleLeft(); this.IsVisibleChanged += (sender, e) => { if (this.IsVisible) { NTMinerRoot.IsUiVisible = true; NTMinerRoot.MainWindowRendedOn = DateTime.Now; } else { NTMinerRoot.IsUiVisible = false; } MoveConsoleWindow(); }; this.ConsoleRectangle.IsVisibleChanged += (sender, e) => { MoveConsoleWindow(); }; this.StateChanged += (s, e) => { if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } if (WindowState == WindowState.Maximized) { ResizeCursors.Visibility = Visibility.Collapsed; this.BorderBrush = WpfUtil.BlackBrush; } else { ResizeCursors.Visibility = Visibility.Visible; this.BorderBrush = _borderBrush; } MoveConsoleWindow(); }; this.SizeChanged += (s, e) => { if (!ConsoleRectangle.IsVisible) { ConsoleWindow.Instance.Hide(); } }; this.ConsoleRectangle.SizeChanged += (s, e) => { MoveConsoleWindow(); }; EventHandler changeNotiCenterWindowLocation = NotiCenterWindow.CreateNotiCenterWindowLocationManager(this); this.Activated += (sender, e) => { changeNotiCenterWindowLocation(sender, e); NotiCenterWindow.Instance.SwitchOwner(this); }; this.LocationChanged += (sender, e) => { MoveConsoleWindow(); changeNotiCenterWindowLocation(sender, e); }; VirtualRoot.BuildCmdPath <CloseMainWindowCommand>(action: message => { UIThread.Execute(() => { if (NTMinerRoot.Instance.MinerProfile.IsCloseMeanExit) { VirtualRoot.Execute(new CloseNTMinerCommand()); return; } this.Close(); VirtualRoot.Out.ShowSuccess(message.Message, "开源矿工"); }); }); if (DevMode.IsDevMode) { this.WindowContextEventPath <ServerJsonVersionChangedEvent>("开发者模式展示ServerJsonVersion", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.ServerJsonVersion = NTMinerRoot.Instance.GetServerJsonVersion(); }); }); } this.WindowContextEventPath <PoolDelayPickedEvent>("从内核输出中提取了矿池延时时展示到界面", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { if (message.IsDual) { Vm.StateBarVm.DualPoolDelayText = message.PoolDelayText; } else { Vm.StateBarVm.PoolDelayText = message.PoolDelayText; } }); }); this.WindowContextEventPath <MineStartedEvent>("开始挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.WindowContextEventPath <MineStopedEvent>("停止挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.WindowContextEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式 和 守护进程状态显示", LogEnum.DevConsole, action: message => { if (NTMinerRoot.IsUiVisible && NTMinerRoot.Instance.MinerProfile.IsAutoNoUi && NTMinerRoot.Instance.IsMining) { if (NTMinerRoot.MainWindowRendedOn.AddMinutes(NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes) < message.Timestamp) { VirtualRoot.Execute(new CloseMainWindowCommand($"界面展示{NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置")); } } Vm.RefreshDaemonStateBrush(); }); RefreshCpu(); #if DEBUG Write.DevTimeSpan($"耗时{Write.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
public LoginWindow() { InitializeComponent(); NotiCenterWindow.Bind(this, isNoOtherWindow: true); this.PbPassword.Focus(); }
public MainWindow() { #if DEBUG VirtualRoot.Stopwatch.Restart(); #endif UIThread.StartTimer(); InitializeComponent(); if (Design.IsInDesignMode) { return; } this.StateChanged += (s, e) => { if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } }; this.SizeChanged += (object sender, SizeChangedEventArgs e) => { if (e.WidthChanged) { const double width = 800; if (e.NewSize.Width < width) { Collapse(); } else if (e.NewSize.Width >= width) { Expand(); } } }; EventHandler changeNotiCenterWindowLocation = NotiCenterWindow.CreateNotiCenterWindowLocationManager(this); this.Activated += changeNotiCenterWindowLocation; this.LocationChanged += changeNotiCenterWindowLocation; if (DevMode.IsDevMode) { this.On <ServerJsonVersionChangedEvent>("开发者模式展示ServerJsonVersion", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.ServerJsonVersion = Vm.GetServerJsonVersion(); }); }); } this.On <PoolDelayPickedEvent>("从内核输出中提取了矿池延时时展示到界面", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { if (message.IsDual) { Vm.StateBarVm.DualPoolDelayText = message.PoolDelayText; } else { Vm.StateBarVm.PoolDelayText = message.PoolDelayText; } }); }); this.On <MineStartedEvent>("开始挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.On <MineStopedEvent>("停止挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.On <Per1MinuteEvent>("挖矿中时自动切换为无界面模式 和 守护进程状态显示", LogEnum.DevConsole, action: message => { if (NTMinerRoot.IsUiVisible && NTMinerRoot.GetIsAutoNoUi() && NTMinerRoot.Instance.IsMining) { if (NTMinerRoot.MainWindowRendedOn.AddMinutes(NTMinerRoot.GetAutoNoUiMinutes()) < message.Timestamp) { VirtualRoot.Execute(new CloseMainWindowCommand($"界面展示{NTMinerRoot.GetAutoNoUiMinutes()}分钟后自动切换为无界面模式,可在选项页调整配置")); } } Vm.RefreshDaemonStateBrush(); }); #if DEBUG Write.DevWarn($"耗时{VirtualRoot.Stopwatch.ElapsedMilliseconds}毫秒 {this.GetType().Name}.ctor"); #endif }
public MainWindow() { this.MinHeight = 430; this.MinWidth = 640; this.Width = AppStatic.MainWindowWidth; this.Height = AppStatic.MainWindowHeight; #if DEBUG Write.Stopwatch.Start(); #endif this.Loaded += (sender, e) => { ConsoleWindow.Instance.Show(); ConsoleWindow.Instance.MouseDown += (ss, ee) => { MoveConsoleWindow(); }; this.Owner = ConsoleWindow.Instance; hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource; hwndSource.AddHook(new HwndSourceHook(Win32MessageProc.WindowProc)); MoveConsoleWindow(); }; InitializeComponent(); BtnMinerProfileGrip.Visibility = Visibility.Collapsed; if (WpfUtil.IsInDesignMode) { return; } UIThread.StartTimer(); _borderBrush = this.BorderBrush; DateTime lastGetServerMessageOn = DateTime.MinValue; NTMinerRoot.RefreshArgsAssembly.Invoke(); // 切换了主界面上的Tab时 this.MainArea.SelectionChanged += (sender, e) => { // 延迟创建,以加快主界面的启动 var selectedItem = MainArea.SelectedItem; if (selectedItem == TabItemSpeedTable) { if (SpeedTableContainer.Child == null) { SpeedTableContainer.Child = GetSpeedTable(); } } else if (selectedItem == TabItemMessage) { if (MessagesContainer.Child == null) { MessagesContainer.Child = new Messages(); } } else if (selectedItem == TabItemToolbox) { if (ToolboxContainer.Child == null) { ToolboxContainer.Child = new Toolbox(); } } else if (selectedItem == TabItemMinerProfileOption) { if (MinerProfileOptionContainer.Child == null) { MinerProfileOptionContainer.Child = new MinerProfileOption(); } } VirtualRoot.SetIsServerMessagesVisible(selectedItem == TabItemMessage); if (selectedItem == TabItemMessage) { if (lastGetServerMessageOn.AddSeconds(10) < DateTime.Now) { lastGetServerMessageOn = DateTime.Now; VirtualRoot.Execute(new LoadNewServerMessageCommand()); } } }; this.IsVisibleChanged += (sender, e) => { if (this.IsVisible) { NTMinerRoot.IsUiVisible = true; NTMinerRoot.MainWindowRendedOn = DateTime.Now; } else { NTMinerRoot.IsUiVisible = false; } MoveConsoleWindow(); }; this.ConsoleRectangle.IsVisibleChanged += (sender, e) => { MoveConsoleWindow(); }; this.StateChanged += (s, e) => { if (Vm.MinerProfile.IsShowInTaskbar) { ShowInTaskbar = true; } else { if (WindowState == WindowState.Minimized) { ShowInTaskbar = false; } else { ShowInTaskbar = true; } } if (WindowState == WindowState.Maximized) { ResizeCursors.Visibility = Visibility.Collapsed; this.BorderBrush = WpfUtil.BlackBrush; } else { ResizeCursors.Visibility = Visibility.Visible; this.BorderBrush = _borderBrush; } MoveConsoleWindow(); }; this.ConsoleRectangle.SizeChanged += (s, e) => { MoveConsoleWindow(); }; NotiCenterWindow.Bind(this, ownerIsTopMost: true); this.LocationChanged += (sender, e) => { MoveConsoleWindow(); }; VirtualRoot.BuildCmdPath <CloseMainWindowCommand>(action: message => { UIThread.Execute(() => { this.Close(); }); }); this.BuildEventPath <PoolDelayPickedEvent>("从内核输出中提取了矿池延时时展示到界面", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { if (message.IsDual) { Vm.StateBarVm.DualPoolDelayText = message.PoolDelayText; } else { Vm.StateBarVm.PoolDelayText = message.PoolDelayText; } }); }); this.BuildEventPath <MineStartedEvent>("开始挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.BuildEventPath <MineStopedEvent>("停止挖矿后将清空矿池延时", LogEnum.DevConsole, action: message => { UIThread.Execute(() => { Vm.StateBarVm.PoolDelayText = string.Empty; Vm.StateBarVm.DualPoolDelayText = string.Empty; }); }); this.BuildEventPath <Per1MinuteEvent>("挖矿中时自动切换为无界面模式 和 守护进程状态显示", LogEnum.DevConsole, action: message => { if (NTMinerRoot.IsUiVisible && NTMinerRoot.Instance.MinerProfile.IsAutoNoUi && NTMinerRoot.Instance.IsMining) { if (NTMinerRoot.MainWindowRendedOn.AddMinutes(NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes) < message.Timestamp) { VirtualRoot.Out.ShowSuccess($"界面展示{NTMinerRoot.Instance.MinerProfile.AutoNoUiMinutes}分钟后自动切换为无界面模式,可在选项页调整配置", "开源矿工"); VirtualRoot.Execute(new CloseMainWindowCommand()); } } }); this.BuildEventPath <CpuPackageStateChangedEvent>("CPU包状态变更后刷新Vm内存", LogEnum.None, action: message => { UIThread.Execute(UpdateCpuView); }); #if DEBUG var elapsedMilliseconds = Write.Stopwatch.Stop(); if (elapsedMilliseconds.ElapsedMilliseconds > NTStopwatch.ElapsedMilliseconds) { Write.DevTimeSpan($"耗时{elapsedMilliseconds} {this.GetType().Name}.ctor"); } #endif }