Skip to content

Commit

Permalink
Merge pull request #7 from hadrrb/save-lang-height
Browse files Browse the repository at this point in the history
Save last lang and height
  • Loading branch information
hadrrb authored Feb 23, 2022
2 parents 360a278 + 766b8fa commit 38b8692
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to the "wordle" extension will be documented in this file.

## 1.0.3

- Ability to change height in settings as well
- The last chosen language and height will be saved from now on

## 1.0.2

- Changed English Wordle to <a href="https://mikhad.github.io/wordle/#daily">Wordle+</a> because the original cannot be loaded as an iframe because of X-Frame-Options policy.
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-wordle",
"displayName": "Wordle for VSCode",
"description": "Play Wordle in your VSCode",
"version": "1.0.2",
"version": "1.0.3",
"keywords": ["wordle", "word game", "game"],
"publisher": "RamziHadrich",
"author": {
Expand Down Expand Up @@ -54,6 +54,11 @@
"type": "string",
"description": "Wordle width (in px or in %)",
"default": "100%"
},
"wordle.height": {
"type": "number",
"description": "Wordle height (in px)",
"default": 600
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export function activate(context: vscode.ExtensionContext) {

vscode.workspace.onDidChangeConfiguration((e) => {
if(e.affectsConfiguration("wordle")){
let lang = vscode.workspace.getConfiguration("wordle").get<string>("defaultLang");
wordleProvider.setLang(lang);
wordleProvider.reload();
}});

context.subscriptions.push(wordle);
Expand Down
7 changes: 2 additions & 5 deletions src/pick_language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ export async function pick_language(wordleProvider: WordleProvider) {
title: "Wordle Language"
});
if(lang){
let link = wordles[lang];
if (link){
wordleProvider.changeLanguage(link);
}

vscode.workspace.getConfiguration("wordle").update("defaultLang", lang, true);
wordleProvider.reload();
}

}
26 changes: 12 additions & 14 deletions src/wordle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { pick_language, wordles } from './pick_language';
export class WordleProvider implements vscode.WebviewViewProvider {

private _view?: vscode.WebviewView;
private height: number = 600;
private wordleLink!: string;

constructor(){
let lang = vscode.workspace.getConfiguration("wordle").get<string>("defaultLang");
Expand All @@ -14,12 +12,9 @@ export class WordleProvider implements vscode.WebviewViewProvider {

public setLang(lang: string | undefined){
if(lang){
this.wordleLink = wordles[lang];
return wordles[lang];
} else {
this.wordleLink = wordles["English"];
}
if (this._view) {
this._view.webview.html = this._getHtmlForWebview();
return wordles["English"];
}
}

Expand All @@ -37,6 +32,8 @@ export class WordleProvider implements vscode.WebviewViewProvider {
}

private _getHtmlForWebview() {
let link = this.setLang(vscode.workspace.getConfiguration("wordle").get<string>("defaultLang"));
let height = vscode.workspace.getConfiguration("wordle").get<string>("height");
let width = vscode.workspace.getConfiguration("wordle").get<string>("width");
return `<!DOCTYPE html>
<html>
Expand All @@ -47,22 +44,23 @@ export class WordleProvider implements vscode.WebviewViewProvider {
</head>
<body>
<iframe src="${this.wordleLink}" height="${this.height}" width="${width}" scrolling="no" frameborder="0" wmode="transparent"></iframe>
<iframe src="${link}" height="${height}" width="${width}" scrolling="no" frameborder="0" wmode="transparent"></iframe>
</body>
</html>`;
}

public changeLanguage(link: string){
this.wordleLink = link;
public reload(){
if (this._view) {
this._view.webview.html = this._getHtmlForWebview();
}
}

public changeHeight(value: number){
this.height = this.height + value;
if (this._view) {
this._view.webview.html = this._getHtmlForWebview();
public changeHeight(change: number){
let height = vscode.workspace.getConfiguration("wordle").get<number>("height");
if(height){
height = height + change;
vscode.workspace.getConfiguration("wordle").update("height", height, true);
this.reload();
}
}

Expand Down

0 comments on commit 38b8692

Please sign in to comment.