Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 9 additions & 6 deletions src/main/lib/ipcEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)
}
})
}
4 changes: 4 additions & 0 deletions src/renderer/src/hooks/usePhoneIslandEventListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
}
}
}
62 changes: 60 additions & 2 deletions src/renderer/src/pages/PhoneIslandPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ export function PhoneIslandPage() {
const isOnLogout = useRef<boolean>(false)
const eventsRef = useRef<{ [x: string]: (...data: any[]) => void; }>(events)
const attachedListener = useRef<boolean>(false)
const lastOpenedUrl = useRef<string | null>(null)
const urlOpenTimeout = useRef<ReturnType<typeof setTimeout> | null>(null)
const isUrlOpening = useRef<boolean>(false)
const urlOpenAttempts = useRef<number>(0)
const urlOpenListenerRegistered = useRef<boolean>(false)

useEffect(() => {
resize(phoneIsalndSizes)
Expand Down Expand Up @@ -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'])
})

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -181,6 +231,14 @@ export function PhoneIslandPage() {
window.electron.send(IPC_EVENTS.LOGOUT_COMPLETED)
}

useEffect(() => {
return () => {
if (urlOpenTimeout.current) {
clearTimeout(urlOpenTimeout.current);
}
};
}, []);

return (
<div
ref={phoneIslandContainer}
Expand Down
6 changes: 5 additions & 1 deletion src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export enum IPC_EVENTS {
CHANGE_SHORTCUT = 'CHANGE_SHORTCUT',
COPY_TO_CLIPBOARD = "COPY_TO_CLIPBOARD",
CHANGE_PREFERRED_DEVICES = "CHANGE_PREFERRED_DEVICES",
PHONE_ISLAND_READY = "PHONE_ISLAND_READY"
PHONE_ISLAND_READY = "PHONE_ISLAND_READY",
URL_OPEN = "URL_OPEN",
}

//PHONE ISLAND EVENTS
Expand Down Expand Up @@ -225,4 +226,7 @@ export enum PHONE_ISLAND_EVENTS {
'phone-island-fullscreen-exited' = 'phone-island-fullscreen-exited',
// Screen Share
'phone-island-screen-share-initialized' = 'phone-island-screen-share-initialized',
// Url param
'phone-island-url-parameter-opened-external' = 'phone-island-url-parameter-opened-external',
'phone-island-already-opened-external-page' = 'phone-island-already-opened-external-page',
}
Loading