forked from jlalmes/trpc-chrome
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from janek26/feature/auto-connect-for-extensions
Feature/auto-connect-for-extensions
- Loading branch information
Showing
9 changed files
with
3,633 additions
and
2,353 deletions.
There are no files selected for viewing
This file contains 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 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,8 @@ | ||
import { relay } from 'trpc-browser/relay'; | ||
import { autoConnect } from 'trpc-browser/shared/chrome'; | ||
|
||
void autoConnect(chrome, (port) => { | ||
return relay(window, port); // return so it has the cleanup function for disconnect | ||
}).then(() => { | ||
return console.log('Content script loaded - bridge initialized'); | ||
}); |
This file contains 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,43 @@ | ||
import { createTRPCProxyClient } from '@trpc/client'; | ||
import type { PlasmoCSConfig } from 'plasmo'; | ||
import type { FC } from 'react'; | ||
import { windowLink } from 'trpc-browser/link'; | ||
import type { AppRouter } from '~background'; | ||
|
||
console.log('inpage script loaded'); | ||
|
||
export const config: PlasmoCSConfig = { | ||
matches: ['<all_urls>'], | ||
world: 'MAIN', | ||
}; | ||
|
||
const windowClient = createTRPCProxyClient<AppRouter>({ | ||
links: [/* 👉 */ windowLink({ window })], | ||
}); | ||
|
||
const ExtensionInpageUi: FC = () => { | ||
return ( | ||
// a button to open google in a new tab | ||
<button | ||
style={{ | ||
padding: 16, | ||
fontSize: 16, | ||
fontWeight: 'bold', | ||
borderRadius: 8, | ||
border: 'none', | ||
backgroundColor: '#000', | ||
color: '#fff', | ||
cursor: 'pointer', | ||
}} | ||
onClick={async () => { | ||
await windowClient.openNewTab.mutate({ | ||
url: 'https://google.com', | ||
}); | ||
}} | ||
> | ||
Open Google | ||
</button> | ||
); | ||
}; | ||
|
||
export default ExtensionInpageUi; |
This file contains 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 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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
{ | ||
"extends": "plasmo/templates/tsconfig.base", | ||
"exclude": ["node_modules"], | ||
"include": [".plasmo/**/*", "./**/*.ts", "./**/*.tsx"], | ||
"compilerOptions": { | ||
"strict": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"~*": ["./src/*"] | ||
} | ||
} | ||
} | ||
{ | ||
"extends": "plasmo/templates/tsconfig.base", | ||
"exclude": ["node_modules"], | ||
"include": [".plasmo/index.d.ts", ".plasmo/**/*", "./**/*.ts", "./**/*.tsx"], | ||
"compilerOptions": { | ||
"strict": true, | ||
"baseUrl": ".", | ||
"ignoreDeprecations": "5.0", | ||
"paths": { | ||
"~*": ["./src/*"] | ||
} | ||
} | ||
} |
Oops, something went wrong.