diff --git a/package-lock.json b/package-lock.json index b5b20765..345b6dae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,7 @@ "@nethesis/nethesis-brands-svg-icons": "github:nethesis/Font-Awesome#ns-brands", "@nethesis/nethesis-light-svg-icons": "github:nethesis/Font-Awesome#ns-light", "@nethesis/nethesis-solid-svg-icons": "github:nethesis/Font-Awesome#ns-solid", - "@nethesis/phone-island": "^0.14.7", + "@nethesis/phone-island": "^0.15.6", "@tailwindcss/forms": "^0.5.7", "@types/lodash": "^4.14.202", "@types/node": "^18.19.9", @@ -5639,9 +5639,9 @@ } }, "node_modules/@nethesis/phone-island": { - "version": "0.14.7", - "resolved": "https://registry.npmjs.org/@nethesis/phone-island/-/phone-island-0.14.7.tgz", - "integrity": "sha512-jhZPaAvwP3d16gwudDDX5OGY5/82uvMmnOcdDW1zCgkkI8lg4mq7ytg6Kzn0Xbf/zw0OHACRw8b8RiXFhgMpww==", + "version": "0.15.6", + "resolved": "https://registry.npmjs.org/@nethesis/phone-island/-/phone-island-0.15.6.tgz", + "integrity": "sha512-XgQTAu1SaKIhi2KswHS3BNnkM8LL1qdM51k2O820L+YK/ZeQ7WWmI9WmfjamKMxkRbZkzwyOUob9jrIIY8DymQ==", "dev": true, "license": "GPL-3.0-or-later", "dependencies": { diff --git a/package.json b/package.json index 70c87127..fd00b2c9 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "@nethesis/nethesis-brands-svg-icons": "github:nethesis/Font-Awesome#ns-brands", "@nethesis/nethesis-light-svg-icons": "github:nethesis/Font-Awesome#ns-light", "@nethesis/nethesis-solid-svg-icons": "github:nethesis/Font-Awesome#ns-solid", - "@nethesis/phone-island": "^0.14.7", + "@nethesis/phone-island": "^0.15.6", "@tailwindcss/forms": "^0.5.7", "@types/lodash": "^4.14.202", "@types/node": "^18.19.9", diff --git a/src/main/lib/ipcEvents.ts b/src/main/lib/ipcEvents.ts index 213f6292..29417770 100644 --- a/src/main/lib/ipcEvents.ts +++ b/src/main/lib/ipcEvents.ts @@ -213,12 +213,7 @@ export function registerIpcEvents() { }) ipcMain.on(IPC_EVENTS.OPEN_EXTERNAL_PAGE, async (event, path) => { - if (isDev()) { - const window = BrowserWindow.fromWebContents(event.sender); - window?.loadURL(join(path)) - } else { - shell.openExternal(join(path)) - } + shell.openExternal(path) }) ipcMain.on(IPC_EVENTS.COPY_TO_CLIPBOARD, async (_, text) => { @@ -408,4 +403,12 @@ export function registerIpcEvents() { Log.error('ENTER SCREEN_SHARE_INIT error ', e) }); }); + + ipcMain.on(IPC_EVENTS.URL_OPEN, (_, data) => { + try { + PhoneIslandController.instance.window.emit(IPC_EVENTS.URL_OPEN, data) + } catch (e) { + Log.error('URL PARAM error', e) + } + }) } diff --git a/src/renderer/src/hooks/usePhoneIslandEventListeners.ts b/src/renderer/src/hooks/usePhoneIslandEventListeners.ts index 524b41c8..bebc8c19 100644 --- a/src/renderer/src/hooks/usePhoneIslandEventListeners.ts +++ b/src/renderer/src/hooks/usePhoneIslandEventListeners.ts @@ -250,6 +250,10 @@ export const usePhoneIslandEventListener = () => { ...eventHandler(PHONE_ISLAND_EVENTS["phone-island-screen-share-initialized"], () => { window.electron.send(IPC_EVENTS.SCREEN_SHARE_INIT) }), + ...eventHandler(PHONE_ISLAND_EVENTS["phone-island-url-parameter-opened-external"], (data) => { + window.electron.send(IPC_EVENTS.URL_OPEN, data.formattedUrl) + }), + ...eventHandler(PHONE_ISLAND_EVENTS["phone-island-already-opened-external-page"]), } } } diff --git a/src/renderer/src/pages/PhoneIslandPage.tsx b/src/renderer/src/pages/PhoneIslandPage.tsx index fbf3f693..2bce7a30 100644 --- a/src/renderer/src/pages/PhoneIslandPage.tsx +++ b/src/renderer/src/pages/PhoneIslandPage.tsx @@ -27,6 +27,11 @@ export function PhoneIslandPage() { const isOnLogout = useRef(false) const eventsRef = useRef<{ [x: string]: (...data: any[]) => void; }>(events) const attachedListener = useRef(false) + const lastOpenedUrl = useRef(null) + const urlOpenTimeout = useRef | null>(null) + const isUrlOpening = useRef(false) + const urlOpenAttempts = useRef(0) + const urlOpenListenerRegistered = useRef(false) useEffect(() => { resize(phoneIsalndSizes) @@ -60,14 +65,12 @@ export function PhoneIslandPage() { }) window.electron.receive(IPC_EVENTS.START_CALL, (number: string) => { - //controllare se sono physical eventDispatch(PHONE_ISLAND_EVENTS['phone-island-call-start'], { number }) }) window.electron.receive(IPC_EVENTS.END_CALL, () => { - //controllare se sono physical eventDispatch(PHONE_ISLAND_EVENTS['phone-island-call-end']) }) @@ -96,8 +99,55 @@ export function PhoneIslandPage() { eventDispatch(PHONE_ISLAND_EVENTS['phone-island-default-device-change'], { deviceInformationObject }) } }) + + if (!urlOpenListenerRegistered.current) { + urlOpenListenerRegistered.current = true; + + window.electron.receive(IPC_EVENTS.URL_OPEN, (urlInfo: string) => { + urlOpenAttempts.current++; + + if (isUrlOpening.current) { + return; + } + + if (lastOpenedUrl.current === urlInfo) { + return; + } + + isUrlOpening.current = true; + lastOpenedUrl.current = urlInfo; + + window.api.openExternalPage(urlInfo); + eventDispatch(PHONE_ISLAND_EVENTS['phone-island-already-opened-external-page'], {}); + + urlOpenAttempts.current = 0; + + if (urlOpenTimeout.current) { + clearTimeout(urlOpenTimeout.current); + } + + urlOpenTimeout.current = setTimeout(() => { + isUrlOpening.current = false; + lastOpenedUrl.current = null; + urlOpenTimeout.current = null; + }, 5000); + }); + } + }) + useEffect(() => { + return () => { + if (urlOpenTimeout.current) { + clearTimeout(urlOpenTimeout.current); + urlOpenTimeout.current = null; + } + isUrlOpening.current = false; + lastOpenedUrl.current = null; + urlOpenAttempts.current = 0; + }; + }, []); + const resize = (phoneIsalndSize: PhoneIslandSizes) => { if (!isOnLogout.current) { const { width, height, top, bottom, left, right } = phoneIsalndSize.sizes @@ -181,6 +231,14 @@ export function PhoneIslandPage() { window.electron.send(IPC_EVENTS.LOGOUT_COMPLETED) } + useEffect(() => { + return () => { + if (urlOpenTimeout.current) { + clearTimeout(urlOpenTimeout.current); + } + }; + }, []); + return (