Skip to content

Commit 52e6c57

Browse files
authored
Merge pull request #6082 from ethereum/logingithub
Logingithub
2 parents 5886d46 + 55c37d5 commit 52e6c57

File tree

30 files changed

+560
-47
lines changed

30 files changed

+560
-47
lines changed

apps/remix-ide/src/app.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import { FoundryHandleDesktop } from './app/plugins/electron/foundryPlugin'
6767
import { HardhatHandle } from './app/files/hardhat-handle'
6868
import { HardhatHandleDesktop } from './app/plugins/electron/hardhatPlugin'
6969
import { circomPlugin } from './app/plugins/electron/circomElectronPlugin'
70+
import { GitHubAuthHandler } from './app/plugins/electron/gitHubAuthHandler'
7071
import { GitPlugin } from './app/plugins/git'
7172
import { Matomo } from './app/plugins/matomo'
7273
import { WalletConnect } from './app/plugins/walletconnect'
@@ -469,6 +470,8 @@ class AppComponent {
469470
this.engine.register([appUpdater])
470471
const remixAIDesktop = new remixAIDesktopPlugin()
471472
this.engine.register([remixAIDesktop])
473+
const githubAuthHandler = new GitHubAuthHandler()
474+
this.engine.register([githubAuthHandler])
472475
}
473476

