From a4190662b9d96db0781f6d660f68e082674b9e64 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Mon, 2 Sep 2024 23:29:42 +0200 Subject: [PATCH] improve about dialog closes #2138 --- src/main/aboutPanel.ts | 38 ++++++++++++++++++++++++++++++++++++++ src/main/index.ts | 32 ++++++-------------------------- src/main/isStoreBuild.ts | 3 +++ 3 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 src/main/aboutPanel.ts create mode 100644 src/main/isStoreBuild.ts diff --git a/src/main/aboutPanel.ts b/src/main/aboutPanel.ts new file mode 100644 index 00000000..43a29edd --- /dev/null +++ b/src/main/aboutPanel.ts @@ -0,0 +1,38 @@ +// eslint-disable-next-line import/no-extraneous-dependencies +import { AboutPanelOptionsOptions, app } from 'electron'; + +import { appName, copyrightYear } from './common.js'; +import { isLinux } from './util.js'; +import isStoreBuild from './isStoreBuild.js'; +import { githubLink, homepage } from './constants.js'; + + +// eslint-disable-next-line import/prefer-default-export +export function getAboutPanelOptions() { + const showVersion = !isStoreBuild; + + const appVersion = app.getVersion(); + + const aboutPanelLines = [ + isStoreBuild ? homepage : githubLink, + '', + `Copyright © 2016-${copyrightYear} Mikael Finstad ❤️ 🇳🇴`, + ]; + + const aboutPanelOptions: AboutPanelOptionsOptions = { + applicationName: appName, + copyright: aboutPanelLines.join('\n'), + version: '', // not very useful (supported on MacOS only, and same as applicationVersion) + }; + + // https://github.com/electron/electron/issues/18918 + // https://github.com/mifi/lossless-cut/issues/1537 + if (isLinux) { + aboutPanelOptions.applicationVersion = appVersion; + } else if (!showVersion) { + // https://github.com/mifi/lossless-cut/issues/1882 + aboutPanelOptions.applicationVersion = `${process.windowsStore ? 'Microsoft Store' : 'App Store'} edition, based on GitHub v${appVersion}`; + } + + return aboutPanelOptions; +} diff --git a/src/main/index.ts b/src/main/index.ts index f2cc6853..5649d881 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -3,7 +3,7 @@ process.traceProcessWarnings = true; /* eslint-disable import/first */ // eslint-disable-next-line import/no-extraneous-dependencies -import electron, { AboutPanelOptionsOptions, BrowserWindow, BrowserWindowConstructorOptions, nativeTheme, shell, app, ipcMain, Notification, NotificationConstructorOptions } from 'electron'; +import electron, { BrowserWindow, BrowserWindowConstructorOptions, nativeTheme, shell, app, ipcMain, Notification, NotificationConstructorOptions } from 'electron'; import i18n from 'i18next'; import debounce from 'lodash.debounce'; import yargsParser from 'yargs-parser'; @@ -16,11 +16,13 @@ import timers from 'node:timers/promises'; import logger from './logger.js'; import menu from './menu.js'; import * as configStore from './configStore.js'; -import { isLinux, isWindows } from './util.js'; -import { appName, copyrightYear } from './common.js'; +import { isWindows } from './util.js'; +import { appName } from './common.js'; import attachContextMenu from './contextMenu.js'; import HttpServer from './httpServer.js'; import isDev from './isDev.js'; +import isStoreBuild from './isStoreBuild.js'; +import { getAboutPanelOptions } from './aboutPanel.js'; import { checkNewVersion } from './updateChecker.js'; @@ -67,8 +69,6 @@ app.commandLine.appendSwitch('enable-blink-features', 'AudioVideoTracks'); remote.initialize(); -const appVersion = app.getVersion(); - app.name = appName; if (isWindows) { @@ -78,28 +78,8 @@ if (isWindows) { app.setAppUserModelId(app.name); } -const isStoreBuild = process.windowsStore || process.mas; - -const showVersion = !isStoreBuild; - -const aboutPanelOptions: AboutPanelOptionsOptions = { - applicationName: appName, - copyright: `Copyright © ${copyrightYear} Mikael Finstad ❤️ 🇳🇴`, - version: '', // not very useful (MacOS only, and same as applicationVersion) -}; - -// https://github.com/electron/electron/issues/18918 -// https://github.com/mifi/lossless-cut/issues/1537 -if (isLinux) { - aboutPanelOptions.version = appVersion; -} -if (!showVersion) { - // https://github.com/mifi/lossless-cut/issues/1882 - aboutPanelOptions.applicationVersion = `${process.windowsStore ? 'Microsoft Store' : 'App Store'} edition, based on GitHub v${appVersion}`; -} - // https://www.electronjs.org/docs/latest/api/app#appsetaboutpaneloptionsoptions -app.setAboutPanelOptions(aboutPanelOptions); +app.setAboutPanelOptions(getAboutPanelOptions()); let filesToOpen: string[] = []; diff --git a/src/main/isStoreBuild.ts b/src/main/isStoreBuild.ts new file mode 100644 index 00000000..b9e39ed4 --- /dev/null +++ b/src/main/isStoreBuild.ts @@ -0,0 +1,3 @@ +const isStoreBuild = process.windowsStore || process.mas; + +export default isStoreBuild;