Skip to content

Commit 1c5f769

Browse files
committed
fix: adding a pat account
1 parent 0f20193 commit 1c5f769

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

_locales/en/messages.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@
121121
"account_enterprise": {
122122
"message": "GitHub Enterprise"
123123
},
124-
"account_github_light": {
124+
"account_github-light": {
125125
"message": "GitHub (no private repos)"
126126
},
127-
"account_github_user": {
128-
"message": "GitHub (User Access Token)"
127+
"account_github-user": {
128+
"message": "GitHub (Personal access token)"
129129
},
130130
"addAccount": {
131131
"message": "Add account"
@@ -143,6 +143,9 @@
143143
"message": "Instance URL"
144144
},
145145
"userToken": {
146-
"message": "User Access Token"
146+
"message": "Personal access token"
147+
},
148+
"generate_token": {
149+
"message": "Create personal access token"
147150
}
148151
}

options.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
<form id="login">
1616
<select class="browser-style">
1717
<option value="github" data-l10n-id="account_github" disabled>GitHub</option>
18-
<option value="github-light" data-l10n-id="account_github_light" disabled>GitHub (no private repos)</option>
18+
<option value="github-light" data-l10n-id="account_github-light" disabled>GitHub (no private repos)</option>
1919
<option value="enterprise" data-l10n-id="account_enterprise">GitHub Enterprise</option>
20-
<option value="github-user" data-l10n-id="account_github_user" selected>GitHub (User Access Token)</option><!-- default because OAuth flow is broken -->
20+
<option value="github-user" data-l10n-id="account_github-user" selected>GitHub (Personal access token)</option><!-- default because OAuth flow is broken -->
2121
</select>
2222
<fieldset name="enterprise" hidden>
2323
<p class="browser-style">
@@ -35,8 +35,9 @@
3535
</fieldset>
3636
<fieldset name="github-user" hidden>
3737
<p class="browser-style">
38-
<label for="github-user-token" data-l10n-id="userToken">User Access Token</label>
39-
<input type="password" id="github-user-token" name="token" disabled>
38+
<label for="github-user-token" data-l10n-id="userToken">Personal access token</label>
39+
<input type="password" id="github-user-token" class="browser-style" name="token" disabled>
40+
<a href="https://github.com/settings/tokens/new" data-l10n-id="generate_token" rel="noopener" target="_blank">Create personal access token</a>
4041
</p>
4142
</fieldset>
4243
<button class="browser-style" type="submit" data-l10n-id="addAccount">Add account</button>

scripts/background.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,29 @@ const init = async () => {
178178
if(!count) {
179179
needsAuth();
180180
}
181-
//TODO only here should we have an online check?
182181
else {
183182
await setupNotificationWorkers();
184183
}
185184
};
186185

187-
if(navigator.onLine) {
188-
init().catch(console.error);
189-
}
190-
else {
191-
window.addEventListener("online", () => {
192-
init().catch(console.error);
193-
}, {
194-
passive: true,
195-
capture: false,
196-
once: true
197-
});
198-
}
186+
window.requestIdleCallback(async () => {
187+
if(navigator.onLine) {
188+
await init().catch(console.error);
189+
}
190+
else {
191+
// If we can't retrieve the accounts, wait for internet and try again.
192+
const records = await manager.getRecords().catch(() => [ 0, 1 ]);
193+
if(!records.length) {
194+
needsAuth();
195+
}
196+
else {
197+
window.addEventListener("online", () => {
198+
init().catch(console.error);
199+
}, {
200+
passive: true,
201+
capture: false,
202+
once: true
203+
});
204+
}
205+
}
206+
});

scripts/options.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class AccountManager extends window.StorageManager {
9494
browser.runtime.sendMessage({
9595
topic: "login",
9696
type: typeForm.value,
97-
details: this.getDetails()
97+
details: this.getDetails(typeForm.value)
9898
}).catch((error) => {
9999
this.showError(error.message);
100100
});
@@ -128,8 +128,8 @@ class AccountManager extends window.StorageManager {
128128
return this.list.querySelector(`[data-id="${id}"]`);
129129
}
130130

131-
getDetails() {
132-
const inputs = this.form.querySelectorAll('fieldset[nane="enterprise"] input'),
131+
getDetails(type) {
132+
const inputs = this.form.querySelectorAll(`fieldset[name="${type}"] input`),
133133
details = {};
134134
for(const input of inputs) {
135135
if(input.value && !input.disabled) {

0 commit comments

Comments
 (0)