-
Notifications
You must be signed in to change notification settings - Fork 0
Add popup to show when desktop app is not running #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
cf1895a
Add popup to show when desktop app is not running
naps62 f5ab7c4
Add wallet info display in popup when connected
naps62 6fdf6a2
Check connection on popup open when state is unknown
naps62 ab2f4bd
Use viem for chain names and fix notification icon
naps62 740b530
wip
naps62 35d98c7
wip
naps62 d733993
Fix connection check hanging when WebSocket closes without error
naps62 eb70515
Left-align popup content and use consistent title styling
naps62 cd815f1
Auto-reconnect when desktop app becomes available
naps62 5a94433
Detect disconnection when desktop app closes
naps62 af77525
Add error alert to disconnected state
naps62 be6fcb4
Refactor popup into hooks and components
naps62 b10e12d
Move useWalletInfo into ConnectedView
naps62 3ff92ff
wip
naps62 995f691
wip
naps62 67f7cc2
wip
naps62 e6ffc6d
wip
naps62 db79fb9
wip
naps62 b9269cf
wip
naps62 fa192f8
wip
naps62 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /// <reference types="chrome" /> | ||
| import { action, runtime } from "webextension-polyfill"; | ||
|
|
||
| export type ConnectionState = "connected" | "disconnected" | "unknown"; | ||
|
|
||
| let globalConnectionState: ConnectionState = "unknown"; | ||
| let hasShownNotification = false; | ||
|
|
||
| const NOTIFICATION_ID = "ethui-connection-status"; | ||
|
|
||
| export function getConnectionState(): ConnectionState { | ||
| return globalConnectionState; | ||
| } | ||
|
|
||
| export function setConnectionState(state: ConnectionState) { | ||
| const previousState = globalConnectionState; | ||
| globalConnectionState = state; | ||
|
|
||
| // Broadcast state change to any open popups | ||
| runtime | ||
| .sendMessage({ | ||
| type: "connection-state", | ||
| state: globalConnectionState, | ||
| }) | ||
| .catch(() => { | ||
| // Popup may not be open, ignore error | ||
| }); | ||
|
|
||
| updateBadge(); | ||
|
|
||
| // Show notification on first disconnection | ||
| if ( | ||
| state === "disconnected" && | ||
| previousState !== "disconnected" && | ||
| !hasShownNotification | ||
| ) { | ||
| showDisconnectedNotification(); | ||
| hasShownNotification = true; | ||
| } | ||
|
|
||
| // Reset notification flag when connected | ||
| if (state === "connected") { | ||
| hasShownNotification = false; | ||
| } | ||
| } | ||
|
|
||
| function updateBadge() { | ||
| if (globalConnectionState === "disconnected") { | ||
| action.setBadgeText({ text: "!" }); | ||
| action.setBadgeBackgroundColor({ color: "#ef4444" }); | ||
| } else if (globalConnectionState === "connected") { | ||
| action.setBadgeText({ text: "" }); | ||
| } | ||
| } | ||
|
|
||
| function showDisconnectedNotification() { | ||
| if (!chrome.notifications?.create) { | ||
| return; | ||
| } | ||
|
|
||
| chrome.notifications.create(NOTIFICATION_ID, { | ||
| type: "basic", | ||
| iconUrl: chrome.runtime.getURL("icons/ethui-purple-128.png"), | ||
|
naps62 marked this conversation as resolved.
Outdated
|
||
| title: "ethui Desktop Not Running", | ||
| message: | ||
| "The ethui desktop app doesn't appear to be running. Click the extension icon for more info.", | ||
| }); | ||
| } | ||
|
|
||
| export function setupConnectionStateListener() { | ||
| runtime.onMessage.addListener((message: unknown) => { | ||
| if ( | ||
| typeof message === "object" && | ||
| message !== null && | ||
| "type" in message && | ||
| (message as { type: string }).type === "get-connection-state" | ||
| ) { | ||
| return Promise.resolve({ | ||
| type: "connection-state", | ||
| state: globalConnectionState, | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| // Handle notification click - open ethui.dev | ||
| chrome.notifications.onClicked.addListener((notificationId) => { | ||
| if (notificationId === NOTIFICATION_ID) { | ||
| chrome.tabs.create({ url: "https://ethui.dev" }); | ||
| } | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <title>ethui</title> | ||
| <style> | ||
| body { | ||
| margin: 0; | ||
| width: 300px; | ||
| min-height: 150px; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div id="root"></div> | ||
| <script type="module" src="./index.tsx"></script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { Button } from "@ethui/ui/components/shadcn/button"; | ||
| import { cn } from "@ethui/ui/lib/utils"; | ||
| import React, { useEffect, useState } from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import { runtime } from "webextension-polyfill"; | ||
|
|
||
| import "./styles.css"; | ||
|
|
||
| type ConnectionState = "connected" | "disconnected" | "unknown"; | ||
|
|
||
| interface ConnectionMessage { | ||
| type: "connection-state"; | ||
| state: ConnectionState; | ||
| } | ||
|
|
||
| function App() { | ||
| const [connectionState, setConnectionState] = | ||
| useState<ConnectionState>("unknown"); | ||
|
|
||
| useEffect(() => { | ||
| runtime | ||
| .sendMessage({ type: "get-connection-state" }) | ||
| .then((response: unknown) => { | ||
| const msg = response as ConnectionMessage; | ||
| if (msg?.state) { | ||
| setConnectionState(msg.state); | ||
| } | ||
| }) | ||
| .catch(() => { | ||
| setConnectionState("unknown"); | ||
| }); | ||
|
|
||
| const listener = (message: unknown) => { | ||
| const msg = message as ConnectionMessage; | ||
| if (msg?.type === "connection-state" && msg?.state) { | ||
| setConnectionState(msg.state); | ||
| } | ||
| }; | ||
| runtime.onMessage.addListener(listener); | ||
| return () => runtime.onMessage.removeListener(listener); | ||
| }, []); | ||
|
|
||
| if (connectionState === "connected") { | ||
| return ( | ||
| <div className="p-5 text-center"> | ||
| <div className="mb-2 font-bold text-green-500 text-lg">Connected</div> | ||
| <p className="text-muted-foreground text-sm"> | ||
| ethui desktop app is running | ||
| </p> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="p-5 text-center"> | ||
| <div | ||
| className={cn( | ||
| "mb-2 font-bold text-lg", | ||
| connectionState === "disconnected" | ||
| ? "text-destructive" | ||
| : "text-muted-foreground", | ||
| )} | ||
| > | ||
| {connectionState === "disconnected" ? "Not Connected" : "Loading..."} | ||
| </div> | ||
| <p className="mb-4 text-muted-foreground text-sm"> | ||
| The ethui desktop app doesn't appear to be running. | ||
| </p> | ||
| <Button asChild> | ||
| <a href="https://ethui.dev" target="_blank" rel="noopener noreferrer"> | ||
| Get ethui Desktop | ||
| </a> | ||
| </Button> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| createRoot(document.getElementById("root") as HTMLElement).render( | ||
| <React.StrictMode> | ||
| <App /> | ||
| </React.StrictMode>, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| @import "@ethui/ui/tailwind.css"; | ||
|
|
||
| @source "../../node_modules/@ethui/ui"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.