Skip to content

Commit 4fdfc25

Browse files
authored
Improve UX
2 parents 8fb8c0e + 7e37e49 commit 4fdfc25

8 files changed

Lines changed: 65 additions & 38 deletions

File tree

src/commons.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,6 @@ export default class Commons {
113113
const extSettings = this.GetSettings();
114114
const cusSettings = await this.GetCustomSettings();
115115

116-
if (
117-
cusSettings.downloadPublicGist
118-
? !extSettings.gist
119-
: !cusSettings.token || !extSettings.gist
120-
) {
121-
this.webviewService.OpenLandingPage();
122-
}
123-
124116
settings.customConfig = cusSettings;
125117
settings.extConfig = extSettings;
126118
return settings;

src/service/github.oauth.service.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class GitHubOAuthService {
1414
this.app.use(express.json(), express.urlencoded({ extended: false }));
1515
}
1616

17-
public async StartProcess() {
17+
public async StartProcess(cmd?: string) {
1818
const customSettings = await state.commons.GetCustomSettings();
1919
const host = customSettings.githubEnterpriseUrl
2020
? new URL(customSettings.githubEnterpriseUrl)
@@ -60,9 +60,7 @@ export class GitHubOAuthService {
6060

6161
const gists: any[] = await this.getGists(token, user, host);
6262

63-
if (gists.length) {
64-
state.commons.webviewService.OpenGistSelectionpage(gists);
65-
}
63+
state.commons.webviewService.OpenGistSelectionpage(gists, cmd);
6664
} catch (err) {
6765
const error = new Error(err);
6866
Commons.LogException(error, state.commons.ERROR_MESSAGE, true);

src/service/webview.service.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ export class WebviewService {
157157
{
158158
find: "@RELEASE_NOTES",
159159
replace: "releaseNotes"
160+
},
161+
{
162+
find: "@CHECKED",
163+
replace: "checked"
160164
}
161165
]
162166
},
@@ -189,6 +193,10 @@ export class WebviewService {
189193
{
190194
find: "@GISTS",
191195
replace: "gists"
196+
},
197+
{
198+
find: "@SKIP",
199+
replace: "skip"
192200
}
193201
]
194202
}
@@ -306,28 +314,24 @@ export class WebviewService {
306314
}
307315

308316
public IsLandingPageEnabled(): boolean {
309-
const dontShowThisAgain = state.context.globalState.get<boolean>(
317+
return !state.context.globalState.get<boolean>(
310318
"landingPage.dontShowThisAgain"
311319
);
312-
if (dontShowThisAgain) {
313-
return false;
314-
} else {
315-
return true;
316-
}
317320
}
318321

319-
public OpenLandingPage() {
322+
public OpenLandingPage(cmd?: string) {
320323
const webview = this.webviews[0];
321324
const releaseNotes = require("../../release-notes.json");
322325
const content: string = this.GenerateContent({
323326
content: webview.htmlContent,
324327
items: webview.replaceables,
325-
releaseNotes
328+
releaseNotes,
329+
checked: this.IsLandingPageEnabled()
326330
});
327331
if (webview.webview) {
328332
webview.webview.webview.html = content;
329333
webview.webview.reveal();
330-
return webview;
334+
return webview.webview;
331335
}
332336
const landingPanel = vscode.window.createWebviewPanel(
333337
"landingPage",
@@ -341,7 +345,7 @@ export class WebviewService {
341345
landingPanel.webview.onDidReceiveMessage(async message => {
342346
switch (message.command) {
343347
case "loginWithGitHub":
344-
new GitHubOAuthService(54321).StartProcess();
348+
new GitHubOAuthService(54321).StartProcess(cmd);
345349
const customSettings = await state.commons.GetCustomSettings();
346350
const host = customSettings.githubEnterpriseUrl
347351
? new URL(customSettings.githubEnterpriseUrl)
@@ -398,17 +402,21 @@ export class WebviewService {
398402
return landingPanel;
399403
}
400404

401-
public OpenGistSelectionpage(gists: any) {
405+
public OpenGistSelectionpage(gists: any, cmd?: string) {
402406
const webview = this.webviews[2];
403407
const content: string = this.GenerateContent({
404408
content: webview.htmlContent,
405409
items: webview.replaceables,
406-
gists
410+
gists,
411+
skip:
412+
cmd !== "extension.downloadSettings"
413+
? `<a href="#" onclick="vscode.postMessage({close: true});" title="Skip (new one will be created upon first upload)" class="btn btn-primary mt-4">Skip (new one will be created upon first upload)</a>`
414+
: ""
407415
});
408416
if (webview.webview) {
409417
webview.webview.webview.html = content;
410418
webview.webview.reveal();
411-
return webview;
419+
return webview.webview;
412420
}
413421
const gistSelectionPanel = vscode.window.createWebviewPanel(
414422
"selectGist",
@@ -428,6 +436,9 @@ export class WebviewService {
428436
} else {
429437
gistSelectionPanel.dispose();
430438
}
439+
if (cmd) {
440+
vscode.commands.executeCommand(cmd);
441+
}
431442
});
432443
webview.webview = gistSelectionPanel;
433444
gistSelectionPanel.onDidDispose(() => (webview.webview = null));

src/sync.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,20 @@ export class Sync {
6969
// @ts-ignore
7070
const args = arguments;
7171
let github: GitHubService = null;
72-
let localConfig = new LocalConfig();
72+
const localConfig = await state.commons.InitalizeSettings();
73+
74+
if (!localConfig.customConfig.token) {
75+
state.commons.webviewService.OpenLandingPage("extension.updateSettings");
76+
return;
77+
}
78+
7379
const allSettingFiles: File[] = [];
7480
let uploadedExtensions: ExtensionInformation[] = [];
7581
const ignoredExtensions: ExtensionInformation[] = [];
7682
const dateNow = new Date();
7783
await state.commons.HandleStopWatching();
7884

7985
try {
80-
localConfig = await state.commons.InitalizeSettings();
8186
localConfig.publicGist = false;
8287
if (args.length > 0) {
8388
if (args[0] === "publicGIST") {
@@ -434,11 +439,22 @@ export class Sync {
434439
* Download setting from github gist
435440
*/
436441
public async download(): Promise<void> {
437-
let localSettings: LocalConfig = new LocalConfig();
442+
const localSettings: LocalConfig = await state.commons.InitalizeSettings();
443+
444+
if (
445+
localSettings.customConfig.downloadPublicGist
446+
? !localSettings.extConfig.gist
447+
: !localSettings.customConfig.token || !localSettings.extConfig.gist
448+
) {
449+
state.commons.webviewService.OpenLandingPage(
450+
"extension.downloadSettings"
451+
);
452+
return;
453+
}
454+
438455
await state.commons.HandleStopWatching();
439456

440457
try {
441-
localSettings = await state.commons.InitalizeSettings();
442458
await StartDownload(localSettings.extConfig, localSettings.customConfig);
443459
} catch (err) {
444460
Commons.LogException(err, state.commons.ERROR_MESSAGE, true);

ui/gist-selection/gist-selection.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ <h3 class="mx-auto mt-2 mb-3 text-white-50a">
3030
Select Your Existing Gist
3131
</h3>
3232
<div id="selectionContainer" class="list-group mx-auto text-left"></div>
33-
<a
34-
href="#"
35-
onclick="vscode.postMessage({close: true});"
36-
title="Skip (new one will be created automatically)"
37-
class="btn btn-primary mt-4"
38-
>Skip (new one will be created automatically)</a
39-
>
33+
<div id="skipContainer"></div>
4034
</div>
4135
<div
4236
class="modal fade"
@@ -90,6 +84,7 @@ <h5 class="modal-title" id="exampleModalCenterTitle">
9084
<font-injector></font-injector>
9185
<script defer>
9286
const gists = JSON.parse(`@GISTS`);
87+
const skip = @SKIP;
9388
</script>
9489
<script defer src="@PWD/ui/gist-selection/gist-selection.js"></script>
9590
</body>

ui/gist-selection/gist-selection.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
// @ts-nocheck
22

3+
function appendHTML(parent, html) {
4+
var div = document.createElement("div");
5+
div.innerHTML = html;
6+
while (div.children.length > 0) {
7+
parent.appendChild(div.children[0]);
8+
}
9+
div.remove();
10+
}
11+
312
const vscode = acquireVsCodeApi();
413

514
/* https://stackoverflow.com/questions/3177836/how-to-format-time-since-xxx-e-g-4-minutes-ago-similar-to-stack-exchange-site */
@@ -52,6 +61,9 @@ document
5261
document.body.className.includes("vscode-dark") ? "bg-dark" : "bg-light"
5362
);
5463

64+
const skipContainer = document.querySelector("#skipContainer");
65+
appendHTML(skipContainer, skip);
66+
5567
const selectionTemplate = `
5668
<button type="button" onclick="saveGistId('@id')" class="list-group-item list-group-item-action">@description (@id) – Updated @timestamp ago</button>`;
5769

ui/landing-page/landing-page.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ <h3 class="mx-auto mb-3 text-white-50a">
134134
>Questions & Issues</a
135135
>
136136
<br />
137-
<a href="https://github.com/shanalikhan/code-settings-sync/blob/master/CONTRIBUTING.md"
137+
<a
138+
href="https://github.com/shanalikhan/code-settings-sync/blob/master/CONTRIBUTING.md"
138139
>Contribute</a
139140
>
140141
<br />
@@ -154,7 +155,6 @@ <h3 class="mb-3">Sponsors</h3>
154155
class="custom-control-input checkbox"
155156
type="checkbox"
156157
id="customCheck1"
157-
checked="true"
158158
onclick="sendCommand('dontShowThisAgain', !this.checked)"
159159
/>
160160
<label for="customCheck1" class="custom-control-label">
@@ -167,6 +167,7 @@ <h3 class="mb-3">Sponsors</h3>
167167
<font-injector></font-injector>
168168
<script defer>
169169
const releaseNotes = JSON.parse(`@RELEASE_NOTES`);
170+
const checked = "@CHECKED";
170171
</script>
171172
<script defer src="@PWD/ui/landing-page/landing-page.js"></script>
172173
</body>

ui/landing-page/landing-page.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ releaseNotes.changes.forEach(change => {
3636

3737
const currentVersionElement = document.querySelector("#current-version");
3838
currentVersionElement.innerHTML = releaseNotes.currentVersion;
39+
40+
document.querySelector("#customCheck1").checked = checked === "true";

0 commit comments

Comments
 (0)