import { Requester } from "../requester" ; import { ChildProcess } from "child_process" ; import { WithError , NullableError } from "../error" ; export type Tab = { id ? : number ; title : string ; url : string ; active : boolean ; } ; export class TabRepository { constructor ( protected readonly requester ) { } public async getCurrent ( ) { return this . requester . execute < Tab > ( { method : "tab/getCurrent" , } ) ; } public async getListAll ( ) { const [ tabs , error ] = await this . requester . execute < Tab [ ] > ( { method : "tab/listAll" , } ) ; if ( tabs === null ) { return [ [ ] , error ] ; } return [ tabs , null ] ; } public async close ( ids ) { return this . requester . batchNotify ( ids . map ( id => { return { method : "tab/close" , params : { id : id } } ; } ) ) ; } public async duplicate ( ids ) { return this . requester . batchNotify ( ids . map ( id => { return { method : "tab/duplicate" , params : { id : id } } ; } ) ) ; } public async reload ( ids ) { return this . requester . batchNotify ( ids . map ( id => { return { method : "tab/reload" , params : { id : id } } ; } ) ) ; } public async activate ( id ) { return this . requester . executeAsync ( { method : "tab/activate" , params : { id : id } , } ) ; } public async open ( url ) { return this . requester . executeAsync ( { method : "tab/open" , params : { url : url } , } ) ; } public async tabOpen ( urls ) { return this . requester . batchNotify ( urls . map ( url => { return { method : "tab/tabOpen" , params : { url : url } } ; } ) ) ; } public async zoomUp ( ids ) { return this . requester . batchNotify ( ids . map ( id => { return { method : "tab/zoom/up" , params : { id : id } } ; } ) ) ; } public async zoomDown ( ids ) { return this . requester . batchNotify ( ids . map ( id => { return { method : "tab/zoom/down" , params : { id : id } } ; } ) ) ; } public async zoomReset ( ids ) { return this . requester . batchNotify ( ids . map ( id => { return { method : "tab/zoom/reset" , params : { id : id } } ; } ) ) ; } public async onChanged ( callback ) { return this . requester . receiveAsyncOnEvent < Tab > ( { } , { } , { body : { eventName : "tabActivated|tabCreated|tabRemoved|tabUpdated|windowActivated|windowCreated|windowRemoved" , } , } , callback , 50 ) ; } }