bool MainWindow::minimizeToTray() {
	if (App::quitting() || !hasTrayIcon()) return false;

	closeWithoutDestroy();
	updateIsActive(Global::OfflineBlurTimeout());
	updateTrayMenu();
	updateGlobalMenu();
	showTrayTooltip();
	return true;
}
MainWindowController::MainWindowController(
    QWidget *parent,
    QString logPathOverride,
    QString dbPathOverride,
    QString scriptPath)
    : QMainWindow(parent),
      ui(new Ui::MainWindowController),
      togglApi(new TogglApi(0, logPathOverride, dbPathOverride)),
      tracking(false),
      loggedIn(false),
      actionEmail(0),
      actionNew(0),
      actionContinue(0),
      actionStop(0),
      actionSync(0),
      actionLogout(0),
      actionClear_Cache(0),
      actionSend_Feedback(0),
      actionReports(0),
      preferencesDialog(new PreferencesDialog(this)),
      aboutDialog(new AboutDialog(this)),
      feedbackDialog(new FeedbackDialog(this)),
      idleNotificationDialog(new IdleNotificationDialog(this)),
      trayIcon(0),
      reminder(false),
      pomodoro(false),
      script(scriptPath),
      ui_started(false) {
    TogglApi::instance->setEnvironment(APP_ENVIRONMENT);

    ui->setupUi(this);

    ui->menuBar->setVisible(true);

    QVBoxLayout *verticalLayout = new QVBoxLayout();
    verticalLayout->addWidget(new ErrorViewController());
    verticalLayout->addWidget(new LoginWidget());
    verticalLayout->addWidget(new TimeEntryListWidget());
    verticalLayout->addWidget(new TimeEntryEditorWidget());
    verticalLayout->setContentsMargins(0, 0, 0, 0);
    verticalLayout->setSpacing(0);
    centralWidget()->setLayout(verticalLayout);

    readSettings();

    connect(TogglApi::instance, SIGNAL(displayApp(bool)),  // NOLINT
            this, SLOT(displayApp(bool)));  // NOLINT

    connect(TogglApi::instance, SIGNAL(displayStoppedTimerState()),  // NOLINT
            this, SLOT(displayStoppedTimerState()));  // NOLINT

    connect(TogglApi::instance, SIGNAL(displayRunningTimerState(TimeEntryView*)),  // NOLINT
            this, SLOT(displayRunningTimerState(TimeEntryView*)));  // NOLINT

    connect(TogglApi::instance, SIGNAL(displayLogin(bool,uint64_t)),  // NOLINT
            this, SLOT(displayLogin(bool,uint64_t)));  // NOLINT

    connect(TogglApi::instance, SIGNAL(displayReminder(QString,QString)),  // NOLINT
            this, SLOT(displayReminder(QString,QString)));  // NOLINT

    connect(TogglApi::instance, SIGNAL(displayUpdate(QString)),  // NOLINT
            this, SLOT(displayUpdate(QString)));  // NOLINT

    connect(TogglApi::instance, SIGNAL(displayOnlineState(int64_t)),  // NOLINT
            this, SLOT(displayOnlineState(int64_t)));  // NOLINT


    hasTrayIconCached = hasTrayIcon();
    if (hasTrayIconCached) {
        icon.addFile(QString::fromUtf8(":/icons/1024x1024/toggldesktop.png"));

        iconDisabled.addFile(QString::fromUtf8(
                                 ":/icons/1024x1024/toggldesktop_gray.png"));

        trayIcon = new QSystemTrayIcon(this);
    }

    connectMenuActions();
    enableMenuActions();

    if (hasTrayIconCached) {
        // icon is set in enableMenuActions based on if tracking is in progress
        trayIcon->show();
    } else {
        setWindowIcon(icon);
    }
}