Skip to content

Commit 62f60f9

Browse files
Merge pull request #114 from ArthurLobopro/reduce-startup-time
Reduce startup time
2 parents f3b73a2 + d0c3f94 commit 62f60f9

File tree

9 files changed

+35
-9
lines changed

9 files changed

+35
-9
lines changed

.github/workflows/publish.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ jobs:
2323
- name: Install vsce
2424
run: npm i -g @vscode/vsce
2525

26+
- name: Compress JSON Files
27+
run: |
28+
chmod +x scripts/compress-json.sh
29+
./scripts/compress-json.sh
30+
2631
- name: Publish Extension on VSCODE
2732
run: vsce publish -p ${{secrets.PUBLISH_TOKEN}} --skip-duplicate
2833

l10n/bundle.l10n.pt-br.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@
6464
"Max char width": "Tamanho Máx. de Caracteres",
6565
"You must have one text selection!": "Você precisa ter algum texto selecionado!",
6666
"Maximum line width based on characters. Use value 0 for no limit.": "Tamanho máximo da linha baseado em caracteres. Use o valor 0 para não limitar.",
67-
"Invalid values will be ignored and the last valid value will be restored": "Valores inválidos irão ser ignorados e o último valor válido será restaurado"
67+
"Invalid values will be ignored and the last valid value will be restored": "Valores inválidos irão ser ignorados e o último valor válido será restaurado",
68+
"Enable Symbol Breadcrumb": "Ativar Breadcrumb de Símbolos"
6869
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "easy-codesnap",
33
"displayName": "Easy CodeSnap",
44
"description": "Take beautiful screenshots of your code 📷",
5-
"version": "1.27.0",
5+
"version": "1.27.1",
66
"l10n": "./l10n",
77
"repository": {
88
"type": "git",

scripts/compactJson.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
ROOT="$PWD"
4+
5+
# Encontra todos os arquivos .json a partir do diretório atual (inclusive em l10n)
6+
find "$ROOT" -type d -name node_modules -prune -false -o -type f -name "*.json" | while read -r file; do tmp="$(mktemp)"
7+
if jq -c . "$file" > "$tmp"; then
8+
mv "$tmp" "$file"
9+
echo "✅ Compressed: $file"
10+
else
11+
echo "❌ Error when compressing: $file"
12+
rm "$tmp"
13+
fi
14+
done

src/webview/SessionConfig.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class SessionConfig {
99
static __config: WebviewConfig = {} as any;
1010

1111
static get hasConfig() {
12-
return !!Object.entries(this.__config).length;
12+
return Object.entries(this.__config).length > 0;
1313
}
1414

1515
static get keys() {
@@ -35,10 +35,17 @@ export class SessionConfig {
3535
newConfig.shouldUpdateTitle ??= true;
3636
newConfig.watermarkText ??= newConfig.defaultWatermarkText;
3737

38+
const updatedKeys = (
39+
Object.keys(newConfig) as WebViewConfigKey[]
40+
).filter((key) => {
41+
return (
42+
!(key in this.__config) || this.__config[key] !== newConfig[key]
43+
);
44+
}) as WebViewConfigKey[];
45+
3846
const currentFileName = this.__config.templates?.fileName;
3947
this.__config = newConfig as WebviewConfig;
4048

41-
const updatedKeys = Object.keys(config) as WebViewConfigKey[];
4249
GenericUpdate(updatedKeys);
4350

4451
if (currentFileName && config.templates?.fileName !== currentFileName) {

src/webview/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { actions, type actionsKey } from "./actions";
55
import { takeSnap } from "./snap";
66
import { btnSave } from "./ui/elements";
77
import { addListeners } from "./ui/listeners";
8-
import { TranslationUpdater } from "./ui/updaters/TranslationUpdater";
98
import { vscode } from "./util";
109

1110
registerLoadSVG();
@@ -35,7 +34,6 @@ window.addEventListener(
3534
"DOMContentLoaded",
3635
() => {
3736
addListeners();
38-
TranslationUpdater();
3937
vscode.postMessage({ type: "ready" });
4038
},
4139
{ once: true },

src/webview/ui/updaters/TranslationUpdater.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { $$, t } from "../../util";
22

33
export function TranslationUpdater() {
4+
console.time("TranslationUpdater");
45
$$("[data-l10n]").forEach((el) => {
56
el.innerHTML = t(el.dataset.l10n as string).replace(
67
/`(\S[^`]{1,}\S)`/g,
@@ -10,4 +11,5 @@ export function TranslationUpdater() {
1011
},
1112
);
1213
});
14+
console.timeEnd("TranslationUpdater");
1315
}
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { updaters } from ".";
2-
import { TranslationUpdater } from "./TranslationUpdater";
32

43
export function UIUpdater() {
54
for (const updater of updaters) {
65
updater.update();
76
}
8-
9-
TranslationUpdater();
107
}

src/webview/ui/updaters/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ export const updaters = [
3333
];
3434

3535
export function GenericUpdate(keys: WebViewConfigKey[]) {
36+
console.time("GenericUpdate");
3637
updaters
3738
.filter((updater) => {
3839
return updater.dependencies.some((dependency) =>
3940
keys.includes(dependency),
4041
);
4142
})
4243
.forEach((updater) => updater.update());
44+
console.timeEnd("GenericUpdate");
4345
}
4446

4547
export function updateWindowTitle() {

0 commit comments

Comments
 (0)