コード例 #1
0
        public void Run()
        {
            bool justCreated = SettingsView.EnsureDefaults();

            bool clearAtStartup = !SettingsViewModel.Load().RestoreHistoryAtStartup;

            ClipboardMonitor.Start(clearAtStartup);

            TrayIcon.ShowHistory  = (s, a) => HistoryView.Popup();
            TrayIcon.ShowSettings = (s, a) => SettingsView.Popup();
            TrayIcon.Rehook       = (s, a) => { ClipboardMonitor.Restart(); TrayIcon.RefreshIcon(); };
            TrayIcon.Test         = (s, a) => ClipboardMonitor.Test();
            TrayIcon.Exit         = (s, a) => this.Close();
            TrayIcon.Init();

            hotKeys.Start();

            HotKeysMapping.EmbeddedHandlers[HistoryView.PopupActionName]            = HistoryView.Popup;
            HotKeysMapping.EmbeddedHandlers[ClipboardMonitor.ToPlainTextActionName] = ClipboardMonitor.ToPlainText;
            HotKeysMapping.EmbeddedHandlers[HotKeysView.PopupActionName]            = HotKeysView.Popup;
            HotKeysMapping.EmbeddedHandlers[ClipboardMonitor.RestartActionName]     = ClipboardMonitor.Restart;

            HotKeysMapping.Bind(hotKeys, TrayIcon.InvokeMenu);

            var timer     = new System.Windows.Threading.DispatcherTimer();
            var lastCheck = DateTime.Now;

            timer.Tick += (s, e) =>
            {
                ClipboardMonitor.Test();

                if ((DateTime.Now - lastCheck) > TimeSpan.FromMinutes(5)) // to ensure that after a long sleep we are restarting
                {
                    ClipboardMonitor.Restart();
                }

                lastCheck = DateTime.Now;

                // refreshing works but I am not convinced it is beneficial enough to be released
                // it also creates a short flickering effect every minute.
                // TrayIcon.RefreshIcon();
            };

            timer.Interval = TimeSpan.FromMinutes(1);

            timer.Start();

            var test2 = "The quick brown fox jumps over a lazy dog" + DateTime.Now;

            if (justCreated)
            {
                SettingsView.Popup(); //can pop it up without any side effect only after all messaging is initialized
            }
            SystemEvents.PowerModeChanged += OnPowerChange;
        }
コード例 #2
0
 private void Close()
 {
     try
     {
         ClipboardMonitor.Stop(shutdown: true);
         SettingsView.CloseIfAny();
         HistoryView.CloseIfAny();
         hotKeys.Stop();
         TrayIcon.Close();
     }
     catch { }
 }
コード例 #3
0
        void StartApp()
        {
            //The app must be hosted as x86 otherwise the Clipboard some operations can lead to
            //the CLR crash. Shocking!
            //
            //Very tempting to use Caliburn.Micro but for such a simple UI it's a bit overkill.
            //But more importantly the current CB.M depends on .NET v4.5 at least. It also requires
            //System.Windows.Interactivity, which is distributed by MS individually. Thus the deployment pressure
            //is to much for such a simple app as this one.
            //
            //Packing of MultiClip.exe into MultiClip.UI.exe resources is also motivated by the deployment considerations

            //SettingsView.Popup();
            //return;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            ClipboardMonitor.Restart();

            new Bootstrapper().Run();
        }
コード例 #4
0
        void Application_Startup(object sender, StartupEventArgs e)
        {
            // Debug.Assert(false);

            if (Environment.GetCommandLineArgs().Contains("-kill"))
            {
                var runningGui = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location))
                                 .Where(p => p.Id != Process.GetCurrentProcess().Id);

                foreach (var server in runningGui)
                {
                    try
                    {
                        server.Kill();
                    }
                    catch { }
                }
                ClipboardMonitor.KillAllServers();

                Shutdown();
            }
            else
            {
                Log.WriteLine($"=============== Started =================");
                Log.WriteLine(Assembly.GetExecutingAssembly().Location);
                //new SettingsView().ShowDialog();return;
                //IMPORTANT: Do not release the mutex. OS will release the mutex on app exit automatically.
                mutex = new Mutex(true, "multiclip.history");
                if (mutex.WaitOne(0))
                {
                    StartApp();
                }
                else
                {
                    Operations.MsgBox("Another instance of the application is already running.", "MultiClip");
                    Shutdown();
                }
            }
        }
コード例 #5
0
 static public void SetClipboardTo(string bufferLocation)
 {
     ClipboardMonitor.LoadSnapshot(bufferLocation);
 }
コード例 #6
0
 public void PurgeHistory()
 {
     ClipboardMonitor.ClearDuplicates();
 }
コード例 #7
0
 public void ClearHistory()
 {
     ClipboardMonitor.ClearAll();
 }