Skip to content
API Documentation
BastionGuard™
ClamApp Class Reference
Inheritance diagram for ClamApp:

Public Member Functions

 ClamApp (bool start_minimized)
CefRefPtr< CefBrowserProcessHandler > GetBrowserProcessHandler () override
void OnBeforeCommandLineProcessing (const CefString &, CefRefPtr< CefCommandLine > cmd) override
 IMPLEMENT_REFCOUNTING (ClamApp)

Protected Member Functions

void on_activate () override

Private Member Functions

void launch_main_window ()

Private Attributes

MainWindow * win_ = nullptr
std::unique_ptr< TrayIcon > tray_
bool start_minimized_
bool holding_ = false

Detailed Description

Definition at line 240 of file main.cpp.

Constructor & Destructor Documentation

◆ ClamApp()

ClamApp::ClamApp ( bool start_minimized)
inline

Definition at line 242 of file main.cpp.

243 : Gtk::Application("org.BastionGuard.gui"),
244 start_minimized_(start_minimized)
245 {}
bool start_minimized_
Definition main.cpp:407

References start_minimized_.

Referenced by SecureBrowser::createApp(), IMPLEMENT_REFCOUNTING(), and main().

Member Function Documentation

◆ GetBrowserProcessHandler()

CefRefPtr< CefBrowserProcessHandler > ClamApp::GetBrowserProcessHandler ( )
inlineoverride

Definition at line 527 of file SecureBrowser.cpp.

527{ return this; }

◆ IMPLEMENT_REFCOUNTING()

ClamApp::IMPLEMENT_REFCOUNTING ( ClamApp )

References ClamApp().

◆ launch_main_window()

void ClamApp::launch_main_window ( )
inlineprivate

Definition at line 280 of file main.cpp.

280 {
281 win_ = new MainWindow();
282 add_window(*win_);
283
284 load_style();
285
286 win_->set_resizable(false);
287 win_->set_default_size(600, 400);
288
289 bool tray_ok = should_enable_trayicon();
290
291
292 const std::string xdg_current = getenv_str("XDG_CURRENT_DESKTOP");
293 const std::string xdg_session = getenv_str("XDG_SESSION_DESKTOP");
294 const std::string desktop_sess = getenv_str("DESKTOP_SESSION");
295
296 auto is = [&](const char* s) {
297 return icontains(xdg_current, s) || icontains(xdg_session, s) || icontains(desktop_sess, s);
298 };
299
300 const bool is_gnome = is("gnome");
301
302#if BASTIONGUARD_HAS_SDBUS
303 if (is_gnome) {
304 tray_ok = true;
305 }
306#else
307 tray_ok = false;
308#endif
309
310 const bool hide_on_close = tray_ok;
311
312
313 if (hide_on_close && !holding_) {
314 hold();
315 holding_ = true;
316 }
317
318 win_->signal_close_request().connect(
319 [this, hide_on_close]() -> bool {
320 if (!hide_on_close)
321 return false;
322
323 if (win_)
324 win_->hide();
325
326 return true;
327 },
328 false
329 );
330
331
332 if (start_minimized_ && !tray_ok) {
333 start_minimized_ = false;
334 }
335
336 if (!start_minimized_) {
337 win_->present();
338 } else {
339 win_->hide();
340 }
341
342 if (tray_ok) {
343 tray_ = std::make_unique<TrayIcon>();
344
345 tray_->bind_ui_context();
346
347 const std::string icon_path =
348 resolve_path("data/logo.png", std::string(DATA_DIR) + "/logo.png");
349
350 tray_->set_icon_file(icon_path, 32);
351 tray_->set_tooltip(_("BastionGuard in esecuzione"));
352
353 tray_->set_on_activate([this]() {
354 // NB: questa lambda è già dispatchata sul main loop GTK da TrayIcon
355 // via g_main_context_invoke(ui_ctx_, ...). Tuttavia, sd_bus può
356 // invocarla all'interno di sd_bus_process: per evitare che gtk_widget_show
357 // riesca a generare un GMainContext annidato dentro lo stack di un
358 // callback sd_bus (che è la causa del crash SIGTRAP visto in
359 // g_main_context_new_with_flags -> g_log fatale), differiamo
360 // ulteriormente di un giro idle del main loop.
361 Glib::signal_idle().connect_once([this]() {
362 if (!win_) return;
363 try {
364 // IMPORTANTE: present() PRIMA di showDashboard().
365 // Se l'app è stata avviata con --minimized, alla prima Activate
366 // dalla tray la finestra non è ancora "realized": chiamare
367 // showDashboard() (che fa grab_focus su widget non realizzati)
368 // emette un g_critical che, con G_DEBUG=fatal-criticals,
369 // termina il processo. Realizziamo la finestra prima.
370 win_->present();
372 } catch (const std::exception& ex) {
373 std::cerr << "[ClamApp] tray activate: " << ex.what() << std::endl;
374 } catch (...) {
375 std::cerr << "[ClamApp] tray activate: errore sconosciuto" << std::endl;
376 }
377 });
378 });
379
380 tray_->set_on_settings([this]() {
381 Glib::signal_idle().connect_once([this]() {
382 if (!win_) return;
383 try {
385 } catch (const std::exception& ex) {
386 std::cerr << "[ClamApp] tray settings: " << ex.what() << std::endl;
387 } catch (...) {
388 std::cerr << "[ClamApp] tray settings: errore sconosciuto" << std::endl;
389 }
390 });
391 });
392
393 tray_->set_on_quit([this]() {
394 Glib::signal_idle().connect_once([this]() {
395 if (tray_) tray_->stop();
396 quit();
397 });
398 });
399
400 tray_->start();
401 }
402}
#define _(s)
std::unique_ptr< TrayIcon > tray_
Definition main.cpp:406
bool holding_
Definition main.cpp:408
MainWindow * win_
Definition main.cpp:405
void open_settings_window()
void showDashboard()
#define DATA_DIR
Definition Resource.hpp:28
void load_style()
static std::string getenv_str(const char *k)
Definition main.cpp:59
static bool icontains(std::string hay, std::string needle)
Definition main.cpp:64
static std::string resolve_path(const std::string &local, const std::string &installed)
Definition main.cpp:118
static bool should_enable_trayicon()
Definition main.cpp:72

