Skip to content

Commit

Permalink
remove stayalive mv3 workaround, fix session removal
Browse files Browse the repository at this point in the history
  • Loading branch information
june07 committed Apr 22, 2024
1 parent 26574d0 commit 81492b0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nimv3",
"version": "3.6.4",
"version": "3.6.5",
"scripts": {
"dev": "vite --host",
"dev:extension": "npm-run-all --parallel build:dev watch:rollup:deps",
Expand Down
33 changes: 24 additions & 9 deletions src/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async function getInfo(host, port) {
return cache.info[cacheId]
} catch (error) {
if (!error?.message?.match(/Failed to fetch/i)) {
console.error(error)
console.log(error)
}
}
}
Expand Down Expand Up @@ -431,11 +431,11 @@ async function group(tabId) {
state.groups['default'] = await chrome.tabGroups.update(groupId, { color: 'green', title: 'NiM' })
amplitude.getInstance().logEvent('Program Event', { action: 'Tab Group Added', detail: 'default' })
} catch (error) {
console.error(error)
console.log(error)
}
}
} catch (error) {
console.error(error)
console.log(error)
}
}
function updateTabUI(tabId) {
Expand Down Expand Up @@ -521,7 +521,7 @@ function messageHandler(request, sender, reply) {
cache[cacheId] = Date.now()
openTab(host, port, manual)
} catch (error) {
console.error(error)
console.log(error)
} finally {
delete cache[cacheId]
}
Expand Down Expand Up @@ -564,7 +564,11 @@ function messageHandler(request, sender, reply) {
reply
)
}).catch(error => {
console.error(error)
if (/no\s+tab/i.test(error)) {
cache.removed[tabId] = Date.now()
reply()
}
console.log(error)
})
} else {
Promise.all(updates.map(update => {
Expand Down Expand Up @@ -718,12 +722,22 @@ chrome.tabGroups.onRemoved.addListener((tabGroup) => {
})
});

/*
(async function StayAlive() {
const lastCall = Date.now()
let alivePort, lastAge = 0
const loadTime = new Date()
let alivePort, lastAge = 0, lastReloadDay = loadTime.getDate(), lastReloadHour = loadTime.getHours()
setInterval(() => {
let age = (Date.now() - lastCall) / 3600000
let age = (Date.now() - Date.parse(loadTime)) / 360000
const currentHour = new Date().getHours()
const currentDay = new Date().getDate()
// Check if we have passed the reload hour on a new day
if (currentDay !== lastReloadDay && currentHour >= lastReloadHour) {
chrome.runtime.reload()
lastReloadDay = currentDay
lastReloadHour = currentHour
}
// console.log(`(DEBUG StayAlive) ----------------------- time elapsed: ${age} hrs`);
if (Math.trunc(age) !== lastAge) {
Expand Down Expand Up @@ -757,4 +771,5 @@ chrome.tabGroups.onRemoved.addListener((tabGroup) => {
}
}, 25000)
})()
})()
*/

0 comments on commit 81492b0

Please sign in to comment.