3
3
handleAuthUrl ,
4
4
setAuthLibStatus
5
5
} from '$Extensions/safe/actions/authenticator_actions' ;
6
- import { app } from 'electron' ;
6
+ import { app , BrowserWindow } from 'electron' ;
7
7
import * as safeBrowserAppActions from '$Extensions/safe/actions/safeBrowserApplication_actions' ;
8
8
import { initSafeBrowserApp } from '$Extensions/safe/safeBrowserApplication' ;
9
9
import { getLibStatus } from '$Extensions/safe/auth-api/authFuncs' ;
@@ -38,7 +38,7 @@ import registerSafeProtocol from './protocols/safe';
38
38
import setupRoutes from './server-routes' ;
39
39
import * as ffiLoader from './auth-api/ffiLoader' ;
40
40
41
- const onWebviewPreload = store => webviewPreload ( store ) ;
41
+ const onWebviewPreload = ( store ) => webviewPreload ( store ) ;
42
42
43
43
const preAppLoad = ( ) => {
44
44
// app.setPath( 'userData', path.resolve( app.getPath( 'temp' ), 'safe-browser' ) );
@@ -61,7 +61,7 @@ const addExtensionMenuItems = ( store, menusArray ) => {
61
61
62
62
const newMenuArray = [ ] ;
63
63
64
- menusArray . forEach ( menu => {
64
+ menusArray . forEach ( ( menu ) => {
65
65
const { label } = menu ;
66
66
let newMenu = menu ;
67
67
@@ -96,7 +96,7 @@ const actionsForBrowser = {
96
96
...SafeBrowserActions
97
97
} ;
98
98
99
- const onInitBgProcess = async store => {
99
+ const onInitBgProcess = async ( store ) => {
100
100
logger . info ( 'Registering SAFE Network Protocols' ) ;
101
101
try {
102
102
setSafeBgProcessStore ( store ) ;
@@ -112,15 +112,15 @@ const onInitBgProcess = async store => {
112
112
// load the auth/safe libs
113
113
const theLibs = await ffiLoader . loadLibrary ( startedRunningMock ) ;
114
114
115
- let prevAuthLibStatus ;
115
+ let previousAuthLibraryStatus ;
116
116
117
117
store . subscribe ( ( ) => {
118
- const authLibStatus = getLibStatus ( ) ;
118
+ const authLibraryStatus = getLibStatus ( ) ;
119
119
120
- if ( authLibStatus && authLibStatus !== prevAuthLibStatus ) {
121
- logger . info ( 'Authenticator lib status: ' , authLibStatus ) ;
122
- prevAuthLibStatus = authLibStatus ;
123
- store . dispatch ( setAuthLibStatus ( authLibStatus ) ) ;
120
+ if ( authLibraryStatus && authLibraryStatus !== previousAuthLibraryStatus ) {
121
+ logger . info ( 'Authenticator lib status: ' , authLibraryStatus ) ;
122
+ previousAuthLibraryStatus = authLibraryStatus ;
123
+ store . dispatch ( setAuthLibStatus ( authLibraryStatus ) ) ;
124
124
125
125
initSafeBrowserApp ( store ) ;
126
126
}
@@ -145,7 +145,7 @@ const onInitBgProcess = async store => {
145
145
* on open of peruse application
146
146
* @param {Object } store redux store
147
147
*/
148
- const onOpen = store =>
148
+ const onOpen = ( store ) =>
149
149
new Promise ( ( resolve , reject ) => {
150
150
logger . info ( 'OnOpen: Setting mock in store. ' , startedRunningMock ) ;
151
151
store . dispatch ( setIsMock ( startedRunningMock ) ) ;
@@ -157,7 +157,7 @@ const onOpen = store =>
157
157
* on open of peruse application
158
158
* @param {Object } store redux store
159
159
*/
160
- const onAppReady = store => {
160
+ const onAppReady = ( store ) => {
161
161
logger . info ( 'OnAppReady: Setting mock in store. ' , startedRunningMock ) ;
162
162
store . dispatch ( setIsMock ( startedRunningMock ) ) ;
163
163
} ;
@@ -166,7 +166,7 @@ const onAppReady = store => {
166
166
* Add middleware to Peruse redux store
167
167
* @param {Object } store redux store
168
168
*/
169
- const middleware = store => next => action => {
169
+ const middleware = ( store ) => ( next ) => ( action ) => {
170
170
if ( isRunningSpectronTestProcess ) {
171
171
logger . info ( 'ACTION:' , action ) ;
172
172
}
@@ -180,7 +180,7 @@ const parseSafeUri = function( uri ) {
180
180
} ;
181
181
182
182
const waitForBasicConnection = ( theStore , timeout = 15000 ) =>
183
- new Promise ( resolve => {
183
+ new Promise ( ( resolve ) => {
184
184
let timeLeft = timeout ;
185
185
const check = ( ) => {
186
186
timeLeft -= 500 ;
@@ -230,9 +230,13 @@ const onReceiveUrl = async ( store, url ) => {
230
230
if ( parsedUrl . protocol === 'safe:' ) {
231
231
await waitForBasicConnection ( store ) ;
232
232
233
- logger . info ( 'Handling safe: url' , url ) ;
234
- // which window is in focus?
235
- store . dispatch ( addTab ( { url, isActiveTab : true } ) ) ;
233
+ logger . info ( 'Opening safe: url' , url ) ;
234
+
235
+ const focusedWindowId = BrowserWindow . getFocusedWindow ( ) . webContents . id ;
236
+
237
+ store . dispatch (
238
+ addTab ( { url, isActiveTab : true , windowId : focusedWindowId } )
239
+ ) ;
236
240
}
237
241
// 20 is arbitrarily looong right now...
238
242
else if (
0 commit comments