Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Commit bffca7b

Browse files
committed
reorg in to folders
1 parent c39111c commit bffca7b

File tree

16 files changed

+148
-93
lines changed

16 files changed

+148
-93
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"dependencies": {
5757
"google-fonts-plugin": "^5.0.2",
5858
"object-sizeof": "^1.6.0",
59-
"purecss": "^2.0.3"
59+
"purecss": "^2.0.3",
60+
"vlq": "^1.0.1"
6061
}
6162
}

src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// Webpack uses MiniCssExtractPlugin when it sees this.
77
import './scss/app.scss';
88

9-
import { grayTabby } from './ui';
10-
import { PAGE_LOAD } from './globals';
9+
import { grayTabby } from './app/ui';
10+
import { PAGE_LOAD } from './lib/globals';
1111

1212
grayTabby().then(
1313
() => {

src/tabs.ts renamed to src/app/tabs.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
* Tab types and logic.
33
*/
44

5-
import { Tabs as WebextTabs } from 'webextension-polyfill-ts/dist/generated/tabs';
6-
import { erase, load, save, fieldKeeper, loadBatch } from './utils';
5+
import { erase, load, save, fieldKeeper, loadBatch } from '../lib/utils';
6+
import { BrowserTab } from '../lib/types';
77

8-
export type BrowserTab = WebextTabs.Tab;
98
export type GrayTab = Pick<BrowserTab, 'url' | 'title'> & { key: number };
109

1110
export type GrayTabGroup = {

src/ui.ts renamed to src/app/ui.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*/
66

77
import * as sizeof from 'object-sizeof';
8-
import { ARCHIVAL, BROWSER, DOCUMENT } from './globals';
9-
import { getOptions, setOptions } from './options';
8+
import * as vlq from 'vlq';
9+
import { ARCHIVAL, BROWSER, DOCUMENT } from '../lib/globals';
10+
import { getOptions, setOptions } from '../lib/options';
1011
import {
1112
dateFromKey,
1213
eraseTabGroup,
@@ -16,8 +17,8 @@ import {
1617
saveTabGroup,
1718
GrayTabGroup,
1819
GrayTab,
19-
BrowserTab,
2020
} from './tabs';
21+
import { BrowserTab } from '../lib/types';
2122

2223
function getDomain(url: string): string {
2324
return new URL(url).hostname;
@@ -250,6 +251,23 @@ class Debugger {
250251
await Promise.all(promises);
251252
console.log(sizeof.default(await loadAllTabGroups()));
252253
}
254+
255+
async groupMeta(): Promise<void> {
256+
const retval: number[] = [];
257+
let groups = await loadAllTabGroups();
258+
const first = groups[0];
259+
retval.push(first.date);
260+
retval.push(first.tabs.length);
261+
groups = groups.slice(1);
262+
for (const group of groups) {
263+
retval.push(group.date - first.date);
264+
retval.push(group.tabs.length);
265+
}
266+
const encoding = vlq.encode(retval);
267+
console.log(encoding);
268+
console.log(sizeof.default(encoding));
269+
console.log(JSON.stringify(retval));
270+
}
253271
}
254272

255273
declare global {

src/background.ts

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,13 @@
77
* Not included in coverage reports, so don't put non-trivial logic here.
88
*/
99

10-
import { Menus } from 'webextension-polyfill-ts';
11-
import {
12-
archiveHandler,
13-
archiveLeftHandler,
14-
archiveOnlyHandler,
15-
archiveOthersHandler,
16-
archiveRightHandler,
17-
} from './archive';
18-
import { saveAsFavorites, restoreFavorites } from './options';
19-
import { BROWSER } from './globals';
10+
import { bindArchivalHandlers } from './bg/archive';
2011

21-
async function init(): Promise<void> {
22-
BROWSER.get().browserAction.onClicked.addListener(archiveHandler);
23-
let isFirefox = false;
24-
try {
25-
const info = await BROWSER.get().runtime.getBrowserInfo();
26-
if (info.name.toLowerCase() === 'firefox') {
27-
isFirefox = true;
28-
}
29-
} catch {
30-
// let isFirefox stay false
31-
}
32-
33-
const contexts: Menus.ContextType[] = isFirefox ? ['tab', 'browser_action'] : ['browser_action'];
34-
35-
BROWSER.get().contextMenus.create({
36-
contexts: contexts,
37-
title: 'Save current tabs as favorites',
38-
onclick: saveAsFavorites,
39-
});
40-
41-
BROWSER.get().contextMenus.create({
42-
contexts: contexts,
43-
title: 'Restore favorite tabs',
44-
onclick: restoreFavorites,
45-
});
46-
47-
BROWSER.get().contextMenus.create({
48-
contexts: contexts,
49-
title: 'Archive...',
50-
onclick: archiveOnlyHandler,
51-
});
52-
53-
BROWSER.get().contextMenus.create({
54-
contexts: contexts,
55-
title: ' Left',
56-
onclick: archiveLeftHandler,
57-
});
58-
59-
BROWSER.get().contextMenus.create({
60-
contexts: contexts,
61-
title: ' Right',
62-
onclick: archiveRightHandler,
63-
});
64-
65-
BROWSER.get().contextMenus.create({
66-
contexts: contexts,
67-
title: ' Others',
68-
onclick: archiveOthersHandler,
69-
});
70-
}
71-
72-
init().then(
12+
bindArchivalHandlers().then(
7313
() => {
7414
console.log('loaded graytabby backend');
7515
},
7616
err => {
77-
console.error(err);
17+
console.error('could not load graytabby backend', err);
7818
},
7919
);

src/archive.ts renamed to src/bg/archive.ts

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
*/
44

55
import { Menus } from 'webextension-polyfill-ts/dist/generated/menus';
6-
import { ARCHIVAL, BROWSER, PAGE_LOAD } from './globals';
7-
import { getOptions } from './options';
8-
import { BrowserTab } from './tabs';
6+
import { ARCHIVAL, BROWSER, PAGE_LOAD } from '../lib/globals';
7+
import { getOptions, restoreFavorites, saveAsFavorites } from '../lib/options';
8+
import { BrowserTab } from '../lib/types';
99

1010
export type OnClickData = Menus.OnClickData;
1111

@@ -49,7 +49,6 @@ export function archivePlan(
4949
const seen: Set<string> = new Set();
5050

5151
for (const tab of browserTabs) {
52-
console.log('aaa', tab.url, tab.pinned);
5352
if (tab.url === homeURL || tab.pinned) continue;
5453
else if (seen.has(tab.url) && !archiveDupes) tabsToClose.push(tab);
5554
else if (shouldJustClose(tab.url)) tabsToClose.push(tab);
@@ -58,7 +57,6 @@ export function archivePlan(
5857
seen.add(tab.url);
5958
}
6059
}
61-
console.log(tabsToArchive, tabsToClose);
6260
return [tabsToArchive, tabsToClose];
6361
}
6462

@@ -139,3 +137,54 @@ export async function archiveRightHandler(_data: OnClickData, tab: BrowserTab):
139137
export async function archiveOnlyHandler(_data: OnClickData, tab: BrowserTab): Promise<void> {
140138
return doArchive(t => t.id == tab.id);
141139
}
140+
141+
export async function bindArchivalHandlers(): Promise<void> {
142+
BROWSER.get().browserAction.onClicked.addListener(archiveHandler);
143+
let isFirefox = false;
144+
try {
145+
const info = await BROWSER.get().runtime.getBrowserInfo();
146+
if (info.name.toLowerCase() === 'firefox') {
147+
isFirefox = true;
148+
}
149+
} catch {
150+
// let isFirefox stay false
151+
}
152+
153+
const contexts: Menus.ContextType[] = isFirefox ? ['tab', 'browser_action'] : ['browser_action'];
154+
155+
BROWSER.get().contextMenus.create({
156+
contexts: contexts,
157+
title: 'Save current tabs as favorites',
158+
onclick: saveAsFavorites,
159+
});
160+
161+
BROWSER.get().contextMenus.create({
162+
contexts: contexts,
163+
title: 'Restore favorite tabs',
164+
onclick: restoreFavorites,
165+
});
166+
167+
BROWSER.get().contextMenus.create({
168+
contexts: contexts,
169+
title: 'Archive...',
170+
onclick: archiveOnlyHandler,
171+
});
172+
173+
BROWSER.get().contextMenus.create({
174+
contexts: contexts,
175+
title: ' Left',
176+
onclick: archiveLeftHandler,
177+
});
178+
179+
BROWSER.get().contextMenus.create({
180+
contexts: contexts,
181+
title: ' Right',
182+
onclick: archiveRightHandler,
183+
});
184+
185+
BROWSER.get().contextMenus.create({
186+
contexts: contexts,
187+
title: ' Others',
188+
onclick: archiveOthersHandler,
189+
});
190+
}
File renamed without changes.

src/globals.ts renamed to src/lib/globals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { browser } from 'webextension-polyfill-ts';
22
import { Broker } from './brokers';
3-
import { BrowserTab } from './tabs';
3+
import { BrowserTab } from './types';
44

55
class Wrapper<T> {
66
wrapped: T;
File renamed without changes.

0 commit comments

Comments
 (0)