From 6ab21cd76ef48207f69ebc85be85394f965ee828 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sun, 30 Apr 2017 23:28:04 -0500 Subject: [PATCH] Options --- htdocs/index.html | 2 ++ htdocs/js/index.js | 8 +++++++- src/siadrive/siadrivehandler.cpp | 24 +++++++++++++++++++----- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/htdocs/index.html b/htdocs/index.html index 086d226..7b54edc 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -190,6 +190,8 @@

Launch file manager on mount



+

Close to system tray

+

Use Bundled siad



API Port

diff --git a/htdocs/js/index.js b/htdocs/js/index.js index bc0a737..14c6d4d 100644 --- a/htdocs/js/index.js +++ b/htdocs/js/index.js @@ -187,6 +187,11 @@ setChecked('ID_SettingsLaunchFileManager', launch); } }, + setCloseToTray: (closeToTray) => { + if (document.getElementById('sia_settings_window').classList.contains('hidden-element')) { + setChecked('ID_SettingsCloseToTray', closeToTray); + } + }, displayShutdownWindow: () => { const div = document.getElementById('shutdown_window'); document.body.innerHTML = ''; @@ -347,7 +352,8 @@ 'ApiPort': getValue('ID_SettingsApiPort'), 'HostPort': getValue('ID_SettingsHostPort'), 'RpcPort': getValue('ID_SettingsRPCPort'), - 'LaunchFileManager': getChecked('ID_SettingsLaunchFileManager') + 'LaunchFileManager': getChecked('ID_SettingsLaunchFileManager'), + 'CloseToTray': getChecked('ID_SettingsCloseToTray') }, (success, reason) => { if (success) { beginMainApplication(); diff --git a/src/siadrive/siadrivehandler.cpp b/src/siadrive/siadrivehandler.cpp index 63d0737..9b622a5 100644 --- a/src/siadrive/siadrivehandler.cpp +++ b/src/siadrive/siadrivehandler.cpp @@ -6,6 +6,8 @@ #include #include #include +#include + using namespace Sia; using namespace Sia::Api; @@ -18,6 +20,7 @@ CSiaDriveHandler* g_instance = nullptr; static HMENU g_trayMenu = nullptr; static WNDPROC g_defProc; static NOTIFYICONDATA g_notifyIcon = { 0 }; +static bool g_trayClose = false; static void ToggleWindowVisible(const HWND& wnd) { @@ -89,6 +92,11 @@ static LRESULT CALLBACK SiaWndProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lpa case MENU_ITEM_EXIT: { + if (!::IsWindowVisible(wnd)) + { + ToggleWindowVisible(wnd); + } + g_trayClose = true; ::PostMessage(wnd, WM_CLOSE, 0, 0); } break; @@ -96,6 +104,7 @@ static LRESULT CALLBACK SiaWndProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lpa } break; } + return ::CallWindowProc(g_defProc, wnd, msg, wparam, lparam); } #endif @@ -187,13 +196,18 @@ void CSiaDriveHandler::OnAfterCreated(CefRefPtr browser) bool CSiaDriveHandler::DoClose(CefRefPtr browser) { CEF_REQUIRE_UI_THREAD(); - + if (!_isClosing && (_browserList.size() == 1)) { - // Set a flag to indicate that the window close should be allowed. - _isClosing = true; - CefRefPtr msg = CefProcessMessage::Create("shutdownServices"); - browser->SendProcessMessage(PID_RENDERER, msg); + CSiaDriveConfig cfg(false); + if (!cfg.GetCloseToTray() || g_trayClose) + { + // Set a flag to indicate that the window close should be allowed. + _isClosing = true; + CefRefPtr msg = CefProcessMessage::Create("shutdownServices"); + browser->SendProcessMessage(PID_RENDERER, msg); + } + return true; }