Beispiel #1
0
        public AppDelegate()
        {
            Forms.Init();
            Application.SetCurrentApplication(app = new App());
            CreateStatusItems();
            SubscribeEvents();

            IssueLauncher.Initialize(new MacMessageBox());
        }
Beispiel #2
0
 static async Task <Settings?> GetSettings()
 {
     try
     {
         return(await SettingsHelper.Read());
     }
     catch (Exception exception)
     {
         var message = $"Cannot start. Failed to read settings: {SettingsHelper.FilePath}";
         Log.Fatal(exception, message);
         IssueLauncher.LaunchForException(message, exception);
         return(null);
     }
 }
Beispiel #3
0
 public static void Handle(string message, Exception exception)
 {
     Log.Error(exception, message);
     IssueLauncher.LaunchForException(message, exception);
 }
Beispiel #4
0
    static async Task Main()
    {
        Logging.Init();

        var settings = await GetSettings();

        if (settings == null)
        {
            return;
        }
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        var tokenSource  = new CancellationTokenSource();
        var cancellation = tokenSource.Token;

        using var mutex = new Mutex(true, "DiffEngine", out var createdNew);
        if (!createdNew)
        {
            Log.Information("Mutex already exists. Exiting.");
            return;
        }


        using var icon = new NotifyIcon
              {
                  Icon    = Images.Default,
                  Visible = true,
                  Text    = "DiffEngine"
              };

        var showMenu = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic) !;

        icon.MouseUp += (sender, args) =>
        {
            if (args.Button == MouseButtons.Left)
            {
                showMenu.Invoke(icon, null);
            }
        };

        await using var tracker = new Tracker(
                        active: () => icon.Icon   = Images.Active,
                        inactive: () => icon.Icon = Images.Default);

        using var task = StartServer(tracker, cancellation);

        using var keyRegister = new KeyRegister(icon.Handle());
        ReBindKeys(settings, keyRegister, tracker);


        icon.ContextMenuStrip = new ContextMenuStrip();
        var messageBox = new WindowsMessageBox(icon.ContextMenuStrip);

        MenuBuilder.Build(icon.ContextMenuStrip,
                          Application.Exit,
                          async() => await OptionsFormLauncher.Launch(messageBox, keyRegister, tracker),
                          tracker);
        IssueLauncher.Initialize(messageBox);

        Application.Run();
        tokenSource.Cancel();
        await task;
    }