/ app / ui / current-window.js
current-window.js
 1  window.getCurrentWindow = function getCurrentWindow () {
 2    const { ipcRenderer } = require('electron')
 3    const EventEmitter = require('events')
 4  
 5    const EVENTS = [
 6      'navigating',
 7      'history-buttons-change',
 8      'page-title-updated',
 9      'enter-html-full-screen',
10      'leave-html-full-screen',
11      'update-target-url',
12      'browser-actions-changed',
13      'close'
14    ]
15  
16    class CurrentWindow extends EventEmitter {
17      constructor () {
18        super()
19  
20        for (const name of EVENTS) {
21          ipcRenderer.on(`agregore-window-${name}`, (event, ...args) => this.emit(name, ...args))
22        }
23      }
24  
25      async goBack () {
26        return this.invoke('goBack')
27      }
28  
29      async goForward () {
30        return this.invoke('goForward')
31      }
32  
33      async reload () {
34        return this.invoke('reload')
35      }
36  
37      async focus () {
38        return this.invoke('focus')
39      }
40  
41      async loadURL (url) {
42        return this.invoke('loadURL', url)
43      }
44  
45      async getURL () {
46        return this.invoke('getURL')
47      }
48  
49      async findInPage (value, opts) {
50        return this.invoke('findInPage', value, opts)
51      }
52  
53      async stopFindInPage () {
54        return this.invoke('stopFindInPage')
55      }
56  
57      async setBounds (rect) {
58        return this.invoke('setBounds', rect)
59      }
60  
61      async searchHistory (query, limit = 8) {
62        return this.invoke('searchHistory', query, limit)
63      }
64  
65      async listExtensionActions () {
66        return this.invoke('listExtensionActions')
67      }
68  
69      async clickExtensionAction (id) {
70        return this.invoke('clickExtensionAction', id)
71      }
72  
73      async invoke (name, ...args) {
74        return ipcRenderer.invoke(`agregore-window-${name}`, ...args)
75      }
76    }
77  
78    return new CurrentWindow()
79  }