aboutsummaryrefslogtreecommitdiff
path: root/src/background/usecases/RepeatUseCase.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-05-26 16:24:14 +0900
committerGitHub <noreply@github.com>2019-05-26 16:24:14 +0900
commitcd584c8e243bafa8fc284279f716e8113607cd65 (patch)
treebc39bc30369f149e4ba4b6dc9c353b2906c4ef90 /src/background/usecases/RepeatUseCase.ts
parent07897df636ca3e732490d53fd2acf947738bf16e (diff)
parent34a96cdc9c5d7c8a11c6f1ae512fbc97724f61c4 (diff)
Merge pull request #592 from ueokande/repeat-last-operation
Add "repeat last operation" command
Diffstat (limited to 'src/background/usecases/RepeatUseCase.ts')
-rw-r--r--src/background/usecases/RepeatUseCase.ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/background/usecases/RepeatUseCase.ts b/src/background/usecases/RepeatUseCase.ts
new file mode 100644
index 0000000..d78de34
--- /dev/null
+++ b/src/background/usecases/RepeatUseCase.ts
@@ -0,0 +1,50 @@
+import { injectable } from 'tsyringe';
+import * as operations from '../../shared/operations';
+import RepeatRepository from '../repositories/RepeatRepository';
+
+type Operation = operations.Operation;
+
+@injectable()
+export default class RepeatUseCase {
+ constructor(
+ private repeatRepository: RepeatRepository,
+ ) {
+ }
+
+ storeLastOperation(op: Operation): void {
+ this.repeatRepository.setLastOperation(op);
+ }
+
+ getLastOperation(): operations.Operation | undefined {
+ return this.repeatRepository.getLastOperation();
+ }
+
+ // eslint-disable-next-line complexity
+ isRepeatable(op: Operation): boolean {
+ switch (op.type) {
+ case operations.NAVIGATE_HISTORY_PREV:
+ case operations.NAVIGATE_HISTORY_NEXT:
+ case operations.NAVIGATE_LINK_PREV:
+ case operations.NAVIGATE_LINK_NEXT:
+ case operations.NAVIGATE_PARENT:
+ case operations.NAVIGATE_ROOT:
+ case operations.PAGE_SOURCE:
+ case operations.PAGE_HOME:
+ case operations.TAB_CLOSE:
+ case operations.TAB_CLOSE_FORCE:
+ case operations.TAB_CLOSE_RIGHT:
+ case operations.TAB_REOPEN:
+ case operations.TAB_RELOAD:
+ case operations.TAB_PIN:
+ case operations.TAB_UNPIN:
+ case operations.TAB_TOGGLE_PINNED:
+ case operations.TAB_DUPLICATE:
+ case operations.ZOOM_IN:
+ case operations.ZOOM_OUT:
+ case operations.ZOOM_NEUTRAL:
+ case operations.INTERNAL_OPEN_URL:
+ return true;
+ }
+ return false;
+ }
+}