Пример #1
0
        public static void CollectAndShowReleaseNotes()
        {
            Task.Run(() =>
            {
                try
                {
                    var json = DownloadJson("https://api.github.com/repos/xupefei/QuickLook/releases");

                    var notes = string.Empty;

                    foreach (var item in json)
                    {
                        notes += $"# {item["name"]}\r\n\r\n";
                        notes += item["body"] + "\r\n\r\n";
                    }

                    var changeLogPath = Path.GetTempFileName() + ".md";
                    File.WriteAllText(changeLogPath, notes);

                    PipeServerManager.SendMessage(PipeMessages.Invoke, changeLogPath);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                    Application.Current.Dispatcher.Invoke(
                        () => TrayIconManager.ShowNotification("",
                                                               string.Format(TranslationHelper.GetString("Update_Error"), e.Message)));
                }
            });
        }
Пример #2
0
        public void View(string path, ContextObject context)
        {
            _viewer = new SlideshowPanel();

            context.ViewerContent = _viewer;
            context.Title         = $"{Path.GetFileName(path)}";

            _entries = new List <string>(
                Directory.GetFiles(path, "*.*", SearchOption.AllDirectories));
            _viewer.ShowEntriesFound(_entries);

            _viewer.StartSlideshow += () =>
            {
                var cts   = new CancellationTokenSource();
                var token = cts.Token;

                int numberOfSeconds = _viewer.NumberOfSeconds * 1000;
                Task.Run(async() =>
                {
                    foreach (var entry in _entries)
                    {
                        if (token.IsCancellationRequested)
                        {
                            break;
                        }
                        PipeServerManager.SendMessage(
                            PipeMessages.Switch, entry);

                        await Task.Delay(numberOfSeconds);
                    }
                    ;
                });

                Task.Run(() =>
                {
                    var PipeName = "QuickLook.App.Pipe." + WindowsIdentity.GetCurrent().User?.Value;

                    var _server = new NamedPipeServerStream(PipeName, PipeDirection.In, 2);

                    using (var reader = new StreamReader(_server))
                    {
                        while (true)
                        {
                            _server.WaitForConnection();
                            var msg = reader.ReadLine();

                            _server.Disconnect();
                            if (msg.IndexOf("Close") > -1)
                            {
                                _server.Dispose();
                                cts.Cancel();
                                break;
                            }
                        }
                    }
                });
            };

            context.IsBusy = false;
        }