Repeat open, tabopen and winopen command

This commit is contained in:
Shin'ya Ueoka 2019-05-25 21:55:45 +09:00
parent a2ee6897bf
commit 48e005dc82
7 changed files with 93 additions and 4 deletions

View file

@ -78,6 +78,9 @@ export const MARK_JUMP_PREFIX = 'mark.jump.prefix';
// Repeat
export const REPEAT_LAST = 'repeat.last';
// Internal
export const INTERNAL_OPEN_URL = 'internal.open.url';
export interface CancelOperation {
type: typeof CANCEL;
}
@ -298,6 +301,14 @@ export interface RepeatLastOperation {
type: typeof REPEAT_LAST;
}
export interface InternalOpenUrl {
type: typeof INTERNAL_OPEN_URL;
url: string;
newTab?: boolean;
newWindow?: boolean;
background?: boolean;
}
export type Operation =
CancelOperation |
AddonEnableOperation |
@ -350,7 +361,8 @@ export type Operation =
FindPrevOperation |
MarkSetPrefixOperation |
MarkJumpPrefixOperation |
RepeatLastOperation;
RepeatLastOperation |
InternalOpenUrl;
const assertOptionalBoolean = (obj: any, name: string) => {
if (Object.prototype.hasOwnProperty.call(obj, name) &&
@ -366,6 +378,13 @@ const assertRequiredNumber = (obj: any, name: string) => {
}
};
const assertRequiredString = (obj: any, name: string) => {
if (!Object.prototype.hasOwnProperty.call(obj, name) ||
typeof obj[name] !== 'string') {
throw new TypeError(`Missing string parameter '${name}`);
}
};
// eslint-disable-next-line complexity, max-lines-per-function
export const valueOf = (o: any): Operation => {
if (!Object.prototype.hasOwnProperty.call(o, 'type')) {
@ -409,6 +428,18 @@ export const valueOf = (o: any): Operation => {
type: URLS_PASTE,
newTab: Boolean(typeof o.newTab === undefined ? false : o.newTab),
};
case INTERNAL_OPEN_URL:
assertOptionalBoolean(o, 'newTab');
assertOptionalBoolean(o, 'newWindow');
assertOptionalBoolean(o, 'background');
assertRequiredString(o, 'url');
return {
type: INTERNAL_OPEN_URL,
url: o.url,
newTab: Boolean(typeof o.newTab === undefined ? false : o.newTab),
newWindow: Boolean(typeof o.newWindow === undefined ? false : o.newWindow), // eslint-disable-line max-len
background: Boolean(typeof o.background === undefined ? true : o.background), // eslint-disable-line max-len
};
case CANCEL:
case ADDON_ENABLE:
case ADDON_DISABLE: