Skip to content

Commit

Permalink
- improve: added default popup for empty/internal chrome pages (#50)
Browse files Browse the repository at this point in the history
* - improve: added default popup for empty/internal chrome pages

* - fix: lint errors
  • Loading branch information
agallardol authored Oct 19, 2023
1 parent 18bd612 commit 77f4a47
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 16 deletions.
10 changes: 3 additions & 7 deletions apps/shinkai-visor/public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
"16": "icon16.png",
"48": "icon48.png"
},
"default_popup": ""
"default_popup": "src/components/installed-popup/installed-popup.html"
},
"background": {
"service_worker": "src/service-worker/service-worker.ts"
},
"web_accessible_resources": [
{
"matches": ["https://*/*", "http://*/*", "<all_urls>"],
"resources": ["src/components/popup/popup.tsx"]
"resources": []
}
],
"commands": {
Expand All @@ -45,11 +45,7 @@
"content_scripts": [
{
"matches": ["https://*/*", "http://*/*", "<all_urls>"],
"js": ["src/components/popup/popup.tsx"]
},
{
"matches": ["https://*/*", "http://*/*", "<all_urls>"],
"js": ["src/components/action-button/action-button.tsx"]
"js": ["src/components/popup/popup.tsx", "src/components/action-button/action-button.tsx"]
}
],
"externally_connectable": {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export const CreateJob = () => {
{agents?.map((agent) => (
<SelectItem key={agent.id} value={agent.id}>
{
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(agent.full_identity_name as any)
?.subidentity_name
}
Expand Down
2 changes: 1 addition & 1 deletion apps/shinkai-visor/src/components/inbox/inbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import { FormattedMessage, useIntl } from 'react-intl';
import { useParams } from 'react-router-dom';

import { cn } from '../../helpers/cn-utils';
import { Message } from '../../message/message';
import { useAuth } from '../../store/auth/auth';
import { InboxInput } from '../inbox-input/inbox-input';
import { Message } from '../message/message';
import { ScrollArea } from '../ui/scroll-area';
import { Skeleton } from '../ui/skeleton';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>ShinkaiVisor</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="stylesheet" href="/src/styles.css" />
</head>
<body>
<div id="root" class="w-[300px] h-[450px]"></div>
<script type="module" src="/apps//shinkai-visor/src/components/installed-popup/installed-popup.tsx"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import '../../theme/styles.css';

import { Player } from '@lottiefiles/react-lottie-player';
import * as React from 'react';
import { createRoot } from 'react-dom/client';
import { FormattedMessage, IntlProvider } from 'react-intl';

import logo from '../../../src/assets/icons/visor.svg';
import InstalledPopupAnimation from '../../assets/animations/installed-popup.json';
import { srcUrlResolver } from '../../helpers/src-url-resolver';
import { langMessages, locale } from '../../lang/intl';

const InstalledPopup = () => {
return (
<div className="h-full flex flex-col justify-start">
<div className="grid place-content-center">
<img
alt="shinkai logo"
className="animate-spin-slow h-10 w-20"
data-cy="shinkai-logo"
src={srcUrlResolver(logo)}
/>
</div>
<div className="flex-1 flex flex-col space-y-3 justify-center items-center">
<div className="p-3">
<Player
autoplay
className="w-full"
loop
src={InstalledPopupAnimation}
></Player>
</div>

<p className="text-md text-center text-white" data-cy="welcome-message">
<FormattedMessage id="installed-sucessfully" />
</p>
</div>
</div>
);
};
const container = document.getElementById('root');
if (!container) {
throw new Error('container not found');
}
const root = createRoot(container);
root.render(
<React.StrictMode>
<IntlProvider locale={locale} messages={langMessages}>
<div className="w-full h-full font-inter overflow-hidden p-3 bg-secondary-600 bg-app-gradient shadow-xl">
<InstalledPopup></InstalledPopup>
</div>
</IntlProvider>
</React.StrictMode>
);
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import MarkdownPreview from '@uiw/react-markdown-preview';
import { Paperclip } from 'lucide-react';

import { Avatar, AvatarFallback, AvatarImage } from '../components/ui/avatar';
import { cn } from '../helpers/cn-utils';
import { cn } from '../../helpers/cn-utils';
import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar';

type MessageProps = {
isLocal: boolean;
Expand Down
Empty file.
2 changes: 0 additions & 2 deletions apps/shinkai-visor/src/components/popup/popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { Inboxes } from '../inboxes/inboxes';
import { SplashScreen } from '../splash-screen/splash-screen';
import Welcome from '../welcome/welcome';
import { WithNav } from '../with-nav/with-nav';
import popupStyle from './popup.css?inline';

export const Popup = ({
container,
Expand Down Expand Up @@ -133,7 +132,6 @@ const root = createRoot(container);
root.render(
<React.StrictMode>
<style>{globalStyle}</style>
<style>{popupStyle}</style>
<QueryClientProvider client={queryClient}>
<IntlProvider locale={locale} messages={langMessages}>
<div className="fixed font-inter w-[357px] h-[600px] top-32 right-16 overflow-hidden z-[1500000000]">
Expand Down
3 changes: 2 additions & 1 deletion apps/shinkai-visor/src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@
"empty-agents-title": "Ask Shinkai AI",
"empty-agents-message": "Connect your first agent to start asking Shinkai AI. Try connecting OpenAI",
"today": "Today",
"yesterday": "Yesterday"
"yesterday": "Yesterday",
"installed-sucessfully": "Shinkai Visor was installed sucessfully, navigate to a website and use the action button to start asking Shinkai AI"
}
3 changes: 2 additions & 1 deletion apps/shinkai-visor/src/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@
"empty-agents-title": "Pregunta a Shinkai AI",
"empty-agents-message": "Conecta tu primer agente para comenzar a preguntar a Shinkai AI",
"today": "Hoy",
"yesterday": "Ayer"
"yesterday": "Ayer",
"installed-sucessfully": "Shinkai Visor se instaló correctamente, navega a un sitio web y usa el botón de acción para comenzar a preguntar a Shinkai AI"
}
31 changes: 29 additions & 2 deletions apps/shinkai-visor/src/service-worker/action.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
import { ContentScriptMessageType } from "./communication/content-script-message-type";
import { sendContentScriptMessage } from "./communication/content-script-messages";

chrome.action.onClicked.addListener((tab) => {
const isChromeInternalUrl = (urlString: string): boolean => {
const url = new URL(urlString);
return url.protocol === 'chrome:';
}

const setDefaultPopup = (tabId: number, url: string): Promise<void> => {
if (!url || isChromeInternalUrl(url)) {
console.log('setting the default popup');
return chrome.action.setPopup({ popup: 'src/components/installed-popup/installed-popup.html', tabId });
} else {
console.log('setting undefined default popup');
return chrome.action.setPopup({ popup: '', tabId });
}
}

chrome.action.onClicked.addListener(async (tab) => {
console.log('actions.onClicked', tab?.id);
if (!tab?.id) {
return;
}
sendContentScriptMessage({ type: ContentScriptMessageType.TogglePopupVisibility }, tab?.id);
sendContentScriptMessage({ type: ContentScriptMessageType.TogglePopupVisibility }, tab.id);
});

chrome.tabs.onUpdated.addListener((tabId, _, tab) => {
console.log('tabs.onUpdated', tabId);
setDefaultPopup(tabId, tab.url || '');
});

chrome.tabs.onActivated.addListener(async (activeInfo) => {
const tab = await chrome.tabs.get(activeInfo.tabId);
console.log('tabs.onActivated', tab.id, tab.url);
setDefaultPopup(activeInfo.tabId, tab.url || '');
});

0 comments on commit 77f4a47

Please sign in to comment.