aboutsummaryrefslogtreecommitdiff
path: root/src/background/repositories/FindRepository.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/background/repositories/FindRepository.ts')
-rw-r--r--src/background/repositories/FindRepository.ts58
1 files changed, 52 insertions, 6 deletions
diff --git a/src/background/repositories/FindRepository.ts b/src/background/repositories/FindRepository.ts
index 813e065..3492759 100644
--- a/src/background/repositories/FindRepository.ts
+++ b/src/background/repositories/FindRepository.ts
@@ -1,22 +1,68 @@
import { injectable } from "tsyringe";
import MemoryStorage from "../infrastructures/MemoryStorage";
-const FIND_KEYWORD_KEY = "find-keyword";
+const FIND_GLOBAL_KEYWORD_KEY = "find-global-keyword";
+const FIND_LOCAL_KEYWORD_KEY = "find-local-keyword";
+
+export type FindState = {
+ keyword: string;
+ frameId: number;
+};
+
+export default interface FindRepository {
+ getGlobalKeyword(): Promise<string | undefined>;
+
+ setGlobalKeyword(keyword: string): Promise<void>;
+
+ getLocalState(tabId: number): Promise<undefined | FindState>;
+
+ setLocalState(tabId: number, state: FindState): Promise<void>;
+
+ deleteLocalState(tabId: number): Promise<void>;
+}
@injectable()
-export default class FindRepository {
+export class FindRepositoryImpl implements FindRepository {
private cache: MemoryStorage;
constructor() {
this.cache = new MemoryStorage();
}
- getKeyword(): Promise<string> {
- return Promise.resolve(this.cache.get(FIND_KEYWORD_KEY));
+ getGlobalKeyword(): Promise<string | undefined> {
+ return Promise.resolve(this.cache.get(FIND_GLOBAL_KEYWORD_KEY));
+ }
+
+ setGlobalKeyword(keyword: string): Promise<void> {
+ this.cache.set(FIND_GLOBAL_KEYWORD_KEY, keyword);
+ return Promise.resolve();
+ }
+
+ getLocalState(tabId: number): Promise<FindState | undefined> {
+ let states = this.cache.get(FIND_LOCAL_KEYWORD_KEY);
+ if (typeof states === "undefined") {
+ states = {};
+ }
+ return Promise.resolve(states[tabId]);
+ }
+
+ setLocalState(tabId: number, state: FindState): Promise<void> {
+ let states = this.cache.get(FIND_LOCAL_KEYWORD_KEY);
+ if (typeof states === "undefined") {
+ states = {};
+ }
+ states[tabId] = state;
+ this.cache.set(FIND_LOCAL_KEYWORD_KEY, states);
+ return Promise.resolve();
}
- setKeyword(keyword: string): Promise<void> {
- this.cache.set(FIND_KEYWORD_KEY, keyword);
+ deleteLocalState(tabId: number): Promise<void> {
+ const states = this.cache.get(FIND_LOCAL_KEYWORD_KEY);
+ if (typeof states === "undefined") {
+ return Promise.resolve();
+ }
+ delete states[tabId];
+ this.cache.set(FIND_LOCAL_KEYWORD_KEY, states);
return Promise.resolve();
}
}