Esempio n. 1
0
        public App()
        {
            // FirstFloor.ModernUI initialization (library used here is a forked version from Content Manager project with extra bits)
            ValuesStorage.Initialize(TypoModel.DataFilename, "_key_zsu4b3ws1k17ties_" + Environment.UserName, true);
            CacheStorage.Initialize();
            Logging.Initialize(TypoModel.LogFilename, false);
            Logging.Write($"App version: {BuildInformation.AppVersion} ({BuildInformation.Platform}, {WindowsVersionHelper.GetVersion()})");

            if (Directory.GetFiles(TypoModel.DataDirectory).Length == 0)
            {
                using (var memory = new MemoryStream(Typo4.Properties.Resources.Typo4Data)) {
                    new ZipArchive(memory).ExtractToDirectory(TypoModel.DataDirectory);
                }
            }

            AppearanceManager.Current.Initialize();
            AppearanceManager.Current.SetTheme(new Uri("pack://application:,,,/Typo4;component/Assets/AppTheme.xaml", UriKind.Absolute));
            AppearanceManager.Current.BoldTitleLinks   = false;
            AppearanceManager.Current.LargerTitleLinks = false;
            AppearanceManager.Current.SubMenuFontSize  = FontSize.Small;
            Resources.MergedDictionaries.Add(new ResourceDictionary {
                Source = new Uri("pack://application:,,,/Typo4;component/Assets/AppAssets.xaml", UriKind.Absolute)
            });

            MuiSystemAccent.Initialize();
            NonfatalError.Initialize();
            AppIconService.Initialize(this);
            FatalErrorMessage.Register(this);

            // All logic in relationship to UI
            _typoModel = new TypoModel();

            // Some more UI initialization bits
            PrepareUi();
            AppShortcut.Initialize("x4fab.Typo4", "Typo4");
            Toast.SetDefaultAction(() => (Current.Windows.OfType <ModernWindow>().FirstOrDefault(x => x.IsActive) ??
                                          Current.MainWindow as ModernWindow)?.BringToFront());
            BbCodeBlock.OptionEmojiProvider = this;

            // Let’s at least try to handle stuff properly
            AppDomain.CurrentDomain.ProcessExit += OnProcessExit;

            // Log stuff using FirstFloor.ModernUI library
            TypoLogging.Logger = (s, m, p, l) => Logging.Write($"{s} (Typo)", m, p, l);
            TypoLogging.TypoLoggingNonFatalErrorHandler = (s, c, e) => NonfatalError.Notify(s, c, e);

            // Most of the time app should work from system tray
            _typoModel.Initialize();
            _trayInterface = new TrayInterface(_typoModel);

            // Close only manually
            ShutdownMode = ShutdownMode.OnExplicitShutdown;

            // Fancy blur for all windows
            DpiAwareWindow.NewWindowCreated += OnWindowLoaded;
        }
Esempio n. 2
0
        public TrayInterface(TypoModel model)
        {
            _model = model;
            _icon  = new TaskbarIcon {
                Icon        = AppIconService.GetTrayIcon(),
                ToolTipText = "Typo4 is running",
                ContextMenu = new ContextMenu {
                    Items =
                    {
                        new MenuItem             {
                            Header = "Open data directory", Command = _model.OpenDataDirectoryCommand
                        },
                        new MenuItem             {
                            Header = "Run Typo4 when my computer starts", IsCheckable = true
                        }.AddBinding(MenuItem.IsCheckedProperty,
                                     new Binding {
                            Path = new PropertyPath(nameof(_model.Autorun.IsActive)), Source = _model.Autorun, Mode = BindingMode.TwoWay
                        }),
                        new MenuItem             {
                            Header = "Settings", Command = new DelegateCommand(WakeUp)
                        },
#if DEBUG
                        new Separator(),
                        new MenuItem             {
                            Header = "Debug window", IsCheckable = true
                        }.AddBinding(MenuItem.IsCheckedProperty,
                                     new Binding {
                            Path = new PropertyPath(nameof(model.Typo.IsDebugFormActive)), Source = model.Typo, Mode = BindingMode.TwoWay
                        }),
#endif
                        new Separator(),
                        new MenuItem             {
                            Header = "Exit", Command = new DelegateCommand(Exit)
                        }
                    }
                },
                DoubleClickCommand = new DelegateCommand(WakeUp)
            };
        }