Skip to content

Commit

Permalink
Implement restore session
Browse files Browse the repository at this point in the history
Restores last page if user opens
app within 5 minutes of last timeout update.

Next:
- We could add more states to restore

Fixes: #26
  • Loading branch information
nikalc committed May 25, 2021
1 parent 6d3ca18 commit e6e15cf
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 104 deletions.
24 changes: 16 additions & 8 deletions frontendApp/assets/js/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ document.addEventListener("DOMContentLoaded", function() { initializeUser()}, fa

function initializeUser() {
var loggedTime = store.get('loggedTimestamp');
const currentDate = new Date();
const currentTime = currentDate.getTime();
var timeDiff = (currentTime - loggedTime)/60000;
if (timeDiff > 720) {
store.delete('loggedUserid');
store.delete('loggedUsername');
store.delete('loggedName');
store.delete('loggedTimestamp');
if (loggedTime != null) {
console.log("Checking time diff ...")
const currentDate = new Date();
const currentTime = currentDate.getTime();
var timeDiff = (currentTime - loggedTime)/60000;
if (timeDiff > 720) {
store.delete('loggedUserid');
store.delete('loggedUsername');
store.delete('loggedName');
store.delete('loggedTimestamp');
store.delete('currentPage');
}
}

var loggedUser = store.get('loggedName');
Expand All @@ -52,6 +56,9 @@ function initializeUser() {
} else {
console.log(loggedUser)
userMenuContainer.innerHTML = userMenu;
var path = window.location.pathname;
var page = path.split("/").pop();
store.set('currentPage', page);
}
}

Expand Down Expand Up @@ -256,6 +263,7 @@ function logout() {
store.delete('loggedUsername');
store.delete('loggedName');
store.delete('loggedTimestamp');
store.delete('currentPage');

initializeUser();
systemToast('logoutSuccess');
Expand Down
20 changes: 19 additions & 1 deletion frontendApp/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,25 @@ function createWindow () {
})

mainWindow.menuBarVisible = false
mainWindow.loadFile('index.html')

var loggedTime = store.get('loggedTimestamp');
if (loggedTime != null) {
const currentDate = new Date();
const currentTime = currentDate.getTime();
var timeDiff = (currentTime - loggedTime)/60000;
if (timeDiff < 5) {
var page = store.get('currentPage');
mainWindow.loadFile(page);
} else {
mainWindow.loadFile('index.html');
}
} else {
mainWindow.loadFile('index.html');
}

/*
mainWindow.loadFile('index.html')*/

/* Global shortcut for F5 to reload window */
globalShortcut.register('f5', function() {
Expand Down
1 change: 0 additions & 1 deletion frontendApp/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet" />
<!-- MDB -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdb-ui-kit/3.3.0/mdb.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body id="manual-control">
<header id="sticky-header" class="header fixed-top">
Expand Down
1 change: 0 additions & 1 deletion frontendApp/mission.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
crossorigin=""></script>
<script src="https://api.mapbox.com/mapbox.js/plugins/leaflet-fullscreen/v1.0.1/Leaflet.fullscreen.min.js"></script>
<script type="text/javascript" src="./assets/js/leaflet-mission-polyline.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body id="mission-control">
<header id="sticky-header" class="header fixed-top">
Expand Down
Loading

0 comments on commit e6e15cf

Please sign in to comment.