aboutsummaryrefslogtreecommitdiff
path: root/src/background/usecases/ConsoleUseCase.ts
blob: 2de5bc19732e98cdd32113e020ba2b269a438e03 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { inject, injectable } from 'tsyringe';
import TabPresenter from '../presenters/TabPresenter';
import ConsoleClient from '../infrastructures/ConsoleClient';

@injectable()
export default class ConsoleUseCase {

  constructor(
    @inject('TabPresenter') private tabPresenter: TabPresenter,
    private consoleClient: ConsoleClient,
  ) {
  }

  async showCommand(): Promise<any> {
    const tab = await this.tabPresenter.getCurrent();
    return this.consoleClient.showCommand(tab.id as number, '');
  }

  async showOpenCommand(alter: boolean): Promise<any> {
    const tab = await this.tabPresenter.getCurrent();
    let command = 'open ';
    if (alter) {
      command += tab.url || '';
    }
    return this.consoleClient.showCommand(tab.id as number, command);
  }

  async showTabopenCommand(alter: boolean): Promise<any> {
    const tab = await this.tabPresenter.getCurrent();
    let command = 'tabopen ';
    if (alter) {
      command += tab.url || '';
    }
    return this.consoleClient.showCommand(tab.id as number, command);
  }

  async showWinopenCommand(alter: boolean): Promise<any> {
    const tab = await this.tabPresenter.getCurrent();
    let command = 'winopen ';
    if (alter) {
      command += tab.url || '';
    }
    return this.consoleClient.showCommand(tab.id as number, command);
  }

  async showBufferCommand(): Promise<any> {
    const tab = await this.tabPresenter.getCurrent();
    const command = 'buffer ';
    return this.consoleClient.showCommand(tab.id as number, command);
  }

  async showAddbookmarkCommand(alter: boolean): Promise<any> {
    const tab = await this.tabPresenter.getCurrent();
    let command = 'addbookmark ';
    if (alter) {
      command += tab.title || '';
    }
    return this.consoleClient.showCommand(tab.id as number, command);
  }

  async hideConsole(): Promise<any> {
    const tab = await this.tabPresenter.getCurrent();
    return this.consoleClient.hide(tab.id as number);
  }
}