aboutsummaryrefslogtreecommitdiff
path: root/src/content/usecases/ClipboardUseCase.ts
blob: 8c4d62190b8dd7143510f2b5e320e3ead93431d6 (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
import { injectable, inject } from 'tsyringe';
import * as urls from '../../shared/urls';
import ClipboardRepository from '../repositories/ClipboardRepository';
import SettingRepository from '../repositories/SettingRepository';
import TabsClient from '../client/TabsClient';
import ConsoleClient from '../client/ConsoleClient';

@injectable()
export default class ClipboardUseCase {
  constructor(
    @inject('ClipboardRepository') private repository: ClipboardRepository,
    @inject('SettingRepository') private settingRepository: SettingRepository,
    @inject('TabsClient') private client: TabsClient,
    @inject('ConsoleClient') private consoleClient: ConsoleClient,
  ) {
  }

  async yankCurrentURL(): Promise<string> {
    let url = window.location.href;
    this.repository.write(url);
    await this.consoleClient.info('Yanked ' + url);
    return Promise.resolve(url);
  }

  async openOrSearch(newTab: boolean): Promise<void> {
    let search = this.settingRepository.get().search;
    let text = this.repository.read();
    let url = urls.searchUrl(text, search);
    await this.client.openUrl(url, newTab);
  }
}