Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with Auto Updater and I18n #541

Merged
merged 1 commit into from
Jul 12, 2023
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
32 changes: 28 additions & 4 deletions src/app/updater.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
import { autoUpdater } from 'electron-updater';
import { BrowserWindow, dialog } from 'electron';
import { useTranslation } from 'react-i18next';
import { initReactI18next } from 'react-i18next';
import i18n from 'i18next';
import Backend from 'i18next-http-backend'; // For loading translations from backend
import { LoggerService } from '../api/src/logger';

export default class Updater {
constructor(
private logger: LoggerService,
private mainWindow: BrowserWindow
private mainWindow: BrowserWindow,
private baseUrl: string
) {
const systemLocale = Intl.DateTimeFormat().resolvedOptions().locale;

const loadPath = `${
this.baseUrl ?? 'http://localhost:3500/'
}/locales/{{lng}}/messages.json`;

i18n
.use(Backend)
.use(initReactI18next)
.init({
initImmediate: false,
fallbackLng: 'en',
backend: {
loadPath,
},
debug:
process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true',
});

i18n.loadLanguages(systemLocale);
const t = i18n.getFixedT(systemLocale);

autoUpdater.autoDownload = false;

autoUpdater.on('error', (error) => {
this.logger.error(error, error.stack);
});

autoUpdater.on('update-available', async () => {
const { t } = useTranslation();
const response = await dialog.showMessageBox(this.mainWindow, {
type: 'info',
title: t('Updater.FoundUpdates'),
Expand All @@ -36,7 +61,6 @@ export default class Updater {
});

autoUpdater.on('update-downloaded', async () => {
const { t } = useTranslation();
const response = await dialog.showMessageBox(this.mainWindow, {
type: 'info',
buttons: [t('Updater.Restart'), t('Updater.Later')],
Expand Down
4 changes: 2 additions & 2 deletions src/i18n/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@
"Sure": "Sure",
"Later": "Later",
"UpdateDownloading": "Update Downloading",
"NotifiedWhenReadyToInstall.": "Update is being downloaded, you will be notified when it is ready to install.",
"NotifiedWhenReadyToInstall": "Update is being downloaded, you will be notified when it is ready to install.",
"Restart": "Restart",
"ApplicationUpdate": "Application Update",
"Update": "Update",
"ApplyUpdates.": "A new version has been downloaded. Restart the application to apply the updates."
"ApplyUpdates": "A new version has been downloaded. Restart the application to apply the updates."
},
"ConfiguratorView": {
"DownloadLUAScript": "Download LUA script",
Expand Down
2 changes: 1 addition & 1 deletion src/main.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ const createWindow = async () => {
shell.openExternal(url);
});

updater = new Updater(logger, mainWindow);
updater = new Updater(logger, mainWindow, baseUrl);
};
/**
* Add event listeners...
Expand Down