Example #1
0
        /// <summary>
        /// Alternative Form_load method since form_load doesnt get called until you first double-click the RemindMe icon due to override SetVisibleCore
        /// </summary>
        private async Task formLoadAsync()
        {
            BLIO.Log("RemindMe_Load");

            BLIO.WriteUpdateBatch(Application.StartupPath);

            lblVersion.Text = "Version " + IOVariables.RemindMeVersion;



            Settings set = BLSettings.GetSettings();

            if (set.LastVersion != null && (new Version(set.LastVersion) < new Version(IOVariables.RemindMeVersion)))
            {
                //User has a new RemindMe version!
                string releaseNotesString = "";

                foreach (KeyValuePair <string, string> entry in UpdateInformation.ReleaseNotes)
                {
                    if (new Version(entry.Key) > new Version(set.LastVersion))
                    {
                        releaseNotesString += "Version " + entry.Key + "\r\n" + entry.Value + "\r\n\r\n\r\n";
                    }
                }
                WhatsNew wn = new WhatsNew(set.LastVersion, releaseNotesString);
                wn.Show();

                //Update lastVersion
                set.LastVersion = IOVariables.RemindMeVersion;
                BLSettings.UpdateSettings(set);
            }

            //Default view should be reminders
            pnlMain.Controls.Add(ucReminders);

            MessageFormManager.MakeTodaysRemindersPopup();
            BLIO.Log("Today's reminders popup created");

            //Create an shortcut in the windows startup folder if it doesn't already exist
            if (!File.Exists(IOVariables.startupFolderPath + "\\RemindMe" + ".lnk"))
            {
                FSManager.Shortcuts.CreateShortcut(IOVariables.startupFolderPath, "RemindMe", System.Windows.Forms.Application.StartupPath + "\\" + "RemindMe.exe", "Shortcut of RemindMe");
            }


            if (Debugger.IsAttached)
            {//Debugging ? show extra option
                btnDebugMode.Visible = true;
            }


            BLSongs.InsertWindowsSystemSounds();

            BLIO.Log("RemindMe loaded");
            Cleanup();

            tmrUpdateRemindMe.Start();

            //If the setup still exists, delete it
            File.Delete(IOVariables.rootFolder + "SetupRemindMe.msi");

            //Call the timer once
            Thread tr = new Thread(() =>
            {
                //wait a bit, then call the update timer once. It then runs every 5 minutes
                Thread.Sleep(5000);
                tmrUpdateRemindMe_Tick(null, null);
            });

            tr.Start();


            this.Opacity       = 0;
            this.ShowInTaskbar = true;
            this.Show();
            tmrInitialHide.Start();
        }
Example #2
0
        private void tmrCheckReminder_Tick(object sender, EventArgs e)
        {
            if (BLReminder.GetReminders().Where(r => r.Enabled == 1).ToList().Count <= 0)
            {
                tmrCheckReminder.Stop(); //No existing reminders? no enabled reminders? stop timer.
                BLIO.Log("Stopping the reminder checking timer, because there are no more (enabled) reminders");
                return;
            }

            //If a day has passed since the start of RemindMe, we may want to refresh the listview.
            //There might be reminders happening on this day, if so, we show the time of the reminder, instead of the day
            if (dayOfStartRemindMe < DateTime.Now.Day)
            {
                BLIO.Log("Dawn of a new day -24 hours remaining- ");
                UpdateCurrentPage();
                dayOfStartRemindMe = DateTime.Now.Day;
                MessageFormManager.MakeTodaysRemindersPopup();
            }


            //We will check for reminders here every 5 seconds.
            foreach (Reminder rem in BLReminder.GetReminders())
            {
                //Create the popup. Do the other stuff afterwards.
                if ((rem.PostponeDate != null && Convert.ToDateTime(rem.PostponeDate) <= DateTime.Now && rem.Enabled == 1) || (Convert.ToDateTime(rem.Date.Split(',')[0]) <= DateTime.Now && rem.PostponeDate == null && rem.Enabled == 1))
                {
                    //temporarily disable it. When the user postpones the reminder, it will be re-enabled.
                    rem.Enabled = 0;
                    BLReminder.EditReminder(rem);
                    MakeReminderPopup(rem);
                    UpdateCurrentPage();
                }
                else
                {
                    // -- In this part we will create popups at the users right bottom corner of the screen saying x reminder is happening in 1 hour or x minutes -- \\
                    if (BLSettings.IsHourBeforeNotificationEnabled() && rem.Enabled == 1)
                    {
                        DateTime theDateToCheckOn; //Like this we dont need an if ánd an else with the same code
                        if (rem.PostponeDate != null)
                        {
                            theDateToCheckOn = Convert.ToDateTime(rem.PostponeDate);
                        }
                        else
                        {
                            theDateToCheckOn = Convert.ToDateTime(rem.Date.Split(',')[0]);
                        }


                        //The timespan between the date and now.
                        TimeSpan timeSpan = Convert.ToDateTime(theDateToCheckOn) - DateTime.Now;
                        if (timeSpan.TotalMinutes >= 59.50 && timeSpan.TotalMinutes <= 60)
                        {
                            remindersToHappenInAnHour.Add(rem);
                        }
                    }
                }
            }


            string message = "You have " + remindersToHappenInAnHour.Count + " reminders set in 60 minutes:\r\n";
            int    count   = 1;

            foreach (Reminder rem in remindersToHappenInAnHour)
            {
                if (remindersToHappenInAnHour.Count > 1)
                {
                    message += count + ") " + rem.Name + Environment.NewLine;
                }
                else
                {
                    message = rem.Name + " in 60 minutes!";
                }

                count++;
            }

            if (remindersToHappenInAnHour.Count > 1) //cut off the last \n
            {
                message = message.Remove(message.Length - 2, 2);

                if (!popupMessages.Contains(message)) //Don't create this popup if we have already created it once before
                {
                    MessageFormManager.MakeMessagePopup(message, 8);
                }

                popupMessages.Add(message);
            }
            else if (remindersToHappenInAnHour.Count > 0)
            {
                if (!popupMessages.Contains(message)) //Don't create this popup if we have already created it once before
                {
                    MessageFormManager.MakeMessagePopup(message, 8, remindersToHappenInAnHour[0]);
                }

                popupMessages.Add(message);
            }

            remindersToHappenInAnHour.Clear();
        }