Repeat open, tabopen and winopen command
This commit is contained in:
parent
a2ee6897bf
commit
48e005dc82
7 changed files with 93 additions and 4 deletions
|
@ -3,6 +3,10 @@ import * as messages from '../../shared/messages';
|
|||
|
||||
export default interface OperationClient {
|
||||
execBackgroundOp(op: operations.Operation): Promise<void>;
|
||||
|
||||
internalOpenUrl(
|
||||
url: string, newTab?: boolean, background?: boolean,
|
||||
): Promise<void>;
|
||||
}
|
||||
|
||||
export class OperationClientImpl implements OperationClient {
|
||||
|
@ -12,4 +16,18 @@ export class OperationClientImpl implements OperationClient {
|
|||
operation: op,
|
||||
});
|
||||
}
|
||||
|
||||
internalOpenUrl(
|
||||
url: string, newTab?: boolean, background?: boolean,
|
||||
): Promise<void> {
|
||||
return browser.runtime.sendMessage({
|
||||
type: messages.BACKGROUND_OPERATION,
|
||||
operation: {
|
||||
type: operations.INTERNAL_OPEN_URL,
|
||||
url,
|
||||
newTab,
|
||||
background,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,16 +2,16 @@ 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';
|
||||
import OperationClient from '../client/OperationClient';
|
||||
|
||||
@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,
|
||||
@inject('OperationClient') private operationClinet: OperationClient,
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,10 @@ export default class ClipboardUseCase {
|
|||
let search = this.settingRepository.get().search;
|
||||
let text = this.repository.read();
|
||||
let url = urls.searchUrl(text, search);
|
||||
await this.client.openUrl(url, newTab);
|
||||
|
||||
// TODO: Repeat pasting from clipboard instead of opening a certain url.
|
||||
// 'Repeat last' command is implemented in the background script and cannot
|
||||
// access to clipboard until Firefox 63.
|
||||
await this.operationClinet.internalOpenUrl(url, newTab);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue