Skip to content

Commit

Permalink
fix: initial language detected correctly (#1881)
Browse files Browse the repository at this point in the history
  • Loading branch information
sr258 committed Oct 2, 2021
1 parent 3928009 commit 1934c0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
15 changes: 13 additions & 2 deletions server/src/config/SettingsCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export default class SettingsStorage {
return this.settings;
}

init(): void {
log.debug('Sending initial notification that settings are available.');
this.subscribers.forEach((subscriber) => subscriber());
}

/**
* Saves the settings so that they can be used elsewhere in the program.
* Also persists these changes to the settings file in the user directory.
Expand Down Expand Up @@ -88,7 +93,12 @@ export default class SettingsStorage {
* same
*/
public validateAndFixSettings(settings: IH5PEditorSettings): boolean {
log.debug(`Validating settings. Language: ${settings.language}`);
let lng = settings.language;
if (!lng) {
settings.language = 'en';
return true;
}
// allow regular language codes like de-DE or zh-HANS
if (
!/^[a-z]{2,3}(-[A-Z]{2,6})?$/i.test(settings.language) ||
Expand Down Expand Up @@ -149,8 +159,9 @@ export default class SettingsStorage {

if (!settingsOk) {
log.debug(
'There was an error loading the settings file. Either none exists or it is malformed. Generating new file.'
`There was an error loading the settings file. Either none exists or it is malformed. Generating new file. locale: ${app.getLocale()}`
);

this.settings = {
...defaultSettings,
language: app.getLocale()
Expand Down Expand Up @@ -191,7 +202,7 @@ export default class SettingsStorage {

if (!settingsOk) {
log.debug(
'There was an error loading the settings file. Either none exists or it is malformed. Generating new file.'
`There was an error loading the settings file. Either none exists or it is malformed. Generating new file. locale: ${app.getLocale()}`
);
this.settings = {
...defaultSettings,
Expand Down
9 changes: 4 additions & 5 deletions server/src/helpers/DelayedEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ export default class DelayedEmitter {
if (this.websocketServer) {
this.websocketServer.on('connection', this.onConnection);
}
if (settingsCache.getSettingsSync().privacyPolicyConsent) {
this.hasConsented = true;
} else {
settingsCache.subscribe(this.onSettingsChanged);
}
settingsCache.subscribe(this.onSettingsChanged);
}

private eventQueue: {
Expand Down Expand Up @@ -81,6 +77,9 @@ export default class DelayedEmitter {
private emitQueue = (): void => {
log.debug('DelayedEmitter: Emitting queued events');
for (const event of this.eventQueue) {
log.debug(
`Event: ${event.name}, args: ${JSON.stringify(event.args)}`
);
this.websocketServer.emit(event.name, ...event.args);
}
this.eventQueue = [];
Expand Down
5 changes: 4 additions & 1 deletion server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ if (!gotSingleInstanceLock) {

// create main BrowserWindow when electron is ready
app.on('ready', async () => {
log.debug('Electron ready event');
settingsCache.init();

// Performs migrations needed due to updates.
await migrations(serverPaths);

Expand Down Expand Up @@ -233,7 +236,7 @@ if (!gotSingleInstanceLock) {
log.info('window created');

const argv = process.argv;
if (process.platform === 'win32' && argv.length >= 2) {
if (argv.length >= 2) {
// Check if there are H5Ps specified in the command line args and
// load them (Windows only).
argv.splice(0, 1);
Expand Down

0 comments on commit 1934c0a

Please sign in to comment.