References _, DATA_DIR, getenv_str(), holding_, icontains(), load_style(), MainWindow::MainWindow(), MainWindow::open_settings_window(), resolve_path(), should_enable_trayicon(), MainWindow::showDashboard(), start_minimized_, tray_, and win_.

Referenced by on_activate().

◆ on_activate()

void ClamApp::on_activate ( )
inlineoverrideprotected

Definition at line 248 of file main.cpp.

248 {
249 if (win_) {
250 win_->present();
251 return;
252 }
253
254 if (wizard_needed()) {
255 auto wiz = new BastionGuard::wizard::WizardWindow();
256 add_window(*wiz);
257
258 load_style();
259
260 wiz->signal_finished().connect([this, wiz]() {
261 wiz->hide();
262 delete wiz;
264 });
265
266 wiz->present();
267 return;
268 }
269
271
273
274 if (!start_minimized_ && win_) {
275 win_->present();
276 }
277 }
void launch_main_window()
Definition main.cpp:280
static bool wizard_needed()
Definition main.cpp:123

References launch_main_window(), load_style(), FirstRunServicesWindow::maybe_show(), start_minimized_, win_, and wizard_needed().

◆ OnBeforeCommandLineProcessing()

void ClamApp::OnBeforeCommandLineProcessing ( const CefString & ,
CefRefPtr< CefCommandLine > cmd )
inlineoverride

Definition at line 529 of file SecureBrowser.cpp.

