Skip to content

Commit

Permalink
feat: add copy button. Ref #2
Browse files Browse the repository at this point in the history
  • Loading branch information
maelgangloff committed Apr 28, 2023
1 parent 0d8a11e commit b36703b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ ipcMain.on('school-search', async (event, schoolName) => {
dialog.showErrorBox('Établissement introuvable', "Nous avons cherché partout, mais nous n'avons pas trouvé cet établissement...")
return mainWindow.reload()
}
mainWindow.webContents.send('school-list', schools)
if (schools.length === 1) {
oidClient = await Skolengo.getOIDClient(schools[0])
const authURL = oidClient.authorizationUrl()
mainWindow.loadURL(authURL)
} else mainWindow.webContents.send('school-list', schools)
} catch (e) {
dialog.showErrorBox('Erreur', 'Une erreur est survenue, veuillez réessayer...')
return mainWindow.reload()
Expand Down
22 changes: 15 additions & 7 deletions src/success.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@
<h1>💖 Félicitations !</h1>
<p><b>🚨 ATTENTION: Ne communiquez jamais vos jetons à un tiers. Ils vous sont strictement personnels. Si vous pensez que vos jetons ont été dérobés, révoquez-les immédiatement.</b></p>
<p>Vous pouvez utiliser ces informations d'authentification avec la librairie <a href="https://github.com/maelgangloff/scolengo-api">scolengo-api</a>.</p>
<a class="dllink">📁 Télecharger le fichier de configuration</a>
<a class="dllink">📁 Télecharger le fichier de configuration</a><br>
<button id="btn-copy" class="school-select">Copier le JSON</button>
<pre class="scroll_enabled">
<code id="auth"></code>
</pre>
<script>
const auth = document.getElementById('auth')
const dllink = document.querySelector('.dllink');
window.electronAPI.sendToken((event, token) => {
auth.innerHTML = JSON.stringify(token, null, 2)
dllink.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(token, null, 2)));
dllink.setAttribute('download', "config.json");
})
</script>
window.electronAPI.sendToken((event, token) => {
const formattedJSON = JSON.stringify(token, null, 2)
auth.innerHTML = formattedJSON
dllink.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(formattedJSON));
dllink.setAttribute('download', "config.json");

const btnCopy = document.getElementById('btn-copy')
btnCopy.addEventListener('click', () => {
btnCopy.hidden = true
navigator.clipboard.writeText(formattedJSON)
})
})
</script>
</body>
</html>

0 comments on commit b36703b

Please # to comment.