diff --git a/build.py b/build.py index 67e1679..abf6b0c 100644 --- a/build.py +++ b/build.py @@ -4,6 +4,7 @@ import json import shutil import re +import os from sys import argv FOLDER = 'build_temp' @@ -11,8 +12,29 @@ data = json.load(m) VERSION = data['version'] -print('\n\x1b[1;31;40m' + 'Building Snoozz v' + VERSION + '\x1b[0m\n') +print('\n\x1b[1;31;40m' + 'Building Snoozz v' + VERSION + '\x1b[0m\n'); +# +# delete old files if they exist +# +if os.path.exists(FOLDER): + shutil.rmtree(FOLDER) +if os.path.exists('snoozz-chrome-' + VERSION + '.zip'): + os.remove('snoozz-chrome-' + VERSION + '.zip') +if os.path.exists('snoozz-chrome-' + VERSION): + shutil.rmtree('snoozz-chrome-' + VERSION) +if os.path.exists('snoozz-ff-' + VERSION + '.zip'): + os.remove('snoozz-ff-' + VERSION + '.zip') +if os.path.exists('snoozz-ff-' + VERSION): + shutil.rmtree('snoozz-ff-' + VERSION) +if os.path.exists('snoozz-' + VERSION + '.zip'): + os.remove('snoozz-' + VERSION + '.zip') +if os.path.exists('snoozz-' + VERSION): + shutil.rmtree('snoozz-' + VERSION) +if os.path.exists('snoozz-safari-' + VERSION + '.zip'): + os.remove('snoozz-safari-' + VERSION + '.zip') +if os.path.exists('snoozz-safari-' + VERSION): + shutil.rmtree('snoozz-safari-' + VERSION) # # Copy essential files only @@ -22,7 +44,7 @@ shutil.copytree('html', FOLDER + '/html', ignore = shitfiles) shutil.copytree('scripts', FOLDER + '/scripts', ignore = shitfiles) shutil.copytree('styles', FOLDER + '/styles', ignore = shitfiles) -shutil.copytree('icons', FOLDER + '/icons', ignore = shitfiles) +shutil.copytree('icons', FOLDER + '/icons', dirs_exist_ok=True, ignore = shitfiles) with open(FOLDER + '/manifest.json', 'w+') as m: m.write(json.dumps(data, indent=4)) @@ -64,6 +86,8 @@ # Modify manifest file for safari and build # shutil.copy('docs/safari.md', FOLDER) +shutil.copy('_instructions_safari.txt', FOLDER) +shutil.copy('safari.sh', FOLDER) if 'idle' in data['permissions']: data['permissions'].remove('idle') if 'notifications' in data['permissions']: data['permissions'].remove('notifications') data['permissions'] = [p.replace('tabs','activeTab') for p in data['permissions']] @@ -85,7 +109,7 @@ # print('\nChanges in v' + VERSION) with open('docs/changelog.md', 'r') as c: - latest = re.search('#### ' + VERSION + '(.+?)####', c.read().replace('\n', '¿')) + latest = re.search('#### ' + VERSION + '(.+?)(####|\*\*)', c.read().replace('\n', '¿')) if latest: print(latest.group(1).replace('¿', '\n')) # # Cleanup diff --git a/scripts/background.js b/scripts/background.js index fa602d8..8027275 100644 --- a/scripts/background.js +++ b/scripts/background.js @@ -5,6 +5,7 @@ chrome.runtime.onMessage.addListener(async msg => { var p = SAVED_OPTIONS && SAVED_OPTIONS.polling ? SAVED_OPTIONS.polling : await getOptions('polling'); if (p !== 'off') poll(msg.poll); } + if (msg.wakeUp) await wakeUpTask(); if (msg.close) setTimeout(_ => { if (msg.tabId) chrome.tabs.remove(msg.tabId); if (msg.windowId) chrome.windows.remove(msg.windowId); @@ -24,7 +25,7 @@ chrome.storage.onChanged.addListener(async changes => { } }); -chrome.notifications.onClicked.addListener(async id => { +if (chrome.notifications) chrome.notifications.onClicked.addListener(async id => { await chrome.notifications.clear(id) var t = await getSnoozedTabs(id); if (t && t.id && id && id.length) { @@ -119,11 +120,11 @@ async function snoozeInBackground(item, tab) { var isHref = item.linkUrl && item.linkUrl.length; var url = isHref ? item.linkUrl : item.pageUrl; - if(!isValid({url})) return createNotification(null, `Can't snoozz that :(`, 'icons/main-icon.png', 'The link you are trying to snooze is invalid.', true); + if(!isValid({url})) return createNotification(null, `Can't snoozz that :(`, 'icons/logo.svg', 'The link you are trying to snooze is invalid.', true); var snoozeTime = c && c.time; if (!snoozeTime || c.disabled || dayjs().isAfter(dayjs(snoozeTime))) { - return createNotification(null, `Can't snoozz that :(`, 'icons/main-icon.png', 'The time you have selected is invalid.', true); + return createNotification(null, `Can't snoozz that :(`, 'icons/logo.svg', 'The time you have selected is invalid.', true); } // add attributes var startUp = item.menuItemId == 'startup' ? true : undefined; @@ -135,7 +136,7 @@ async function snoozeInBackground(item, tab) { var snoozed = await snoozeTab(item.menuItemId == 'startup' ? 'startup' : snoozeTime.valueOf(), assembledTab); var msg = `${!isHref ? tab.title : getHostname(url)} will wake up ${formatSnoozedUntil(assembledTab)}.` - createNotification(snoozed.tabDBId, 'A new tab is now napping :)', 'icons/main-icon.png', msg, true); + createNotification(snoozed.tabDBId, 'A new tab is now napping :)', 'icons/logo.svg', msg, true); if (!isHref) await chrome.tabs.remove(tab.id); await chrome.runtime.sendMessage({updateDash: true}); diff --git a/scripts/common.js b/scripts/common.js index a494320..168ca98 100644 --- a/scripts/common.js +++ b/scripts/common.js @@ -144,7 +144,7 @@ async function openTab(tab, windowId, automatic = false) { } if (!automatic) return; var msg = `${tab.title} -- snoozed ${dayjs(tab.timeCreated).fromNow()}`; - createNotification(tab.id, 'A tab woke up!', 'icons/main-icon.png', msg); + createNotification(tab.id, 'A tab woke up!', 'icons/logo.svg', msg); } async function openWindow(t, automatic = false) { @@ -172,7 +172,7 @@ async function openWindow(t, automatic = false) { if (!automatic) return; var msg = `This window was put to sleep ${dayjs(t.timeCreated).fromNow()}`; - createNotification(t.id, 'A window woke up!', 'icons/main-icon.png', msg); + createNotification(t.id, 'A window woke up!', 'icons/logo.svg', msg); return; } diff --git a/scripts/nap_room.js b/scripts/nap_room.js index 1e5f63d..f62f9d2 100644 --- a/scripts/nap_room.js +++ b/scripts/nap_room.js @@ -42,7 +42,7 @@ async function init() { buildTimeGroups(); observer.observe(); - if (getBrowser() === 'safari') await chrome.runtime.getBackgroundPage(async bg => {await bg.wakeUpTask()}); + if (getBrowser() === 'safari') chrome.runtime.sendMessage({wakeUp: true}); } function setupClock() { @@ -97,7 +97,7 @@ function insertIntoCorrectPosition(t, alreadyExists = false) { }); group.insertBefore(tab, Array.from(allTabs)[index]); } else { - group.append(tab); + try {group.append(tab)}catch(e){} } buildTabActions(t, tab) } @@ -329,7 +329,7 @@ function openEditModal(tabId) { iframe.setAttribute('scrolling', 'no'); overlay.append(iframe); overlay.classList.add('open'); - setTimeout(_ => iframe.contentWindow.focus(), 100); + setTimeout(_ => {try {iframe.contentWindow.focus()} catch(e){}}, 200); bodyScrollFreezer.freeze(); overlay.addEventListener('click', closeOnOutsideClick, {once: true}); document.addEventListener('keyup', closeOnOutsideClick); diff --git a/scripts/popup.js b/scripts/popup.js index 013b51c..1bf7caa 100644 --- a/scripts/popup.js +++ b/scripts/popup.js @@ -25,7 +25,7 @@ async function init() { chrome.tabs.onActivated.addListener(_ => setTimeout(_ => window.close(), 50)) chrome.runtime.onMessage.addListener(msg => {if (msg.closePopup) window.close()}); } - if (getBrowser() === 'safari') await chrome.runtime.getBackgroundPage(async bg => {await bg.wakeUpTask()}); + if (getBrowser() === 'safari') chrome.runtime.sendMessage({wakeUp: true}); closeDelay = await getOptions('closeDelay'); var tabs = await getSnoozedTabs(); @@ -77,8 +77,8 @@ async function buildTargets() { document.getElementById('window').classList.toggle('disabled', !isWindowValid); var isSelectionValid = getBrowser() !== 'safari' && validTabs.length > 1 && activeTab.highlighted && validTabs.filter(t => t.highlighted).length > 1; document.getElementById('selection').classList.toggle('disabled', !isSelectionValid); - var isGroupValid = false && getBrowser() === 'chrome' && validTabs.length > 1 && activeTab.groupId && activeTab.groupId != -1 && validTabs.filter(vt => vt.groupId && vt.groupId != activeTab.groupId).length > 1 - document.getElementById('group').classList.toggle('disabled', !isGroupValid); + // var isGroupValid = false && getBrowser() === 'chrome' && validTabs.length > 1 && activeTab.groupId && activeTab.groupId != -1 && validTabs.filter(vt => vt.groupId && vt.groupId != activeTab.groupId).length > 1 + // document.getElementById('group').classList.toggle('disabled', !isGroupValid); document.querySelectorAll('.target').forEach(t => t.tabIndex = t.classList.contains('disabled') ? -1 : 0); document.querySelectorAll('.target').forEach(t => t.addEventListener('keyup', e => { if (e.which == 13) t.click() })); @@ -115,11 +115,13 @@ async function generatePreview(type) { if (!iconTheme) iconTheme = 'human'; var allTabs = await getTabsInWindow(); - if (!allTabs || !allTabs.length) return; + if (!allTabs || allTabs.length == 0) return; + if (allTabs.length === undefined) allTabs = [allTabs]; if (type == 'tab') { - previewText.innerText = allTabs.find(at => at.active).title; - previewIcon.src = allTabs.find(at => at.active).favIconUrl ? allTabs.find(at => at.active).favIconUrl : '../icons/unknown.png'; + var a = allTabs.find(at => at.active) + previewText.innerText = a.title; + previewIcon.src = a.favIconUrl ? a.favIconUrl : (getBrowser() === 'safari' ? getFaviconUrl(a.url) : '../icons/unknown.png'); } else if (type == 'window') { var validTabs = allTabs.filter(t => !isDefault(t) && isValid(t)); previewText.innerText = `${getTabCountLabel(validTabs)} from ${getSiteCountLabel(validTabs)}`; diff --git a/scripts/settings.js b/scripts/settings.js index 8fe9755..04b2182 100644 --- a/scripts/settings.js +++ b/scripts/settings.js @@ -43,7 +43,7 @@ async function initialize() { setTimeout(_ => document.querySelector('body > .copied').classList.remove('toast'), 4000) }); - if (getBrowser() === 'safari') await chrome.runtime.getBackgroundPage(async bg => {await bg.wakeUpTask()}); + if (getBrowser() === 'safari') chrome.runtime.sendMessage({wakeUp: true}); } function highlightSetting(name, condition) { var el = document.getElementById(name).closest('.input-container'); @@ -189,7 +189,7 @@ async function resetSettings() { badge: 'today', closeDelay: 1000, polling: 'on', - contextMenu: ['today-evening', 'tom-morning', 'tom-evening', 'weekend', 'monday'] + contextMenu: ['startup', 'in-an-hour', 'today-evening', 'tom-morning', 'weekend'] } await saveOptions(defaultOptions); updateFormValues(defaultOptions);