529 {
530 // Il Secure Browser usa un profilo CEF dedicato e persistente. Non
531 // forzare --incognito nel processo bancario/payment: gli auth cookie
532 // di sessione devono poter sopravvivere alla chiusura della finestra,
533 // altrimenti ogni riapertura appare come un nuovo device/sessione ai
534 // sistemi SCA/3DS/anti-abuso. La finestra notify resta invece
535 // incognito perché BG_CEF_PERSIST_SESSION non viene impostato lì.
536 if (std::getenv("BG_CEF_PERSIST_SESSION"))
537 cmd->AppendSwitch("persist-session-cookies");
538 else
539 cmd->AppendSwitch("incognito");
540
541 cmd->AppendSwitch("disable-extensions");
542 cmd->AppendSwitch("disable-sync");
543 cmd->AppendSwitch("disable-component-update");
544 cmd->AppendSwitch("disable-print-preview");
545
546 // Alcuni flussi bancari/3-D Secure aprono la finestra di conferma dopo
547 // una callback asincrona e Chromium puo' classificarla come popup non
548 // direttamente associato al click. Nel processo SecureBrowser i popup
549 // devono restare consentiti e vengono comunque contenuti nel CEF Views
550 // gestito sopra.
551 cmd->AppendSwitch("disable-popup-blocking");
552
553 cmd->AppendSwitchWithValue("disable-features", "TranslateUI");
554 cmd->AppendSwitchWithValue("ssl-certificates-file", "/etc/ssl/certs/ca-certificates.crt");
555
556 cmd->AppendSwitchWithValue("dns-over-https-mode", "automatic");
557 cmd->AppendSwitchWithValue(
558 "dns-over-https-servers",
559 "https://cloudflare-dns.com/dns-query,https://dns.google/dns-query"
560 );
561
562 cmd->AppendSwitch("no-proxy-server");
563 cmd->AppendSwitchWithValue("proxy-server", "direct://");
564 cmd->AppendSwitch("proxy-bypass-list=*");
565
566 cmd->AppendSwitch("enable-gpu");
567 cmd->AppendSwitch("disable-gpu-compositing");
568 cmd->AppendSwitch("use-gl=desktop");
569
570 // -----------------------------------------------------------------
571 // Selezione backend Ozone (Wayland o X11).
572 //
573 // L'ordine di priorità è (high → low):
574 // 1) BastionGuard_CEF_BACKEND = wayland|x11 (override interno usato
575 // dal fallback in SecureBrowser::open per ritentare con X11)
576 // 2) OZONE_PLATFORM = wayland|x11 (env standard Chromium)
577 // 3) XDG_SESSION_TYPE = wayland|x11 (logind)
578 // 4) WAYLAND_DISPLAY presente → wayland, altrimenti DISPLAY → x11
579 // Se nulla di tutto questo è presente, default = x11 (più resiliente).
580 // -----------------------------------------------------------------
581 auto eq = [](const char* a, const char* b) -> bool {
582 return a && b && std::strcmp(a, b) == 0;
583 };
584
585 const char* internal_be = std::getenv("BastionGuard_CEF_BACKEND");
586 const char* ozone_be = std::getenv("OZONE_PLATFORM");
587 const char* sess_type = std::getenv("XDG_SESSION_TYPE");
588 const char* wl_disp = std::getenv("WAYLAND_DISPLAY");
589 const char* x_disp = std::getenv("DISPLAY");
590
591 bool want_wayland;
592 const char* picked_by;
593
594 if (eq(internal_be, "wayland")) { want_wayland = true; picked_by = "BastionGuard_CEF_BACKEND"; }
595 else if (eq(internal_be, "x11")) { want_wayland = false; picked_by = "BastionGuard_CEF_BACKEND"; }
596 else if (eq(ozone_be, "wayland")) { want_wayland = true; picked_by = "OZONE_PLATFORM"; }
597 else if (eq(ozone_be, "x11")) { want_wayland = false; picked_by = "OZONE_PLATFORM"; }
598 else if (eq(sess_type, "wayland")) { want_wayland = true; picked_by = "XDG_SESSION_TYPE"; }
599 else if (eq(sess_type, "x11")) { want_wayland = false; picked_by = "XDG_SESSION_TYPE"; }
600 else if (wl_disp && *wl_disp) { want_wayland = true; picked_by = "WAYLAND_DISPLAY"; }
601 else if (x_disp && *x_disp) { want_wayland = false; picked_by = "DISPLAY"; }
602 else { want_wayland = false; picked_by = "default(x11)"; }
603
604 std::cerr << "[SecureBrowser] Ozone backend: "
605 << (want_wayland ? "wayland" : "x11")
606 << " (via " << picked_by << ")\n";
607
608 cmd->AppendSwitchWithValue(
609 "enable-features",
610 "UseOzonePlatform,VaapiVideoDecoder,UseSkiaRenderer,DnsOverHttps"
611 );
612
613 if (want_wayland) {
614 cmd->AppendSwitchWithValue("ozone-platform", "wayland");
615 cmd->AppendSwitch("enable-webrtc-pipewire-capturer");
616 } else {
617 cmd->AppendSwitchWithValue("ozone-platform", "x11");
618 // Su X11 puro evita warning di Chromium su Wayland mancante
619 cmd->AppendSwitchWithValue("ozone-platform-hint", "x11");
620 }
621
622 cmd->AppendSwitch("no-default-browser-check");
623 cmd->AppendSwitch("no-first-run");
624 cmd->AppendSwitch("disable-crash-reporter");
625 cmd->AppendSwitch("disable-background-networking");
626 cmd->AppendSwitch("disable-breakpad");
627 }

Member Data Documentation

◆ holding_

bool ClamApp::holding_ = false
private

Definition at line 408 of file main.cpp.

Referenced by launch_main_window().

◆ start_minimized_

bool ClamApp::start_minimized_
private

Definition at line 407 of file main.cpp.

Referenced by ClamApp(), launch_main_window(), and on_activate().

◆ tray_

std::unique_ptr<TrayIcon> ClamApp::tray_
private

Definition at line 406 of file main.cpp.

Referenced by launch_main_window().

◆ win_

MainWindow* ClamApp::win_ = nullptr
private

Definition at line 405 of file main.cpp.

Referenced by launch_main_window(), and on_activate().


The documentation for this class was generated from the following files: