Skip to content

Commit fc6f90c

Browse files
committed
fix(Links): Opening a link will only open in focussed browser window now
1 parent 5aabb1a commit fc6f90c

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

app/extensions/safe/index.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
handleAuthUrl,
44
setAuthLibStatus
55
} from '$Extensions/safe/actions/authenticator_actions';
6-
import { app } from 'electron';
6+
import { app, BrowserWindow } from 'electron';
77
import * as safeBrowserAppActions from '$Extensions/safe/actions/safeBrowserApplication_actions';
88
import { initSafeBrowserApp } from '$Extensions/safe/safeBrowserApplication';
99
import { getLibStatus } from '$Extensions/safe/auth-api/authFuncs';
@@ -38,7 +38,7 @@ import registerSafeProtocol from './protocols/safe';
3838
import setupRoutes from './server-routes';
3939
import * as ffiLoader from './auth-api/ffiLoader';
4040

41-
const onWebviewPreload = store => webviewPreload( store );
41+
const onWebviewPreload = ( store ) => webviewPreload( store );
4242

4343
const preAppLoad = () => {
4444
// app.setPath( 'userData', path.resolve( app.getPath( 'temp' ), 'safe-browser' ) );
@@ -61,7 +61,7 @@ const addExtensionMenuItems = ( store, menusArray ) => {
6161

6262
const newMenuArray = [];
6363

64-
menusArray.forEach( menu => {
64+
menusArray.forEach( ( menu ) => {
6565
const { label } = menu;
6666
let newMenu = menu;
6767

@@ -96,7 +96,7 @@ const actionsForBrowser = {
9696
...SafeBrowserActions
9797
};
9898

99-
const onInitBgProcess = async store => {
99+
const onInitBgProcess = async ( store ) => {
100100
logger.info( 'Registering SAFE Network Protocols' );
101101
try {
102102
setSafeBgProcessStore( store );
@@ -112,15 +112,15 @@ const onInitBgProcess = async store => {
112112
// load the auth/safe libs
113113
const theLibs = await ffiLoader.loadLibrary( startedRunningMock );
114114

115-
let prevAuthLibStatus;
115+
let previousAuthLibraryStatus;
116116

117117
store.subscribe( () => {
118-
const authLibStatus = getLibStatus();
118+
const authLibraryStatus = getLibStatus();
119119

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 ) );
124124

125125
initSafeBrowserApp( store );
126126
}
@@ -145,7 +145,7 @@ const onInitBgProcess = async store => {
145145
* on open of peruse application
146146
* @param {Object} store redux store
147147
*/
148-
const onOpen = store =>
148+
const onOpen = ( store ) =>
149149
new Promise( ( resolve, reject ) => {
150150
logger.info( 'OnOpen: Setting mock in store. ', startedRunningMock );
151151
store.dispatch( setIsMock( startedRunningMock ) );
@@ -157,7 +157,7 @@ const onOpen = store =>
157157
* on open of peruse application
158158
* @param {Object} store redux store
159159
*/
160-
const onAppReady = store => {
160+
const onAppReady = ( store ) => {
161161
logger.info( 'OnAppReady: Setting mock in store. ', startedRunningMock );
162162
store.dispatch( setIsMock( startedRunningMock ) );
163163
};
@@ -166,7 +166,7 @@ const onAppReady = store => {
166166
* Add middleware to Peruse redux store
167167
* @param {Object} store redux store
168168
*/
169-
const middleware = store => next => action => {
169+
const middleware = ( store ) => ( next ) => ( action ) => {
170170
if ( isRunningSpectronTestProcess ) {
171171
logger.info( 'ACTION:', action );
172172
}
@@ -180,7 +180,7 @@ const parseSafeUri = function( uri ) {
180180
};
181181

182182
const waitForBasicConnection = ( theStore, timeout = 15000 ) =>
183-
new Promise( resolve => {
183+
new Promise( ( resolve ) => {
184184
let timeLeft = timeout;
185185
const check = () => {
186186
timeLeft -= 500;
@@ -230,9 +230,13 @@ const onReceiveUrl = async ( store, url ) => {
230230
if ( parsedUrl.protocol === 'safe:' ) {
231231
await waitForBasicConnection( store );
232232

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+
);
236240
}
237241
// 20 is arbitrarily looong right now...
238242
else if (

0 commit comments

Comments
 (0)