Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/electionguard_gui/components/guardian_home_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ def get_key_ceremonies(self) -> dict[str, Any]:
return eel_success(js_key_ceremonies)

def watch_db_collections(self) -> None:
self._log.debug("Watching database")
db = self._db_service.get_db()
self._db_watcher_service.watch_database(db, None, notify_ui_db_changed)
self._log.debug("exited watching database")
try:
self._log.debug("Watching database")
db = self._db_service.get_db()
self._db_watcher_service.watch_database(db, None, notify_ui_db_changed)
self._log.debug("exited watching database")
except KeyboardInterrupt:
Comment thread
SteveMaier-IRT marked this conversation as resolved.
self._log.debug("Keyboard interrupt, exiting watch database")
self._db_watcher_service.stop_watching()
except Exception as e: # pylint: disable=broad-except
self.handle_error(e)
self._db_watcher_service.stop_watching()
# no need to raise exception or return anything, we're in fire-and-forget mode here

def stop_watching_db_collections(self) -> None:
self._log.debug("Stopping watch database")
Expand Down
24 changes: 16 additions & 8 deletions src/electionguard_gui/components/key_ceremony_details_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,22 @@ def expose(self) -> None:
eel.expose(self.stop_watching_key_ceremony)

def watch_key_ceremony(self, key_ceremony_id: str) -> None:
db = self._db_service.get_db()
# retrieve and send the key ceremony to the client
self.on_key_ceremony_changed("key_ceremonies", key_ceremony_id)
self._log.debug(f"watching key ceremony '{key_ceremony_id}'")
# start watching for key ceremony changes from guardians
self._db_watcher_service.watch_database(
db, key_ceremony_id, self.on_key_ceremony_changed
)
try:
db = self._db_service.get_db()
# retrieve and send the key ceremony to the client
self.on_key_ceremony_changed("key_ceremonies", key_ceremony_id)
self._log.debug(f"watching key ceremony '{key_ceremony_id}'")
# start watching for key ceremony changes from guardians
self._db_watcher_service.watch_database(
db, key_ceremony_id, self.on_key_ceremony_changed
)
except KeyboardInterrupt:
self._log.debug("Keyboard interrupt, exiting watch database")
self._db_watcher_service.stop_watching()
except Exception as e: # pylint: disable=broad-except
self.handle_error(e)
self._db_watcher_service.stop_watching()
# we're in a fire-and-forget scenario, so no need to raise an exception or return anything

def stop_watching_key_ceremony(self) -> None:
self._db_watcher_service.stop_watching()
Expand Down
15 changes: 14 additions & 1 deletion src/electionguard_gui/main_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,21 @@ def start(self) -> None:
port = self.config_service.get_port()
host = self.config_service.get_host()
self.log_service.debug(f"Starting eel port={port} mode={mode} host={host}")
eel.start("index.html", size=(1024, 768), port=port, mode=mode, host=host)
eel.start(
"index.html",
size=(1024, 768),
port=port,
mode=mode,
host=host,
close_callback=self.on_close,
Comment thread
SteveMaier-IRT marked this conversation as resolved.
)
self.log_service.info("Exiting main app normally")
except Exception as e:
self.log_service.error("error in main app start", e)
traceback.print_exc()
raise e

def on_close(self, _page: str, _open_sockets: list) -> None:
self.log_service.info(
"To close the egui app ensure the browser tab is closed and hit Ctrl+C"
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import KeyCeremonyList from "../shared/key-ceremony-list-component.js";
import DecryptionList from "./decryption-list-component.js";
import Spinner from "../shared/spinner-component.js";

const sleepResumeInterval = 2000;

export default {
components: {
KeyCeremonyList,
Expand All @@ -13,9 +15,21 @@ export default {
loading: true,
decryptions: [],
keyCeremonies: [],
lastAwakeTime: new Date().getTime(),
};
},
methods: {
refresh: async function () {
this.loading = true;
try {
this.decryptions = [];
this.keyCeremonies = [];
await this.refreshDecryptions();
await this.refreshKeyCeremonies();
} finally {
this.loading = false;
}
},
keyCeremoniesChanged: async function () {
await this.refreshKeyCeremonies();
},
Expand All @@ -38,8 +52,17 @@ export default {
console.error(result.error);
}
},
sleepResumeChecker: function () {
var currentTime = new Date().getTime();
if (currentTime > this.lastAwakeTime + sleepResumeInterval * 2) {
console.log("system appears to have returned from sleep, refreshing");
document.location.reload(true);
}
this.lastAwakeTime = currentTime;
},
},
async mounted() {
setInterval(this.sleepResumeChecker, sleepResumeInterval);
eel.expose(this.keyCeremoniesChanged, "key_ceremonies_changed");
eel.expose(this.decryptionsChanged, "decryptions_changed");
console.log("begin watching for key ceremonies");
Expand All @@ -51,10 +74,18 @@ export default {
unmounted() {
console.log("stop watching key ceremonies");
eel.stop_watching_db_collections();
clearInterval(this.sleepResumeChecker);
},
template: /*html*/ `
<div class="container">
<h1>Guardian Home</h1>
<div class="row">
<div class="col-11">
<h1>Guardian Home</h1>
</div>
<div class="col-1 text-end">
<button class="btn btn-lg btn-light" @click="refresh"><i class="bi-arrow-clockwise"></i></button>
</div>
</div>
<spinner :visible="loading"></spinner>
<div v-if="!loading" class="row">
<div class="col-12 col-lg-6">
Expand Down