Example #1
0
        public async Task Initialize()
        {
            await model.Initialize();

            //modelの初期化エラーへの対処はShellViewModelでするので全部無視
            if (model.State != Model.TVTCommentState.Working)
            {
                return;
            }

            WindowTopmost.Value  = model.Settings.View.WindowTopmost;
            WindowOpacity.Value  = model.Settings.View.WindowOpacity;
            WindowFontSize.Value = model.Settings.View.WindowFontSize;

            compositeDisposable.Add(WindowTopmost.Subscribe(x => model.Settings.View.WindowTopmost   = x));
            compositeDisposable.Add(WindowOpacity.Subscribe(x => model.Settings.View.WindowOpacity   = x));
            compositeDisposable.Add(WindowFontSize.Subscribe(x => model.Settings.View.WindowFontSize = x));

            //256段階でスライダーを動かすと大量にSetChatOpacityIPCMessageが発生してしまうため16段階にする
            ChatOpacity = model.ChatOpacity.MakeLinkedObservableValue(x => (byte)(x / 16), x => (byte)(x * 16));
            ClearChatsOnChannelChange = model.ChatModule.ClearChatsOnChannelChange;

            ChatCollectTimeAdjustment = model.ChatCollectServiceModule.TimeAdjustment;

            AddChatCollectTimeAdjustment = new DelegateCommand <int?>(time => { if (time.HasValue)
                                                                                {
                                                                                    ChatCollectTimeAdjustment.Value = ChatCollectTimeAdjustment.Value.Add(TimeSpan.FromSeconds(time.Value));
                                                                                }
                                                                      }, _ => true);
            SetChatCollectTimeAdjustment = new DelegateCommand <int?>(time => { if (time.HasValue)
                                                                                {
                                                                                    ChatCollectTimeAdjustment.Value = TimeSpan.FromSeconds(time.Value);
                                                                                }
                                                                      }, _ => true);

            PropertyChanged(this, new PropertyChangedEventArgs(null));
        }
Example #2
0
        private async Task initializeInternal()
        {
            if (initialized)
            {
                return;
            }
            initialized = true;

            // モデルの初期化
            try
            {
                await model.Initialize();

                await BasicSettingControlViewModel.Initialize();

                //await ChatPostControlViewModel.Initialize();
            }
            catch (Exception e)
            {
                AlertRequest.Raise(new Notification {
                    Title = "TVTCommentエラー", Content = $"初期化で予期しないエラーが発生しました\n{e.ToString()}"
                });
                CloseApplication();
                return;
            }
            if (model.State != Model.TVTCommentState.Working)
            {
                AlertRequest.Raise(new Notification {
                    Title = "TVTCommentエラー", Content = "Viewer側(TVTestプラグイン側)と接続できませんでした"
                });
                CloseApplication();
                return;
            }

            // 表示関係の設定復元
            Model.Serialization.WindowPositionEntity rect = model.Settings.View.MainWindowPosition;
            this.WindowPosition.X      = rect.X;
            this.WindowPosition.Y      = rect.Y;
            this.WindowPosition.Width  = rect.Width;
            this.WindowPosition.Height = rect.Height;

            ChatListColumnInfos = model.Settings.View.ChatListViewColumns?.Select(
                x => new Views.AttachedProperties.GridViewColumnSettingsBinder.ColumnInfo(x.Id, x.Width)
                ).ToArray();

            this.SelectedTab.Value = model.Settings.View.MainWindowTab;

            // ウィンドウの位置を復元したら最小化を解除
            Window window = Application.Current.MainWindow;

            window.WindowState = WindowState.Normal;

            // モデルのイベントハンドラを登録
            model.ChatCollectServiceModule.ErrorOccurredInChatCollecting  += model_ErrorOccurredInChatCollecting;
            model.ChatCollectServiceModule.ErrorOccurredInChatPosting     += model_ErrorOccurredInChatPosting;
            model.ChatCollectServiceModule.ErrorOccurredInServiceCreation += model_ErrorOccurredAtChatCollectServiceCreation;

            // モデルのプロパティを結びつける
            CurrentPlayTime = model.ChannelInformationModule.CurrentTime;
            CurrentChannel  = model.ChannelInformationModule.CurrentChannel;
            CurrentEvent    = model.ChannelInformationModule.CurrentEvent;

            disposables.Add(CurrentPlayTime.Subscribe(_ => updateWindowTitle()));
            disposables.Add(CurrentChannel.Subscribe(_ => updateWindowTitle()));
            disposables.Add(CurrentEvent.Subscribe(_ => updateWindowTitle()));

            // 旧ニコニコ実況が廃止されたので現状常にnull
            // 今後対応するときのためにとって置いてる
            forceValueData = new ReadOnlyObservableValue <Model.IForceValueData>(Observable.Return <Model.IForceValueData>(null));

            UseDefaultChatCollectService = model.DefaultChatCollectServiceModule.IsEnabled;

            model.CommandModule.ShowWindowCommandInvoked += commandModule_ShowWindowCommandInvoked;

            // コマンド生成
            ChangeChannelCommand = new DelegateCommand <Model.ChannelInfo>(channel => { if (channel != null)
                                                                                        {
                                                                                            model.ChannelInformationModule.SetCurrentChannel(channel);
                                                                                        }
                                                                           });

            AddChatCollectServiceCommand = new DelegateCommand <ShellContents.ChatCollectServiceAddListItemViewModel>(
                async x => { if (x != null)
                             {
                                 await addChatCollectService(x);
                             }
                },
                _ => !UseDefaultChatCollectService.Value
                );
            RemoveChatCollectServiceCommand = new DelegateCommand <Model.ChatCollectService.IChatCollectService>(
                service => { if (service != null)
                             {
                                 model.ChatCollectServiceModule.RemoveService(service);
                             }
                },
                _ => !UseDefaultChatCollectService.Value
                );
            UseDefaultChatCollectService.Subscribe(x => {
                AddChatCollectServiceCommand.RaiseCanExecuteChanged();
                RemoveChatCollectServiceCommand.RaiseCanExecuteChanged();
            });

            ClearChatsCommand = new DelegateCommand(() => model.ChatModule.ClearChats());
            AddWordNgCommand  = new DelegateCommand <Model.Chat>(chat =>
            {
                if (chat == null)
                {
                    return;
                }
                model.ChatModule.AddChatModRule(new Model.ChatModRules.WordNgChatModRule(model.ChatServices.SelectMany(x => x.ChatCollectServiceEntries), chat.Text));
            });
            AddUserNgCommand = new DelegateCommand <Model.Chat>(chat =>
            {
                if (chat == null)
                {
                    return;
                }
                model.ChatModule.AddChatModRule(new Model.ChatModRules.UserNgChatModRule(chat.SourceService.Owner.ChatCollectServiceEntries, chat.UserId));
            });
            CopyCommentCommand = new DelegateCommand <Model.Chat>(chat =>
            {
                if (chat == null)
                {
                    return;
                }
                Clipboard.SetText(chat.Text);
            });
            CopyUserCommand = new DelegateCommand <Model.Chat>(chat =>
            {
                if (chat == null)
                {
                    return;
                }
                Clipboard.SetText(chat.UserId);
            });

            OnPropertyChanged(null);
        }