Skip to content

Commit

Permalink
Fix bug where project creation pages always start in light mode
Browse files Browse the repository at this point in the history
  • Loading branch information
will-v-pi committed Jan 15, 2025
1 parent 11f9cdc commit 20bd425
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/webview/newMicroPythonProjectPanel.mts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,12 @@ print("Finished.")\r\n`;
// Restrict the webview to only load specific scripts
const nonce = getNonce();

const defaultTheme =
window.activeColorTheme.kind === ColorThemeKind.Dark ||
window.activeColorTheme.kind === ColorThemeKind.HighContrast
? "dark"
: "light";

return `<!DOCTYPE html>
<html lang="en">
<head>
Expand All @@ -492,9 +498,12 @@ print("Finished.")\r\n`;
tailwind.config = {
darkMode: 'class',
};
localStorage.theme = "${defaultTheme}";
</script>
</head>
<body class="scroll-smooth w-screen">
<body class="scroll-smooth w-screen${defaultTheme === "dark" ? " dark" : ""}">
<div id="above-nav" class="container max-w-6xl mx-auto flex justify-between items-center w-full sticky top-0 z-10 pl-5 h-5">
</div>
<div id="nav-overlay" class="overlay hidden md:hidden inset-y-0 right-0 w-auto z-50 overflow-y-auto ease-out bg-slate-400 dark:bg-slate-800 drop-shadow-lg">
Expand Down
13 changes: 11 additions & 2 deletions src/webview/newProjectPanel.mts
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,13 @@ export class NewProjectPanel {
)
);

const defaultTheme =
window.activeColorTheme.kind === ColorThemeKind.Dark ||
window.activeColorTheme.kind === ColorThemeKind.HighContrast
? "dark"
: "light";
const riscvDefaultSvgUri = defaultTheme === "dark" ? riscvWhiteSvgUri : riscvBlackSvgUri;

this._versionBundlesLoader = new VersionBundlesLoader(this._extensionUri);

// construct auxiliary html
Expand Down Expand Up @@ -1664,14 +1671,16 @@ export class NewProjectPanel {
var doProjectImport = ${this._isProjectImport};
var forceCreateFromExample = ${forceCreateFromExample};
localStorage.theme = "${defaultTheme}";
// riscv logos
const riscvWhiteSvgUri = "${riscvWhiteSvgUri.toString()}";
const riscvWhiteYellowSvgUri = "${riscvWhiteYellowSvgUri.toString()}";
const riscvBlackSvgUri = "${riscvBlackSvgUri.toString()}";
const riscvColorSvgUri = "${riscvColorSvgUri.toString()}";
</script>
</head>
<body class="scroll-smooth w-screen">
<body class="scroll-smooth w-screen${defaultTheme === "dark" ? " dark" : ""}">
<div id="above-nav" class="container max-w-6xl mx-auto flex justify-between items-center w-full sticky top-0 z-10 pl-5 h-5">
</div>
<div id="nav-overlay" class="overlay hidden md:hidden inset-y-0 right-0 w-auto z-50 overflow-y-auto ease-out bg-slate-400 dark:bg-slate-800 drop-shadow-lg">
Expand Down Expand Up @@ -1796,7 +1805,7 @@ export class NewProjectPanel {
<label for="riscvToggle" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Architecture (Pico 2)</label>
<div class="flex items-center justify-between p-2 bg-gray-100 rounded-lg dark:bg-gray-700">
<input type="checkbox" id="sel-riscv" class="ms-2" />
<img id="riscvIcon" src="${riscvColorSvgUri.toString()}" alt="RISC-V Logo" class="h-6 mx-auto w-28">
<img id="riscvIcon" src="${riscvDefaultSvgUri.toString()}" alt="RISC-V Logo" class="h-6 mx-auto w-28">
</div>
</div>
</div>
Expand Down

0 comments on commit 20bd425

Please sign in to comment.