Allows sorting items by last used

This commit is contained in:
Alicia Sykes
2021-09-05 01:00:44 +01:00
parent 955985071f
commit 11f5f8c9df
3 changed files with 20 additions and 1 deletions

View File

@@ -107,7 +107,9 @@ export default {
} else {
this.$emit('itemClicked');
}
// Update the most/ last used ledger, for smart-sorting
this.incrementMostUsedCount(this.id);
this.incrementLastUsedCount(this.id);
},
/* Open custom context menu, and set position */
openContextMenu(e) {
@@ -200,7 +202,7 @@ export default {
default: window.open(url, '_blank');
}
},
/* Used for smart-sort when sorting items by most/ last used */
/* Used for smart-sort when sorting items by most used apps */
incrementMostUsedCount(itemId) {
const mostUsed = JSON.parse(localStorage.getItem(localStorageKeys.MOST_USED) || '{}');
let counter = mostUsed[itemId] || 0;
@@ -208,6 +210,12 @@ export default {
mostUsed[itemId] = counter;
localStorage.setItem(localStorageKeys.MOST_USED, JSON.stringify(mostUsed));
},
/* Used for smart-sort when sorting by last used apps */
incrementLastUsedCount(itemId) {
const lastUsed = JSON.parse(localStorage.getItem(localStorageKeys.LAST_USED) || '{}');
lastUsed[itemId] = new Date().getTime();
localStorage.setItem(localStorageKeys.LAST_USED, JSON.stringify(lastUsed));
},
},
mounted() {
// If ststus checking is enabled, then check service status