Skip to content

Commit 5bd1544

Browse files
authored
Merge pull request #2237 from minbrowser/multi-window-2
Multi-window support
2 parents 38ca792 + 5d2f22a commit 5bd1544

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+758
-309
lines changed

js/browserUI.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,14 @@ function switchToTask (id) {
168168
function switchToTab (id, options) {
169169
options = options || {}
170170

171-
tabEditor.hide()
172-
173171
tabs.setSelected(id)
174172
tabBar.setActiveTab(id)
175173
webviews.setSelected(id, {
176174
focus: options.focusWebview !== false
177175
})
176+
177+
tabEditor.hide()
178+
178179
if (!tabs.get(id).url) {
179180
document.body.classList.add('is-ntp')
180181
} else {

js/default.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ process.argv.forEach(function (arg) {
88
}
99
})
1010

11+
window.windowId = globalArgs['window-id']
12+
1113
window.electron = require('electron')
1214
window.fs = require('fs')
1315
window.EventEmitter = require('events')
@@ -45,6 +47,16 @@ ipc.on('unmaximize', function () {
4547
document.body.classList.remove('maximized')
4648
})
4749

50+
document.body.classList.add('focused')
51+
52+
ipc.on('focus', function () {
53+
document.body.classList.add('focused')
54+
})
55+
56+
ipc.on('blur', function () {
57+
document.body.classList.remove('focused')
58+
})
59+
4860
// https://remysharp.com/2010/07/21/throttling-function-calls
4961

5062
window.throttle = function (fn, threshhold, scope) {
@@ -128,6 +140,7 @@ window.addEventListener('load', function () {
128140
})
129141

130142
require('tabState.js').initialize()
143+
require('tabState/windowSync.js').initialize()
131144
require('windowControls.js').initialize()
132145
require('navbar/menuButton.js').initialize()
133146

js/defaultKeybindings.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,24 +247,18 @@ const defaultKeybindings = {
247247
browserUI.addTab() // create a new, blank tab
248248
})
249249

250-
var lastReload = 0
250+
keybindings.defineShortcut('closeWindow', function() {
251+
ipc.invoke('close')
252+
})
251253

252254
keybindings.defineShortcut('reload', function () {
253-
var time = Date.now()
254-
255-
// pressing mod+r twice in a row reloads the whole browser
256-
if (time - lastReload < 500) {
257-
ipc.send('destroyAllViews')
258-
ipc.invoke('reloadWindow')
259-
} else if (tabs.get(tabs.getSelected()).url.startsWith(webviews.internalPages.error)) {
255+
if (tabs.get(tabs.getSelected()).url.startsWith(webviews.internalPages.error)) {
260256
// reload the original page rather than show the error page again
261257
webviews.update(tabs.getSelected(), new URL(tabs.get(tabs.getSelected()).url).searchParams.get('url'))
262258
} else {
263259
// this can't be an error page, use the normal reload method
264260
webviews.callAsync(tabs.getSelected(), 'reload')
265261
}
266-
267-
lastReload = time
268262
})
269263

270264
keybindings.defineShortcut('reloadIgnoringCache', function () {

js/focusMode.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ var isFocusMode = false
33
ipc.on('enterFocusMode', function () {
44
isFocusMode = true
55
document.body.classList.add('is-focus-mode')
6-
7-
setTimeout(function () { // wait to show the message until the tabs have been hidden, to make the message less confusing
8-
ipc.invoke('showFocusModeDialog1')
9-
}, 16)
106
})
117

128
ipc.on('exitFocusMode', function () {

js/keybindings.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ function initialize () {
133133
shortcut.keys.forEach(function (key) {
134134
if (!(
135135
key === input.key.toLowerCase() ||
136-
key === input.code.replace('Digit', '') ||
136+
key === input.code.replace('Digit', '').toLowerCase() ||
137+
key === input.code.replace('Key', '').toLowerCase() ||
137138
(key === 'esc' && input.key === 'Escape') ||
138139
(key === 'left' && input.key === 'ArrowLeft') ||
139140
(key === 'right' && input.key === 'ArrowRight') ||

js/navbar/tabBar.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ tasks.on('tab-updated', function (id, key) {
268268
})
269269

270270
permissionRequests.onChange(function (tabId) {
271-
tabBar.updateTab(tabId)
271+
if (tabs.get(tabId)) {
272+
tabBar.updateTab(tabId)
273+
}
272274
})
273275

274276
tabBar.initializeTabDragging()

js/places/fullTextSearch.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* global db Dexie */
22

33
const stemmer = require('stemmer')
4-
importScripts('../../ext/xregexp/nonLetterRegex.js')
54

65
const whitespaceRegex = /\s+/g
76

js/places/places.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
/* global Worker tabs */
1+
/* global tabs */
22

33
var webviews = require('webviews.js')
44
const searchEngine = require('util/searchEngine.js')
55
const urlParser = require('util/urlParser.js')
66

77
const places = {
8+
sendMessage: function (data) {
9+
ipc.send('places-request', data)
10+
},
811
savePage: function (tabId, extractedText) {
912
/* this prevents pages that are immediately left from being saved to history, and also gives the page-favicon-updated event time to fire (so the colors saved to history are correct). */
1013
setTimeout(function () {
@@ -17,7 +20,7 @@ const places = {
1720
extractedText: extractedText
1821
}
1922

20-
places.worker.postMessage({
23+
places.sendMessage({
2124
action: 'updatePlace',
2225
pageData: data,
2326
flags: {
@@ -73,21 +76,21 @@ const places = {
7376
}
7477
},
7578
deleteHistory: function (url) {
76-
places.worker.postMessage({
79+
places.sendMessage({
7780
action: 'deleteHistory',
7881
pageData: {
7982
url: url
8083
}
8184
})
8285
},
8386
deleteAllHistory: function () {
84-
places.worker.postMessage({
87+
places.sendMessage({
8588
action: 'deleteAllHistory'
8689
})
8790
},
8891
searchPlaces: function (text, callback, options) {
8992
const callbackId = places.addWorkerCallback(callback)
90-
places.worker.postMessage({
93+
places.sendMessage({
9194
action: 'searchPlaces',
9295
text: text,
9396
callbackId: callbackId,
@@ -96,26 +99,26 @@ const places = {
9699
},
97100
searchPlacesFullText: function (text, callback) {
98101
const callbackId = places.addWorkerCallback(callback)
99-
places.worker.postMessage({
102+
places.sendMessage({
100103
action: 'searchPlacesFullText',
101104
text: text,
102105
callbackId: callbackId
103106
})
104107
},
105108
getPlaceSuggestions: function (url, callback) {
106109
const callbackId = places.addWorkerCallback(callback)
107-
places.worker.postMessage({
110+
places.sendMessage({
108111
action: 'getPlaceSuggestions',
109112
text: url,
110113
callbackId: callbackId
111114
})
112115
},
113-
onMessage: function (e) { // assumes this is from a search operation
114-
places.runWorkerCallback(e.data.callbackId, e.data.result)
116+
onMessage: function (e, data) {
117+
places.runWorkerCallback(data.callbackId, data.result)
115118
},
116119
getItem: function (url, callback) {
117120
const callbackId = places.addWorkerCallback(callback)
118-
places.worker.postMessage({
121+
places.sendMessage({
119122
action: 'getPlace',
120123
pageData: {
121124
url: url
@@ -125,14 +128,14 @@ const places = {
125128
},
126129
getAllItems: function (callback) {
127130
const callbackId = places.addWorkerCallback(callback)
128-
places.worker.postMessage({
131+
places.sendMessage({
129132
action: 'getAllPlaces',
130133
callbackId: callbackId
131134
})
132135
},
133136
updateItem: function (url, fields, callback) {
134137
const callbackId = places.addWorkerCallback(callback)
135-
places.worker.postMessage({
138+
places.sendMessage({
136139
action: 'updatePlace',
137140
pageData: {
138141
url: url,
@@ -151,7 +154,7 @@ const places = {
151154
} else {
152155
item.tags.push(tag)
153156
}
154-
places.worker.postMessage({
157+
places.sendMessage({
155158
action: 'updatePlace',
156159
pageData: {
157160
url: url,
@@ -162,7 +165,7 @@ const places = {
162165
},
163166
getSuggestedTags: function (url, callback) {
164167
const callbackId = places.addWorkerCallback(callback)
165-
places.worker.postMessage({
168+
places.sendMessage({
166169
action: 'getSuggestedTags',
167170
pageData: {
168171
url: url
@@ -172,7 +175,7 @@ const places = {
172175
},
173176
getAllTagsRanked: function (url, callback) {
174177
const callbackId = places.addWorkerCallback(callback)
175-
places.worker.postMessage({
178+
places.sendMessage({
176179
action: 'getAllTagsRanked',
177180
pageData: {
178181
url: url
@@ -182,7 +185,7 @@ const places = {
182185
},
183186
getSuggestedItemsForTags: function (tags, callback) {
184187
const callbackId = places.addWorkerCallback(callback)
185-
places.worker.postMessage({
188+
places.sendMessage({
186189
action: 'getSuggestedItemsForTags',
187190
pageData: {
188191
tags: tags
@@ -192,7 +195,7 @@ const places = {
192195
},
193196
autocompleteTags: function (tags, callback) {
194197
const callbackId = places.addWorkerCallback(callback)
195-
places.worker.postMessage({
198+
places.sendMessage({
196199
action: 'autocompleteTags',
197200
pageData: {
198201
tags: tags
@@ -201,11 +204,7 @@ const places = {
201204
})
202205
},
203206
initialize: function () {
204-
if (places.worker) {
205-
places.worker.terminate()
206-
}
207-
places.worker = new Worker('js/places/placesWorker.js')
208-
places.worker.onmessage = places.onMessage
207+
ipc.on('places-response', places.onMessage)
209208

210209
webviews.bindIPC('pageData', places.receiveHistoryData)
211210
}

js/places/placesService.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Min history service</title>
5+
<script src="../../node_modules/dexie/dist/dexie.min.js"></script>
6+
<script src="../../node_modules/string_score/string_score.min.js"></script>
7+
<script src="../util/database.js"></script>
8+
<script src="../../ext/xregexp/nonLetterRegex.js"></script>
9+
<script src="fullTextSearch.js"></script>
10+
<script src="placesSearch.js"></script>
11+
<script src="tagIndex.js"></script>
12+
<script src="placesService.js"></script>
13+
</head>
14+
<body>
15+
</body>
16+
</html>

0 commit comments

Comments
 (0)