protected override void Run()
 {
     RPC_Config.Load();
     if (RPC_Config.Current.Enabled)
     {
         Task.Run(() => RPCController.StartRPC());
     }
 }
示例#2
0
        public static void Load()
        {
            if (!File.Exists(FilePath))
            {
                Save();
            }

            var xs = new XmlSerializer(typeof(RPC_Config));

            using (var sr = new StreamReader(FilePath))
            {
                _current = (RPC_Config)xs.Deserialize(sr);
            }
        }
示例#3
0
        protected override void Run()
        {
            RPC_Config.Current.Enabled = !RPC_Config.Current.Enabled;

            RPC_Config.Save();
            if (RPC_Config.Current.Enabled)
            {
                Task.Run(() => RPCController.StartRPC());
            }
            else
            {
                RPCController.StopRPC();
            }

            RPCController.UpdatePresence();
        }
示例#4
0
 protected override void Run()
 {
     RPC_Config.Current.ShowFileIcon = !RPC_Config.Current.ShowFileIcon;
     RPCController.UpdatePresence();
     RPC_Config.Save();
 }
示例#5
0
 protected override void Run()
 {
     RPC_Config.Current.ResetTimeOnFileChange = !RPC_Config.Current.ResetTimeOnFileChange;
     RPCController.UpdatePresence();
     RPC_Config.Save();
 }
示例#6
0
 protected override void Run()
 {
     RPC_Config.Current.ShowSolutionName = !RPC_Config.Current.ShowSolutionName;
     RPCController.UpdatePresence();
     RPC_Config.Save();
 }
        public static void StartRPC()
        {
            RPC_Config.Load();

            MonoDevelop.Ide.IdeApp.Workspace.SolutionLoaded        += Workspace_SolutionLoaded;
            MonoDevelop.Ide.IdeApp.Workspace.SolutionUnloaded      += Workspace_SolutionUnloaded;
            MonoDevelop.Ide.IdeApp.Workbench.ActiveDocumentChanged += Workbench_ActiveDocumentChanged;
            MonoDevelop.Ide.IdeApp.Workspace.FileRenamedInProject  += Workspace_FileRenamedInProject;

            using (client = new DiscordRpcClient("595335536802267187"))
            {
                client.SetPresence(presence);

                client.Initialize();

                while (client != null)
                {
                    Thread.Sleep(250);

                    UpdatePresence();
                }
            }

            void Workspace_FileRenamedInProject(object sender, MonoDevelop.Projects.ProjectFileRenamedEventArgs e)
            {
                var document = MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument;

                if (document != null)
                {
                    foreach (var item in e)
                    {
                        if (item.OldName.FileName == document.FileName.FileName)
                        {
                            presence.Assets.LargeImageKey = GetIcon(item.NewName);
                            presence.State = $"Editing {item.NewName.FileName}";
                            break;
                        }
                    }
                }
            }

            void Workbench_ActiveDocumentChanged(object sender, EventArgs e)
            {
                if (RPC_Config.Current.ResetTimeOnFileChange)
                {
                    presence.Timestamps = new Timestamps(DateTime.UtcNow);
                }
                var document = MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument;

                if (document != null)
                {
                    presence.Assets.LargeImageKey = GetIcon(document.FileName);
                    presence.State = $"Editing {document.FileName.FileName}";
                }
            }

            void Workspace_SolutionLoaded(object sender, MonoDevelop.Projects.SolutionEventArgs e)
            {
                presence.Timestamps = new Timestamps(DateTime.UtcNow);

                presence.Details = e.Solution.Name;
            }

            void Workspace_SolutionUnloaded(object sender, MonoDevelop.Projects.SolutionEventArgs e)
            {
                presence = new RichPresence
                {
                    Details = "Home screen",
                    Assets  = new Assets()
                    {
                        LargeImageKey = "logo",
                        SmallImageKey = "logo",
                    }
                };
                client.SetPresence(presence);
            }
        }