Skip to content

Commit 4d8224c

Browse files
committed
Add copy link button in external auth popup
1 parent 617c123 commit 4d8224c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

emailproxy.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,20 @@
9999
APP_PACKAGE).expanduser() # Windows startup .cmd file location
100100
AUTOSTART_FILE_PATH = pathlib.Path('~/.config/autostart/%s.desktop' % APP_PACKAGE).expanduser() # XDG Autostart file
101101

102-
EXTERNAL_AUTH_HTML = '''<html><style type="text/css">body{margin:20px auto;line-height:1.3;font-family:sans-serif;
103-
font-size:16px;color:#444;padding:0 24px}</style>
102+
EXTERNAL_AUTH_HTML = '''<html><head><script type="text/javascript">function copyLink(targetLink){
103+
var copySource=document.createElement('textarea');copySource.value=targetLink;copySource.style.position='absolute';
104+
copySource.style.left='-9999px';document.body.appendChild(copySource);copySource.select();
105+
document.execCommand('copy');document.body.removeChild(copySource);
106+
document.getElementById('copy').innerText='✔'}</script><style type="text/css">body{margin:20px auto;line-height:1.3;
107+
font-family:sans-serif;font-size:16px;color:#444;padding:0 24px}</style></head><body>
104108
<h3 style="margin:0.3em 0;">Login authorisation request for %s</h3>
105109
<p style="margin-top:0">Click the following link to open your browser and approve the request:</p>
106-
<p><a href="%s" target="_blank" style="word-wrap:break-word;word-break:break-all">%s</a></p>
110+
<p><a href="%s" target="_blank" style="word-wrap:break-word;word-break:break-all">%s</a>
111+
<a id="copy" onclick="copyLink('%s')" style="margin-left:0.5em;margin-top:0.1em;font-weight:bold;font-size:150%%;
112+
text-decoration:none;cursor:pointer;float:right" title="Copy link">⧉</a></p>
107113
<p style="margin-top:2em">After logging in and successfully authorising your account, paste and submit the
108-
resulting URL from the browser's address bar using the box below to allow the %s script to transparently
109-
handle login requests on your behalf in future.</p>
114+
resulting URL from the browser's address bar using the box at the bottom of this page to allow the %s script to
115+
transparently handle login requests on your behalf in future.</p>
110116
<p>Note that your browser may show a navigation error (e.g., <em>"localhost refused to connect"</em>) after
111117
successfully logging in, but the final URL is the only important part, and as long as this begins with the
112118
correct redirection URI and contains a valid authorisation code your email client's request will succeed.''' + (
@@ -117,7 +123,7 @@
117123
document.auth.submit.value='Submitting...'; document.auth.submit.disabled=true; return false">
118124
<div style="display:flex;flex-direction:row;margin-top:4em"><label for="url">Authorisation success URL:
119125
</label><input type="text" name="url" id="url" style="flex:1;margin:0 5px;width:65%%"><input type="submit"
120-
id="submit" value="Submit"></div></form></html>'''
126+
id="submit" value="Submit"></div></form></body></html>'''
121127

122128
EXITING = False # used to check whether to restart failed threads - is set to True if the user has requested to exit
123129

@@ -1712,7 +1718,7 @@ def create_authorisation_window(self, request):
17121718
window_title = 'Authorise your account: %s' % request['username']
17131719
if self.args.external_auth:
17141720
auth_page = EXTERNAL_AUTH_HTML % (request['username'], request['permission_url'], request['permission_url'],
1715-
APP_NAME, request['redirect_uri'])
1721+
request['permission_url'], APP_NAME, request['redirect_uri'])
17161722
authorisation_window = webview.create_window(window_title, html=auth_page, on_top=True, text_select=True)
17171723
else:
17181724
authorisation_window = webview.create_window(window_title, request['permission_url'], on_top=True)

0 commit comments

Comments
 (0)