Skip to content

Commit

Permalink
fixes for safari
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanb10 committed Jun 13, 2021
1 parent d937604 commit 4243898
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 20 deletions.
30 changes: 27 additions & 3 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,37 @@
import json
import shutil
import re
import os
from sys import argv

FOLDER = 'build_temp'
with open('manifest.json') as m:
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
Expand All @@ -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))

Expand Down Expand Up @@ -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']]
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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});
Expand Down
4 changes: 2 additions & 2 deletions scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions scripts/nap_room.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 8 additions & 6 deletions scripts/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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() }));
Expand Down Expand Up @@ -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)}`;
Expand Down
4 changes: 2 additions & 2 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4243898

Please sign in to comment.