Skip to content

Commit 1785130

Browse files
committed
Remove all data
1 parent ba8635f commit 1785130

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

src/components/GeneralSettings.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ import {
124124
import { ranges, ThisWeekRange } from '../utils/date';
125125
import { useImportToCsv } from '../compositions/toCsv';
126126
import { FileType, useFile } from '../compositions/loadFile';
127+
import { removeAllData } from '../compositions/remove-all-data';
127128
128129
const { t } = useI18n();
129130
@@ -195,7 +196,8 @@ async function removeAll() {
195196
needToConfirmDeleteAllData.value = true;
196197
}
197198
198-
function removeAllConfirm() {
199+
async function removeAllConfirm() {
200+
await removeAllData();
199201
needToConfirmDeleteAllData.value = false;
200202
}
201203
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Browser from 'webextension-polyfill';
2+
import { injecStorage } from '../storage/inject-storage';
3+
import { Messages } from '../utils/messages';
4+
5+
export async function removeAllData() {
6+
const storage = injecStorage();
7+
await storage.saveIntervalList([]);
8+
9+
Browser.runtime.sendMessage(Messages.ClearAllData);
10+
}

src/repository/tabs-repository-interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Tab } from '../entity/tab';
22

33
export interface ITabsRepository {
44
getTabs(): Tab[];
5+
removeAllTabs(): void;
56
getTodayTabs(): Tab[];
67
getTab(domain: string): Tab | undefined;
78
addTab(domain: string, favicon: string | undefined): Promise<Tab | undefined>;

src/repository/tabs-repository.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export class TabsRepository implements ITabsRepository {
2020
return this.tabs;
2121
}
2222

23+
removeAllTabs(): void {
24+
this.tabs = [];
25+
}
26+
2327
getTodayTabs(): Tab[] {
2428
return this.tabs.filter(x => x.days.find(s => s.date === todayLocalDate()));
2529
}

src/tracker.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { convertSummaryTimeToBadgeString } from './utils/converter';
1616
import { Settings } from './compositions/settings';
1717
import { isNeedToShowNotification } from './compositions/notification-list';
1818
import { NotificationType, showNotification } from './compositions/show-notification';
19+
import { Messages } from './utils/messages';
1920

2021
const activeTabInstance = ActiveTab.getInstance();
2122

@@ -160,3 +161,12 @@ async function saveTabs() {
160161
const tabs = repo.getTabs();
161162
await storage.saveTabs(tabs);
162163
}
164+
165+
Browser.runtime.onMessage.addListener(async message => {
166+
if (message == Messages.ClearAllData) {
167+
const storage = injecStorage();
168+
const repo = await injectTabsRepositorySingleton();
169+
repo.removeAllTabs();
170+
await storage.saveTabs([]);
171+
}
172+
});

src/utils/messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export enum Messages {
22
RescheduleJobs = 'reschedule-jobs',
3+
ClearAllData = 'clear-data',
34
}

0 commit comments

Comments
 (0)