Skip to content

Commit

Permalink
Fix skip break
Browse files Browse the repository at this point in the history
  • Loading branch information
nikelasi committed Jan 15, 2023
1 parent 7aba7f1 commit e2e8672
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
21 changes: 20 additions & 1 deletion src/background/alarms.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ browser.alarms.onAlarm.addListener(async (alarm) => {
}
});

browser.runtime.onMessage.addListener(data => {
browser.runtime.onMessage.addListener(async (data) => {
try {
const { trigger } = JSON.parse(data);

Expand All @@ -32,6 +32,25 @@ browser.runtime.onMessage.addListener(data => {
});
});
}
else if (trigger === "endbreakearly") {
browser.alarms.clear("breakAlarm");
const periodInSecs = (await browser.storage.sync.get("interval")).interval || 60 * 10

browser.alarms.create(
"Breaks",
{
periodInMinutes: periodInSecs / 60
}
)

browser.tabs.query({}, function (tabs) {
tabs.forEach(tab => {
browser.tabs.sendMessage(tab.id, JSON.stringify({
trigger: "closeoverlay",
}));
});
});
}

} catch {

Expand Down
23 changes: 2 additions & 21 deletions src/content/break-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,12 @@ let breakTimeout;

// Break Handling

const sendEndBreak = async () => {
};

const sendSkipBreak = () => {
browser.tabs.query({}, function (tabs) {
for (const tab of tabs) {
const msgPromise = browser.tabs.sendMessage(
tab.id,
JSON.stringify({trigger: "skipbreak"})
)
}
});
};
browser.runtime.sendMessage(JSON.stringify({ trigger: "endbreakearly" }));
}

const skipBreak = async () => {
overlay.remove();
await sendEndBreak();
const breakAlarm = await browser.alarms.get("breakAlarm");
if (breakAlarm) {
browser.alarms.clear("breakAlarm");
}
};

const displayBreakOverlay = async (quote) => {
Expand All @@ -68,7 +53,6 @@ const displayBreakOverlay = async (quote) => {
btn.style.position = "relative";

btn.onclick = (event) => {
skipBreak();
sendSkipBreak();
};
}
Expand Down Expand Up @@ -104,7 +88,6 @@ browser.runtime.onMessage.addListener(async data => {

try {
const jsondata = JSON.parse(data)
console.log(jsondata);
const { trigger } = jsondata;

if (jsondata.trigger === 'breaks') {
Expand All @@ -121,10 +104,8 @@ browser.runtime.onMessage.addListener(async data => {
skipBreak();
}
else if (trigger === "onesecondinterval") {
console.log("1s interval");
const alarm = jsondata.breakAlarm;
if (alarm) {
console.log("hello");
timeLeft = alarm.scheduledTime - Date.now();
}

Expand Down

0 comments on commit e2e8672

Please sign in to comment.