Skip to content

Commit f4494ec

Browse files
authored
#768 - System now successfully resumes from sleep on guardian page (#771)
* System now resumes from sleep on guardian page * fix linting * Refresh button * minor fixups per PR * Better description
1 parent c141603 commit f4494ec

4 files changed

Lines changed: 74 additions & 14 deletions

File tree

src/electionguard_gui/components/guardian_home_component.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,18 @@ def get_key_ceremonies(self) -> dict[str, Any]:
4949
return eel_success(js_key_ceremonies)
5050

5151
def watch_db_collections(self) -> None:
52-
self._log.debug("Watching database")
53-
db = self._db_service.get_db()
54-
self._db_watcher_service.watch_database(db, None, notify_ui_db_changed)
55-
self._log.debug("exited watching database")
52+
try:
53+
self._log.debug("Watching database")
54+
db = self._db_service.get_db()
55+
self._db_watcher_service.watch_database(db, None, notify_ui_db_changed)
56+
self._log.debug("exited watching database")
57+
except KeyboardInterrupt:
58+
self._log.debug("Keyboard interrupt, exiting watch database")
59+
self._db_watcher_service.stop_watching()
60+
except Exception as e: # pylint: disable=broad-except
61+
self.handle_error(e)
62+
self._db_watcher_service.stop_watching()
63+
# no need to raise exception or return anything, we're in fire-and-forget mode here
5664

5765
def stop_watching_db_collections(self) -> None:
5866
self._log.debug("Stopping watch database")

src/electionguard_gui/components/key_ceremony_details_component.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,22 @@ def expose(self) -> None:
7070
eel.expose(self.stop_watching_key_ceremony)
7171

7272
def watch_key_ceremony(self, key_ceremony_id: str) -> None:
73-
db = self._db_service.get_db()
74-
# retrieve and send the key ceremony to the client
75-
self.on_key_ceremony_changed("key_ceremonies", key_ceremony_id)
76-
self._log.debug(f"watching key ceremony '{key_ceremony_id}'")
77-
# start watching for key ceremony changes from guardians
78-
self._db_watcher_service.watch_database(
79-
db, key_ceremony_id, self.on_key_ceremony_changed
80-
)
73+
try:
74+
db = self._db_service.get_db()
75+
# retrieve and send the key ceremony to the client
76+
self.on_key_ceremony_changed("key_ceremonies", key_ceremony_id)
77+
self._log.debug(f"watching key ceremony '{key_ceremony_id}'")
78+
# start watching for key ceremony changes from guardians
79+
self._db_watcher_service.watch_database(
80+
db, key_ceremony_id, self.on_key_ceremony_changed
81+
)
82+
except KeyboardInterrupt:
83+
self._log.debug("Keyboard interrupt, exiting watch database")
84+
self._db_watcher_service.stop_watching()
85+
except Exception as e: # pylint: disable=broad-except
86+
self.handle_error(e)
87+
self._db_watcher_service.stop_watching()
88+
# we're in a fire-and-forget scenario, so no need to raise an exception or return anything
8189

8290
def stop_watching_key_ceremony(self) -> None:
8391
self._db_watcher_service.stop_watching()

src/electionguard_gui/main_app.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,21 @@ def start(self) -> None:
101101
port = self.config_service.get_port()
102102
host = self.config_service.get_host()
103103
self.log_service.debug(f"Starting eel port={port} mode={mode} host={host}")
104-
eel.start("index.html", size=(1024, 768), port=port, mode=mode, host=host)
104+
eel.start(
105+
"index.html",
106+
size=(1024, 768),
107+
port=port,
108+
mode=mode,
109+
host=host,
110+
close_callback=self.on_close,
111+
)
112+
self.log_service.info("Exiting main app normally")
105113
except Exception as e:
106114
self.log_service.error("error in main app start", e)
107115
traceback.print_exc()
108116
raise e
117+
118+
def on_close(self, _page: str, _open_sockets: list) -> None:
119+
self.log_service.info(
120+
"To close the egui app ensure the browser tab is closed and hit Ctrl+C"
121+
)

src/electionguard_gui/web/components/guardian/guardian-home-component.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import KeyCeremonyList from "../shared/key-ceremony-list-component.js";
22
import DecryptionList from "./decryption-list-component.js";
33
import Spinner from "../shared/spinner-component.js";
44

5+
const sleepResumeInterval = 2000;
6+
57
export default {
68
components: {
79
KeyCeremonyList,
@@ -13,9 +15,21 @@ export default {
1315
loading: true,
1416
decryptions: [],
1517
keyCeremonies: [],
18+
lastAwakeTime: new Date().getTime(),
1619
};
1720
},
1821
methods: {
22+
refresh: async function () {
23+
this.loading = true;
24+
try {
25+
this.decryptions = [];
26+
this.keyCeremonies = [];
27+
await this.refreshDecryptions();
28+
await this.refreshKeyCeremonies();
29+
} finally {
30+
this.loading = false;
31+
}
32+
},
1933
keyCeremoniesChanged: async function () {
2034
await this.refreshKeyCeremonies();
2135
},
@@ -38,8 +52,17 @@ export default {
3852
console.error(result.error);
3953
}
4054
},
55+
sleepResumeChecker: function () {
56+
var currentTime = new Date().getTime();
57+
if (currentTime > this.lastAwakeTime + sleepResumeInterval * 2) {
58+
console.log("system appears to have returned from sleep, refreshing");
59+
document.location.reload(true);
60+
}
61+
this.lastAwakeTime = currentTime;
62+
},
4163
},
4264
async mounted() {
65+
setInterval(this.sleepResumeChecker, sleepResumeInterval);
4366
eel.expose(this.keyCeremoniesChanged, "key_ceremonies_changed");
4467
eel.expose(this.decryptionsChanged, "decryptions_changed");
4568
console.log("begin watching for key ceremonies");
@@ -51,10 +74,18 @@ export default {
5174
unmounted() {
5275
console.log("stop watching key ceremonies");
5376
eel.stop_watching_db_collections();
77+
clearInterval(this.sleepResumeChecker);
5478
},
5579
template: /*html*/ `
5680
<div class="container">
57-
<h1>Guardian Home</h1>
81+
<div class="row">
82+
<div class="col-11">
83+
<h1>Guardian Home</h1>
84+
</div>
85+
<div class="col-1 text-end">
86+
<button class="btn btn-lg btn-light" @click="refresh"><i class="bi-arrow-clockwise"></i></button>
87+
</div>
88+
</div>
5889
<spinner :visible="loading"></spinner>
5990
<div v-if="!loading" class="row">
6091
<div class="col-12 col-lg-6">

0 commit comments

Comments
 (0)