Skip to content

Commit 5b8c394

Browse files
authored
fix: created new event to manage urlParam (#69)
1 parent 04337ce commit 5b8c394

File tree

6 files changed

+83
-14
lines changed

6 files changed

+83
-14
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@nethesis/nethesis-brands-svg-icons": "github:nethesis/Font-Awesome#ns-brands",
5050
"@nethesis/nethesis-light-svg-icons": "github:nethesis/Font-Awesome#ns-light",
5151
"@nethesis/nethesis-solid-svg-icons": "github:nethesis/Font-Awesome#ns-solid",
52-
"@nethesis/phone-island": "^0.14.7",
52+
"@nethesis/phone-island": "^0.15.6",
5353
"@tailwindcss/forms": "^0.5.7",
5454
"@types/lodash": "^4.14.202",
5555
"@types/node": "^18.19.9",

src/main/lib/ipcEvents.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,7 @@ export function registerIpcEvents() {
213213
})
214214

215215
ipcMain.on(IPC_EVENTS.OPEN_EXTERNAL_PAGE, async (event, path) => {
216-
if (isDev()) {
217-
const window = BrowserWindow.fromWebContents(event.sender);
218-
window?.loadURL(join(path))
219-
} else {
220-
shell.openExternal(join(path))
221-
}
216+
shell.openExternal(path)
222217
})
223218

224219
ipcMain.on(IPC_EVENTS.COPY_TO_CLIPBOARD, async (_, text) => {
@@ -408,4 +403,12 @@ export function registerIpcEvents() {
408403
Log.error('ENTER SCREEN_SHARE_INIT error ', e)
409404
});
410405
});
406+
407+
ipcMain.on(IPC_EVENTS.URL_OPEN, (_, data) => {
408+
try {
409+
PhoneIslandController.instance.window.emit(IPC_EVENTS.URL_OPEN, data)
410+
} catch (e) {
411+
Log.error('URL PARAM error', e)
412+
}
413+
})
411414
}

src/renderer/src/hooks/usePhoneIslandEventListeners.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ export const usePhoneIslandEventListener = () => {
250250
...eventHandler(PHONE_ISLAND_EVENTS["phone-island-screen-share-initialized"], () => {
251251
window.electron.send(IPC_EVENTS.SCREEN_SHARE_INIT)
252252
}),
253+
...eventHandler(PHONE_ISLAND_EVENTS["phone-island-url-parameter-opened-external"], (data) => {
254+
window.electron.send(IPC_EVENTS.URL_OPEN, data.formattedUrl)
255+
}),
256+
...eventHandler(PHONE_ISLAND_EVENTS["phone-island-already-opened-external-page"]),
253257
}
254258
}
255259
}

src/renderer/src/pages/PhoneIslandPage.tsx

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export function PhoneIslandPage() {
2727
const isOnLogout = useRef<boolean>(false)
2828
const eventsRef = useRef<{ [x: string]: (...data: any[]) => void; }>(events)
2929
const attachedListener = useRef<boolean>(false)
30+
const lastOpenedUrl = useRef<string | null>(null)
31+
const urlOpenTimeout = useRef<ReturnType<typeof setTimeout> | null>(null)
32+
const isUrlOpening = useRef<boolean>(false)
33+
const urlOpenAttempts = useRef<number>(0)
34+
const urlOpenListenerRegistered = useRef<boolean>(false)
3035

3136
useEffect(() => {
3237
resize(phoneIsalndSizes)
@@ -60,14 +65,12 @@ export function PhoneIslandPage() {
6065
})
6166

6267
window.electron.receive(IPC_EVENTS.START_CALL, (number: string) => {
63-
//controllare se sono physical
6468
eventDispatch(PHONE_ISLAND_EVENTS['phone-island-call-start'], {
6569
number
6670
})
6771
})
6872

6973
window.electron.receive(IPC_EVENTS.END_CALL, () => {
70-
//controllare se sono physical
7174
eventDispatch(PHONE_ISLAND_EVENTS['phone-island-call-end'])
7275
})
7376

@@ -96,8 +99,55 @@ export function PhoneIslandPage() {
9699
eventDispatch(PHONE_ISLAND_EVENTS['phone-island-default-device-change'], { deviceInformationObject })
97100
}
98101
})
102+
103+
if (!urlOpenListenerRegistered.current) {
104+
urlOpenListenerRegistered.current = true;
105+
106+
window.electron.receive(IPC_EVENTS.URL_OPEN, (urlInfo: string) => {
107+
urlOpenAttempts.current++;
108+
109+
if (isUrlOpening.current) {
110+
return;
111+
}
112+
113+
if (lastOpenedUrl.current === urlInfo) {
114+
return;
115+
}
116+
117+
isUrlOpening.current = true;
118+
lastOpenedUrl.current = urlInfo;
119+
120+
window.api.openExternalPage(urlInfo);
121+
eventDispatch(PHONE_ISLAND_EVENTS['phone-island-already-opened-external-page'], {});
122+
123+
urlOpenAttempts.current = 0;
124+
125+
if (urlOpenTimeout.current) {
126+
clearTimeout(urlOpenTimeout.current);
127+
}
128+
129+
urlOpenTimeout.current = setTimeout(() => {
130+
isUrlOpening.current = false;
131+
lastOpenedUrl.current = null;
132+
urlOpenTimeout.current = null;
133+
}, 5000);
134+
});
135+
}
136+
99137
})
100138

139+
useEffect(() => {
140+
return () => {
141+
if (urlOpenTimeout.current) {
142+
clearTimeout(urlOpenTimeout.current);
143+
urlOpenTimeout.current = null;
144+
}
145+
isUrlOpening.current = false;
146+
lastOpenedUrl.current = null;
147+
urlOpenAttempts.current = 0;
148+
};
149+
}, []);
150+
101151
const resize = (phoneIsalndSize: PhoneIslandSizes) => {
102152
if (!isOnLogout.current) {
103153
const { width, height, top, bottom, left, right } = phoneIsalndSize.sizes
@@ -181,6 +231,14 @@ export function PhoneIslandPage() {
181231
window.electron.send(IPC_EVENTS.LOGOUT_COMPLETED)
182232
}
183233

234+
useEffect(() => {
235+
return () => {
236+
if (urlOpenTimeout.current) {
237+
clearTimeout(urlOpenTimeout.current);
238+
}
239+
};
240+
}, []);
241+
184242
return (
185243
<div
186244
ref={phoneIslandContainer}

src/shared/constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ export enum IPC_EVENTS {
9393
CHANGE_SHORTCUT = 'CHANGE_SHORTCUT',
9494
COPY_TO_CLIPBOARD = "COPY_TO_CLIPBOARD",
9595
CHANGE_PREFERRED_DEVICES = "CHANGE_PREFERRED_DEVICES",
96-
PHONE_ISLAND_READY = "PHONE_ISLAND_READY"
96+
PHONE_ISLAND_READY = "PHONE_ISLAND_READY",
97+
URL_OPEN = "URL_OPEN",
9798
}
9899

99100
//PHONE ISLAND EVENTS
@@ -225,4 +226,7 @@ export enum PHONE_ISLAND_EVENTS {
225226
'phone-island-fullscreen-exited' = 'phone-island-fullscreen-exited',
226227
// Screen Share
227228
'phone-island-screen-share-initialized' = 'phone-island-screen-share-initialized',
229+
// Url param
230+
'phone-island-url-parameter-opened-external' = 'phone-island-url-parameter-opened-external',
231+
'phone-island-already-opened-external-page' = 'phone-island-already-opened-external-page',
228232
}

0 commit comments

Comments
 (0)