Flipper browser singleton

Summary:
This will ensure only one instance of Flipper is running at any given point in time.

#thanks antonk52 for guidance and advise implementing a single Flipper instance solution which will improve overall Flipper user experience.

Reviewed By: antonk52

Differential Revision: D50455446

fbshipit-source-id: 2407c77d43ba28e91d525f6cdb11d7b9db1cfab7
This commit is contained in:
Lorenzo Blasa
2023-11-02 03:31:35 -07:00
committed by Facebook GitHub Bot
parent 1a98038979
commit c8ee1847a2

View File

@@ -28,6 +28,16 @@ let cachedDeepLinkURL: string | undefined;
const logger = initLogger(); const logger = initLogger();
async function start() { async function start() {
/**
* The following is used to ensure only one instance of Flipper is running at a time.
* The event will not be fired for the current tab.
*/
window.addEventListener('storage', function (event) {
if (event.key === 'flipper-kill-window') {
window.close();
}
});
// @ts-ignore // @ts-ignore
electronRequire = function (path: string) { electronRequire = function (path: string) {
console.error( console.error(
@@ -143,6 +153,12 @@ async function start() {
require('flipper-ui-core').startFlipperDesktop(flipperServer); require('flipper-ui-core').startFlipperDesktop(flipperServer);
window.flipperHideMessage?.(); window.flipperHideMessage?.();
/**
* At this stage, the current client has established a connection with the server.
* So, it is safe to 'set' into local storage so that other clients close.
*/
localStorage.setItem('flipper-kill-window', Date.now().toString());
getLogger().info('[flipper-client][ui-browser] UI initialised'); getLogger().info('[flipper-client][ui-browser] UI initialised');
logger.track('success-rate', 'flipper-ui-browser-started', {value: 1}); logger.track('success-rate', 'flipper-ui-browser-started', {value: 1});
} }