474477
const compilerloader = isElectron() ? new compilerLoaderPluginDesktop() : new compilerLoaderPlugin()
@@ -611,7 +614,7 @@ class AppComponent {
611614
await this.appManager.activatePlugin(['solidity-script', 'remix-templates'])
612615

613616
if (isElectron()) {
614-
await this.appManager.activatePlugin(['isogit', 'electronconfig', 'electronTemplates', 'xterm', 'ripgrep', 'appUpdater', 'slither', 'foundry', 'hardhat', 'circom']) // 'remixAID'
617+
await this.appManager.activatePlugin(['isogit', 'electronconfig', 'electronTemplates', 'xterm', 'ripgrep', 'appUpdater', 'slither', 'foundry', 'hardhat', 'circom', 'githubAuthHandler']) // 'remixAID'
615618
}
616619

617620
this.appManager.on(
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import React, { useEffect, useRef } from 'react'
2+
import axios from 'axios'
3+
import '../components/styles/preload.css'
4+
import { endpointUrls } from "@remix-endpoints-helper"
5+
6+
const extractCode = () => {
7+
const searchParams = new URLSearchParams(window.location.search)
8+
if (searchParams.get('code')) return searchParams.get('code')
9+
10+
// If not found in search, check the hash
11+
const hashParams = new URLSearchParams(window.location.hash.slice(1)) // strip #
12+
return hashParams.get('code')
13+
}
14+
15+
const logo = (
16+
<svg id="Ebene_2" data-name="Ebene 2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 105 100">
17+
<path d="M91.84,35a.09.09,0,0,1-.1-.07,41,41,0,0,0-79.48,0,.09.09,0,0,1-.1.07C9.45,35,1,35.35,1,42.53c0,8.56,1,16,6,20.32,2.16,1.85,5.81,2.3,9.27,2.22a44.4,44.4,0,0,0,6.45-.68.09.09,0,0,0,.06-.15A34.81,34.81,0,0,1,17,45c0-.1,0-.21,0-.31a35,35,0,0,1,70,0c0,.1,0,.21,0,.31a34.81,34.81,0,0,1-5.78,19.24.09.09,0,0,0,.06.15,44.4,44.4,0,0,0,6.45.68c3.46.08,7.11-.37,9.27-2.22,5-4.27,6-11.76,6-20.32C103,35.35,94.55,35,91.84,35Z" />
18+
<path d="M52,74,25.4,65.13a.1.1,0,0,0-.1.17L51.93,91.93a.1.1,0,0,0,.14,0L78.7,65.3a.1.1,0,0,0-.1-.17L52,74A.06.06,0,0,1,52,74Z" />
19+
<path d="M75.68,46.9,82,45a.09.09,0,0,0,.08-.09,29.91,29.91,0,0,0-.87-6.94.11.11,0,0,0-.09-.08l-6.43-.58a.1.1,0,0,1-.06-.18l4.78-4.18a.13.13,0,0,0,0-.12,30.19,30.19,0,0,0-3.65-6.07.09.09,0,0,0-.11,0l-5.91,2a.1.1,0,0,1-.12-.14L72.19,23a.11.11,0,0,0,0-.12,29.86,29.86,0,0,0-5.84-4.13.09.09,0,0,0-.11,0l-4.47,4.13a.1.1,0,0,1-.17-.07l.09-6a.1.1,0,0,0-.07-.1,30.54,30.54,0,0,0-7-1.47.1.1,0,0,0-.1.07l-2.38,5.54a.1.1,0,0,1-.18,0l-2.37-5.54a.11.11,0,0,0-.11-.06,30,30,0,0,0-7,1.48.12.12,0,0,0-.07.1l.08,6.05a.09.09,0,0,1-.16.07L37.8,18.76a.11.11,0,0,0-.12,0,29.75,29.75,0,0,0-5.83,4.13.11.11,0,0,0,0,.12l2.59,5.6a.11.11,0,0,1-.13.14l-5.9-2a.11.11,0,0,0-.12,0,30.23,30.23,0,0,0-3.62,6.08.11.11,0,0,0,0,.12l4.79,4.19a.1.1,0,0,1-.06.17L23,37.91a.1.1,0,0,0-.09.07A29.9,29.9,0,0,0,22,44.92a.1.1,0,0,0,.07.1L28.4,47a.1.1,0,0,1,0,.18l-5.84,3.26a.16.16,0,0,0,0,.11,30.17,30.17,0,0,0,2.1,6.76c.32.71.67,1.4,1,2.08a.1.1,0,0,0,.06,0L52,68.16H52l26.34-8.78a.1.1,0,0,0,.06-.05,30.48,30.48,0,0,0,3.11-8.88.1.1,0,0,0-.05-.11l-5.83-3.26A.1.1,0,0,1,75.68,46.9Z" />
20+
</svg>
21+
)
22+
23+
export const GitHubPopupCallback = () => {
24+
const hasRun = useRef(false)
25+
26+
const exchangeToken = async () => {
27+
28+
const code = extractCode()
29+
window.history.replaceState({}, document.title, window.location.pathname)
30+
31+
if (!code) {
32+
console.warn('[GitHubPopupCallback] Missing code', { code })
33+
window.opener?.postMessage({ type: 'GITHUB_AUTH_FAILURE', error: 'missing code' }, window.location.origin)
34+
return
35+
}
36+
37+
try {
38+
const { data } = await axios.post(`${endpointUrls.gitHubLoginProxy}/login/oauth/access_token?_=${Date.now()}`, {
39+
code,
40+
redirect_uri: window.location.origin + '/auth/github/callback'
41+
}, {
42+
headers: {
43+
'Content-Type': 'application/json',
44+
Accept: 'application/json'
45+
}
46+
})
47+
48+
if (data.access_token) {
49+
window.opener?.postMessage({ type: 'GITHUB_AUTH_SUCCESS', token: data.access_token }, window.location.origin)
50+
} else {
51+
console.log('[GitHubPopupCallback] Posting failure message')
52+
window.opener?.postMessage({ type: 'GITHUB_AUTH_FAILURE', error: 'no access token' }, window.location.origin)
53+
}
54+
} catch (error) {
55+
console.error('[GitHubPopupCallback] Token exchange error:', error)
56+
window.opener?.postMessage({ type: 'GITHUB_AUTH_FAILURE', error: error instanceof Error ? error.message : String(error), code }, window.location.origin)
57+
}
58+
}
59+
60+
useEffect(() => {
61+
if (!hasRun.current) {
62+
hasRun.current = true
63+
exchangeToken()
64+
}
65+
}, [])
66+
67+
return (
68+
<>
69+
<div className="preload-container">
70+
<div className="preload-logo pb-4">
71+
{logo}
72+
<div>
73+
<div className='text-center'>
74+
<i className="fas fa-spinner fa-spin fa-2x"></i>
75+
</div>
76+
</div>
77+
</div>
78+
</div>
79+
</>
80+
)
81+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ElectronPlugin } from '@remixproject/engine-electron';
2+
3+
export class GitHubAuthHandler extends ElectronPlugin {
4+
constructor() {
5+
super({
6+
displayName: 'githubAuthHandler',
7+
name: 'githubAuthHandler',
8+
description: 'githubAuthHandler',
9+
})
10+
this.methods = []
11+
}
12+
13+
}

apps/remix-ide/src/app/tabs/theme-module.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ export class ThemeModule extends Plugin {
5454
themes.map((theme) => {
5555
this.themes[theme.name.toLocaleLowerCase()] = {
5656
...theme,
57-
url: isElectron() ? theme.url : window.location.origin + (window.location.pathname.startsWith('/address/') || window.location.pathname.endsWith('.sol') ? '/' : window.location.pathname) + theme.url
57+
url: isElectron()
58+
? theme.url
59+
: window.location.pathname.startsWith('/auth')
60+
? window.location.origin + '/' + theme.url
61+
: window.location.origin + (window.location.pathname.startsWith('/address/') || window.location.pathname.endsWith('.sol') ? '/' : window.location.pathname) + theme.url
5862
}
5963
})
6064
this._paq = _paq
@@ -123,6 +127,8 @@ export class ThemeModule extends Plugin {
123127
if (!this.forced) this._deps.config.set('settings/theme', next)
124128
document.getElementById('theme-link') ? document.getElementById('theme-link').remove() : null
125129

130+
131+
126132
const theme = document.createElement('link')
127133
theme.setAttribute('rel', 'stylesheet')
128134
theme.setAttribute('href', nextTheme.url)

apps/remix-ide/src/index.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,33 @@ import React from 'react'
33
import './index.css'
44
import { ThemeModule } from './app/tabs/theme-module'
55
import { Preload } from './app/components/preload'
6+
import { BrowserRouter, Routes, Route } from 'react-router-dom'
7+
import { GitHubPopupCallback } from './app/pages/GitHubPopupCallback'
68
import Config from './config'
79
import { Registry } from '@remix-project/remix-lib'
810
import { Storage } from '@remix-project/remix-lib'
911

1012
import { createRoot } from 'react-dom/client'
1113

12-
;(async function () {
14+
; (async function () {
1315
try {
1416
const configStorage = new Storage('config-v0.8:')
1517
const config = new Config(configStorage)
1618
Registry.getInstance().put({ api: config, name: 'config' })
17-
} catch (e) {}
19+
} catch (e) { }
1820
const theme = new ThemeModule()
1921
theme.initTheme()
2022

2123
const container = document.getElementById('root');
2224
const root = createRoot(container)
2325
if (container) {
24-
root.render(<Preload root={root} />);
26+
root.render(
27+
<BrowserRouter>
28+
<Routes>
29+
<Route path="/auth/github/callback" element={<GitHubPopupCallback />} />
30+
<Route path="*" element={<Preload root={root} />} />
31+
</Routes>
32+
</BrowserRouter>
33+
)
2534
}
2635
})()

apps/remix-ide/src/remixAppManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ let requiredModules = [
9191
'walletconnect',
9292
'popupPanel',
9393
'remixAI',
94-
'remixAID'
94+
'remixAID',
95+
'githubAuthHandler'
9596
]
9697

9798
// dependentModules shouldn't be manually activated (e.g hardhat is activated by remixd)

apps/remix-ide/webpack.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const fs = require('fs')
77
const TerserPlugin = require('terser-webpack-plugin')
88
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
99
const path = require('path')
10+
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
1011

1112
const versionData = {
1213
version: version,
@@ -126,6 +127,7 @@ module.exports = composePlugins(withNx(), withReact(), (config) => {
126127
url: ['url', 'URL'],
127128
process: 'process/browser'
128129
})
130+
//,new BundleAnalyzerPlugin()
129131
)
130132

131133
// set the define plugin to load the WALLET_CONNECT_PROJECT_ID

apps/remixdesktop/Info.plist

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
3+
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
4+
<plist version="1.0">
5+
<dict>
6+
<key>CFBundleURLTypes</key>
7+
<array>
8+
<dict>
9+
<key>CFBundleURLName</key>
10+
<string>Remix URL Scheme</string>
11+
<key>CFBundleURLSchemes</key>
12+
<array>
13+
<string>remix</string>
14+
</array>
15+
</dict>
16+
</array>
17+
</dict>
18+
</plist>

apps/remixdesktop/insiders.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"hardenedRuntime": true,
2727
"gatekeeperAssess": false,
2828
"entitlements": "entitlements.mac.plist",
29-
"entitlementsInherit": "entitlements.mac.plist"
29+
"entitlementsInherit": "entitlements.mac.plist",
30+
"extendInfo": "Info.plist"
3031
},
3132
"dmg": {
3233
"writeUpdateInfo": true,
@@ -58,5 +59,11 @@
5859
},
5960
"directories": {
6061
"output": "release"
62+
},
63+
"protocols": [
64+
{
65+
"name": "Remix",
66+
"schemes": ["remix"]
6167
}
68+
]
6269
}

apps/remixdesktop/src/engine.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { FoundryPlugin } from './plugins/foundryPlugin';
1616
import { HardhatPlugin } from './plugins/hardhatPlugin';
1717
import { CircomElectronPlugin } from './plugins/circomElectronBasePlugin';
1818
import { isE2E } from './main';
19+
import { GitHubAuthHandler } from './plugins/githubAuthHandler';
1920

2021
const engine = new Engine()
2122
const appManager = new PluginManager()
@@ -32,6 +33,7 @@ const foundryPlugin = new FoundryPlugin()
3233
const hardhatPlugin = new HardhatPlugin()
3334
const remixAIDesktopPlugin = new RemixAIDesktopPlugin()
3435
const circomPlugin = new CircomElectronPlugin()
36+
export const githubAuthHandlerPlugin = new GitHubAuthHandler()
3537

3638
engine.register(appManager)
3739
engine.register(fsPlugin)
@@ -47,6 +49,7 @@ engine.register(appUpdaterPlugin)
4749
engine.register(hardhatPlugin)
4850
engine.register(remixAIDesktopPlugin)
4951
engine.register(circomPlugin)
52+
engine.register(githubAuthHandlerPlugin)
5053

5154
appManager.activatePlugin('electronconfig')
5255
appManager.activatePlugin('fs')
@@ -88,7 +91,6 @@ ipcMain.handle('getWebContentsID', (event, message) => {
8891
return event.sender.id
8992
})
9093

91-
9294
app.on('before-quit', async (event) => {
9395
await appManager.call('fs', 'removeCloseListener')
9496
await appManager.call('fs', 'closeWatch')

0 commit comments

Comments
 (0)