Clipbaord as a clean architecture
This commit is contained in:
parent
c6288f19d9
commit
8cef5981b8
7 changed files with 195 additions and 52 deletions
44
src/content/usecases/ClipboardUseCase.ts
Normal file
44
src/content/usecases/ClipboardUseCase.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
import * as urls from '../../shared/urls';
|
||||
import ClipboardRepository, { ClipboardRepositoryImpl }
|
||||
from '../repositories/ClipboardRepository';
|
||||
import SettingRepository, { SettingRepositoryImpl }
|
||||
from '../repositories/SettingRepository';
|
||||
import TabsClient, { TabsClientImpl }
|
||||
from '../client/TabsClient';
|
||||
import ConsoleClient, { ConsoleClientImpl } from '../client/ConsoleClient';
|
||||
|
||||
export default class ClipboardUseCase {
|
||||
private repository: ClipboardRepository;
|
||||
|
||||
private settingRepository: SettingRepository;
|
||||
|
||||
private client: TabsClient;
|
||||
|
||||
private consoleClient: ConsoleClient;
|
||||
|
||||
constructor({
|
||||
repository = new ClipboardRepositoryImpl(),
|
||||
settingRepository = new SettingRepositoryImpl(),
|
||||
client = new TabsClientImpl(),
|
||||
consoleClient = new ConsoleClientImpl(),
|
||||
} = {}) {
|
||||
this.repository = repository;
|
||||
this.settingRepository = settingRepository;
|
||||
this.client = client;
|
||||
this.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);
|
||||
}
|
||||
}
|
Reference in a new issue