Skip to content

Commit

Permalink
Made tab reload optional - sometimes we have our own code to reinject…
Browse files Browse the repository at this point in the history
… content script necessities, or we don't have content script, and sometimes we don't want the page to refresh
  • Loading branch information
mikob committed Apr 29, 2020
1 parent 0c18322 commit 3d98f1a
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions hot-reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ const timestampForFilesInDirectory = dir =>
filesInDirectory (dir).then (files =>
files.map (f => f.name + f.lastModifiedDate).join ())

const reload = () => {
const reload = (reloadTab) => {

chrome.tabs.query ({ active: true, currentWindow: true }, tabs => { // NB: see https://github.com/xpl/crx-hotreload/issues/5
if (reloadTab) {
chrome.tabs.query ({ active: true, currentWindow: true }, tabs => { // NB: see https://github.com/xpl/crx-hotreload/issues/5

if (tabs[0]) { chrome.tabs.reload (tabs[0].id) }
if (tabs[0]) { chrome.tabs.reload (tabs[0].id) }

chrome.runtime.reload ()
})
} else {
chrome.runtime.reload ()
})
}
}

const watchChanges = (dir, lastTimestamp) => {
const watchChanges = (dir, reloadTab, lastTimestamp) => {

timestampForFilesInDirectory (dir).then (timestamp => {

Expand All @@ -37,16 +41,19 @@ const watchChanges = (dir, lastTimestamp) => {

} else {

reload ()
reload (reloadTab)
}
})

}

chrome.management.getSelf (self => {

if (self.installType === 'development') {

chrome.runtime.getPackageDirectoryEntry (dir => watchChanges (dir))
if (typeof module === 'object') {
exports.default = (opts) => {
chrome.management.getSelf (self => {
if (self.installType === 'development') {
chrome.runtime.getPackageDirectoryEntry (dir => watchChanges (dir, opts.reloadTab))
}
})
}
})
}

0 comments on commit 3d98f1a

Please sign in to comment.