Skip to content

Commit

Permalink
fix: update app bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
Najeong-Kim committed Nov 5, 2024
1 parent 9dff610 commit 2703b7d
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/shared/lib/postAppMessage.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
declare global {
interface Window {
BRIDGE: {
sendMessage: (message: string) => void;
Android: {
showToast: (message: string) => void;
};
webkit: {
messageHandlers: {
weski: {
showToast: (message: string) => void;
postMessage: ({ method, message }: { method: "showToast", message: string }) => void;
};
};
};
}
}

const postAppMessage = (message: string) => {
const userAgent = navigator.userAgent;
const android = userAgent.match(/Android/i);
const iphone = userAgent.match(/iPhone/i);
const userAgent = navigator.userAgent.toLowerCase();
const android = userAgent.match(/android/i);
const iphone = userAgent.match(/iphone/i);

if (android !== null) {
console.log("Android");
return window.BRIDGE.sendMessage(message);

return window.Android.showToast(message);
} else if (iphone !== null) {
console.log("iOS");
return window.webkit.messageHandlers.weski.showToast(message);

if (window.webkit.messageHandlers.weski) {
window.webkit.messageHandlers.weski.postMessage({ method: "showToast", message: message });
} else {
console.error("Weski bridge is not available.");
}
} else {
return window.opener.postMessage(message);
}
Expand Down

0 comments on commit 2703b7d

Please sign in to comment.