Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/default-project/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ const defaultProject = translator => {
dataFormat: 'SVG',
data: encoder.encode(backdrop)
}, {
id: '927d672925e7b99f7813735c484c6922',
id: '3ffb86585ebbb654fbc092ea9b0a41b3',
assetType: 'ImageVector',
dataFormat: 'SVG',
data: encoder.encode(costume1)
},
{
id: 'f1b8a0c2e3e4f5a6b7c8d9e0f1a2b3c4',
id: '2e11410044fca296f1623ae28a7abff4',
assetType: 'ImageVector',
dataFormat: 'SVG',
data: encoder.encode(costume2)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import defaultProject from './default-project';

// eslint-disable-next-line import/no-commonjs
const {TRUSTED_IFRAME_HOST} = require('./brand.js');
const isStandAlone = process.env.IS_STANDLALONE === 'true';
const isStandAlone = process.env.IS_STANDALONE === 'true';

/**
* Wrapper for ScratchStorage which adds default web sources.
Expand Down
35 changes: 30 additions & 5 deletions src/lib/themes/themePersistance.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {BLOCKS_CUSTOM, Theme} from '.';

const STORAGE_KEY = 'ct:theme';

const matchMedia = query => (window.matchMedia ? window.matchMedia(query) : null);
const PREFERS_HIGH_CONTRAST_QUERY = matchMedia('(prefers-contrast: more)');
const PREFERS_DARK_QUERY = matchMedia('(prefers-color-scheme: dark)');
Expand All @@ -11,19 +13,20 @@ const systemPreferencesTheme = () => {
// Check for URL search parameters first (highest priority)
const urlParams = new URLSearchParams(window.location.search);
const modeParam = urlParams.get('mode');

// Check for mode parameter on any page
if (modeParam === 'dark') {
return Theme.dark;
} else if (modeParam === 'light') {
return Theme.light;
}

// If on home page, default to light theme
if (window.location.pathname === "/" || window.location.pathname.includes("/index.html") || window.location.pathname === "/build/") {
// eslint-disable-next-line max-len
if (window.location.pathname === '/' || window.location.pathname.includes('/index.html') || window.location.pathname === '/build/') {
return Theme.light;
}

if (PREFERS_HIGH_CONTRAST_QUERY && PREFERS_HIGH_CONTRAST_QUERY.matches) {
return Theme.highContrast;
}
Expand Down Expand Up @@ -62,7 +65,29 @@ const onSystemPreferenceChange = onChange => {
*/
const detectTheme = () => {
const systemPreferences = systemPreferencesTheme();
return systemPreferences;
let theme = systemPreferences;

try {
const stored = localStorage.getItem(STORAGE_KEY);
if (stored) {
const parsed = JSON.parse(stored);
if (parsed) {
if (parsed.accent) {
theme = theme.set('accent', parsed.accent);
}
if (parsed.gui) {
theme = theme.set('gui', parsed.gui);
}
if (parsed.blocks && parsed.blocks !== BLOCKS_CUSTOM) {
theme = theme.set('blocks', parsed.blocks);
}
}
}
} catch (e) {
// ignore
}

return theme;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ module.exports = [
'process.env.FORCE_EMBED': JSON.stringify(process.env.FORCE_EMBED || 'true'),
'process.env.COLLABORATION_HOST': JSON.stringify(process.env.COLLABORATION_HOST || 'wss://collaborator.codetorch.net/'),
'process.env.COLLABORATION_DEV_MODE': JSON.stringify(process.env.COLLABORATION_DEV_MODE || 'false'),
'process.env.IS_STANDLALONE': JSON.stringify(process.env.IS_STANDLALONE || 'false')
'process.env.IS_STANDALONE': JSON.stringify(process.env.IS_STANDALONE || 'false')
}),
new HtmlWebpackPlugin({
chunks: ['editor'],
Expand Down
Loading