mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Relocate some explicit error handlings to proper level of abstraction
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
e1733d382a
commit
18d13a23ac
@ -13,6 +13,9 @@ import updatesAreBeingDiscoveredInjectable from "../../common/application-update
|
|||||||
import progressOfUpdateDownloadInjectable from "../../common/application-update/progress-of-update-download/progress-of-update-download.injectable";
|
import progressOfUpdateDownloadInjectable from "../../common/application-update/progress-of-update-download/progress-of-update-download.injectable";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
import processCheckingForUpdatesInjectable from "./check-for-updates/process-checking-for-updates.injectable";
|
import processCheckingForUpdatesInjectable from "./check-for-updates/process-checking-for-updates.injectable";
|
||||||
|
import { withErrorSuppression } from "../../common/utils/with-error-suppression/with-error-suppression";
|
||||||
|
import { pipeline } from "@ogre-tools/fp";
|
||||||
|
import withErrorLoggingInjectable from "../../common/utils/with-error-logging/with-error-logging.injectable";
|
||||||
|
|
||||||
const checkForUpdatesTrayItemInjectable = getInjectable({
|
const checkForUpdatesTrayItemInjectable = getInjectable({
|
||||||
id: "check-for-updates-tray-item",
|
id: "check-for-updates-tray-item",
|
||||||
@ -25,6 +28,7 @@ const checkForUpdatesTrayItemInjectable = getInjectable({
|
|||||||
const downloadingUpdateState = di.inject(updateIsBeingDownloadedInjectable);
|
const downloadingUpdateState = di.inject(updateIsBeingDownloadedInjectable);
|
||||||
const checkingForUpdatesState = di.inject(updatesAreBeingDiscoveredInjectable);
|
const checkingForUpdatesState = di.inject(updatesAreBeingDiscoveredInjectable);
|
||||||
const processCheckingForUpdates = di.inject(processCheckingForUpdatesInjectable);
|
const processCheckingForUpdates = di.inject(processCheckingForUpdatesInjectable);
|
||||||
|
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: "check-for-updates",
|
id: "check-for-updates",
|
||||||
@ -51,11 +55,19 @@ const checkForUpdatesTrayItemInjectable = getInjectable({
|
|||||||
|
|
||||||
visible: computed(() => updatingIsEnabled),
|
visible: computed(() => updatingIsEnabled),
|
||||||
|
|
||||||
click: async () => {
|
click: pipeline(
|
||||||
await processCheckingForUpdates();
|
async () => {
|
||||||
|
await processCheckingForUpdates();
|
||||||
|
|
||||||
await showApplicationWindow();
|
await showApplicationWindow();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
withErrorLoggingFor(() => "[TRAY]: Checking for updates failed."),
|
||||||
|
|
||||||
|
// TODO: Find out how to improve typing so that instead of
|
||||||
|
// x => withErrorSuppression(x) there could only be withErrorSuppression
|
||||||
|
(x) => withErrorSuppression(x),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,9 @@ import { trayMenuItemInjectionToken } from "../tray/tray-menu-item/tray-menu-ite
|
|||||||
import quitAndInstallUpdateInjectable from "../electron-app/features/quit-and-install-update.injectable";
|
import quitAndInstallUpdateInjectable from "../electron-app/features/quit-and-install-update.injectable";
|
||||||
import discoveredUpdateVersionInjectable from "../../common/application-update/discovered-update-version/discovered-update-version.injectable";
|
import discoveredUpdateVersionInjectable from "../../common/application-update/discovered-update-version/discovered-update-version.injectable";
|
||||||
import updateIsBeingDownloadedInjectable from "../../common/application-update/update-is-being-downloaded/update-is-being-downloaded.injectable";
|
import updateIsBeingDownloadedInjectable from "../../common/application-update/update-is-being-downloaded/update-is-being-downloaded.injectable";
|
||||||
|
import { withErrorSuppression } from "../../common/utils/with-error-suppression/with-error-suppression";
|
||||||
|
import { pipeline } from "@ogre-tools/fp";
|
||||||
|
import withErrorLoggingInjectable from "../../common/utils/with-error-logging/with-error-logging.injectable";
|
||||||
|
|
||||||
const installApplicationUpdateTrayItemInjectable = getInjectable({
|
const installApplicationUpdateTrayItemInjectable = getInjectable({
|
||||||
id: "install-update-tray-item",
|
id: "install-update-tray-item",
|
||||||
@ -16,6 +19,7 @@ const installApplicationUpdateTrayItemInjectable = getInjectable({
|
|||||||
const quitAndInstallUpdate = di.inject(quitAndInstallUpdateInjectable);
|
const quitAndInstallUpdate = di.inject(quitAndInstallUpdateInjectable);
|
||||||
const discoveredVersionState = di.inject(discoveredUpdateVersionInjectable);
|
const discoveredVersionState = di.inject(discoveredUpdateVersionInjectable);
|
||||||
const downloadingUpdateState = di.inject(updateIsBeingDownloadedInjectable);
|
const downloadingUpdateState = di.inject(updateIsBeingDownloadedInjectable);
|
||||||
|
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: "install-update",
|
id: "install-update",
|
||||||
@ -34,9 +38,15 @@ const installApplicationUpdateTrayItemInjectable = getInjectable({
|
|||||||
() => !!discoveredVersionState.value.get() && !downloadingUpdateState.value.get(),
|
() => !!discoveredVersionState.value.get() && !downloadingUpdateState.value.get(),
|
||||||
),
|
),
|
||||||
|
|
||||||
click: () => {
|
click: pipeline(
|
||||||
quitAndInstallUpdate();
|
quitAndInstallUpdate,
|
||||||
},
|
|
||||||
|
withErrorLoggingFor(() => "[TRAY]: Update installation failed."),
|
||||||
|
|
||||||
|
// TODO: Find out how to improve typing so that instead of
|
||||||
|
// x => withErrorSuppression(x) there could only be withErrorSuppression
|
||||||
|
(x) => withErrorSuppression(x),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,9 @@ import showApplicationWindowInjectable from "../../../start-main-application/len
|
|||||||
import showAboutInjectable from "../../../menu/show-about.injectable";
|
import showAboutInjectable from "../../../menu/show-about.injectable";
|
||||||
import { trayMenuItemInjectionToken } from "../tray-menu-item-injection-token";
|
import { trayMenuItemInjectionToken } from "../tray-menu-item-injection-token";
|
||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
|
import withErrorLoggingInjectable from "../../../../common/utils/with-error-logging/with-error-logging.injectable";
|
||||||
|
import { withErrorSuppression } from "../../../../common/utils/with-error-suppression/with-error-suppression";
|
||||||
|
import { pipeline } from "@ogre-tools/fp";
|
||||||
|
|
||||||
const aboutAppTrayItemInjectable = getInjectable({
|
const aboutAppTrayItemInjectable = getInjectable({
|
||||||
id: "about-app-tray-item",
|
id: "about-app-tray-item",
|
||||||
@ -16,6 +19,7 @@ const aboutAppTrayItemInjectable = getInjectable({
|
|||||||
const productName = di.inject(productNameInjectable);
|
const productName = di.inject(productNameInjectable);
|
||||||
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
|
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
|
||||||
const showAbout = di.inject(showAboutInjectable);
|
const showAbout = di.inject(showAboutInjectable);
|
||||||
|
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: "about-app",
|
id: "about-app",
|
||||||
@ -25,11 +29,19 @@ const aboutAppTrayItemInjectable = getInjectable({
|
|||||||
enabled: computed(() => true),
|
enabled: computed(() => true),
|
||||||
visible: computed(() => true),
|
visible: computed(() => true),
|
||||||
|
|
||||||
click: async () => {
|
click: pipeline(
|
||||||
await showApplicationWindow();
|
async () => {
|
||||||
|
await showApplicationWindow();
|
||||||
|
|
||||||
await showAbout();
|
await showAbout();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
withErrorLoggingFor(() => "[TRAY]: Opening of show about failed."),
|
||||||
|
|
||||||
|
// TODO: Find out how to improve typing so that instead of
|
||||||
|
// x => withErrorSuppression(x) there could only be withErrorSuppression
|
||||||
|
(x) => withErrorSuppression(x),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,9 @@ import { trayMenuItemInjectionToken } from "../tray-menu-item-injection-token";
|
|||||||
import productNameInjectable from "../../../app-paths/app-name/product-name.injectable";
|
import productNameInjectable from "../../../app-paths/app-name/product-name.injectable";
|
||||||
import showApplicationWindowInjectable from "../../../start-main-application/lens-window/show-application-window.injectable";
|
import showApplicationWindowInjectable from "../../../start-main-application/lens-window/show-application-window.injectable";
|
||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
|
import withErrorLoggingInjectable from "../../../../common/utils/with-error-logging/with-error-logging.injectable";
|
||||||
|
import { withErrorSuppression } from "../../../../common/utils/with-error-suppression/with-error-suppression";
|
||||||
|
import { pipeline } from "@ogre-tools/fp";
|
||||||
|
|
||||||
const openAppTrayItemInjectable = getInjectable({
|
const openAppTrayItemInjectable = getInjectable({
|
||||||
id: "open-app-tray-item",
|
id: "open-app-tray-item",
|
||||||
@ -14,6 +17,7 @@ const openAppTrayItemInjectable = getInjectable({
|
|||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const productName = di.inject(productNameInjectable);
|
const productName = di.inject(productNameInjectable);
|
||||||
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
|
const showApplicationWindow = di.inject(showApplicationWindowInjectable);
|
||||||
|
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: "open-app",
|
id: "open-app",
|
||||||
@ -23,9 +27,17 @@ const openAppTrayItemInjectable = getInjectable({
|
|||||||
enabled: computed(() => true),
|
enabled: computed(() => true),
|
||||||
visible: computed(() => true),
|
visible: computed(() => true),
|
||||||
|
|
||||||
click: async () => {
|
click: pipeline(
|
||||||
await showApplicationWindow();
|
async () => {
|
||||||
},
|
await showApplicationWindow();
|
||||||
|
},
|
||||||
|
|
||||||
|
withErrorLoggingFor(() => "[TRAY]: Opening of application window failed."),
|
||||||
|
|
||||||
|
// TODO: Find out how to improve typing so that instead of
|
||||||
|
// x => withErrorSuppression(x) there could only be withErrorSuppression
|
||||||
|
(x) => withErrorSuppression(x),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -6,12 +6,16 @@ import { getInjectable } from "@ogre-tools/injectable";
|
|||||||
import { trayMenuItemInjectionToken } from "../tray-menu-item-injection-token";
|
import { trayMenuItemInjectionToken } from "../tray-menu-item-injection-token";
|
||||||
import navigateToPreferencesInjectable from "../../../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable";
|
import navigateToPreferencesInjectable from "../../../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable";
|
||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
|
import { withErrorSuppression } from "../../../../common/utils/with-error-suppression/with-error-suppression";
|
||||||
|
import { pipeline } from "@ogre-tools/fp";
|
||||||
|
import withErrorLoggingInjectable from "../../../../common/utils/with-error-logging/with-error-logging.injectable";
|
||||||
|
|
||||||
const openPreferencesTrayItemInjectable = getInjectable({
|
const openPreferencesTrayItemInjectable = getInjectable({
|
||||||
id: "open-preferences-tray-item",
|
id: "open-preferences-tray-item",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const navigateToPreferences = di.inject(navigateToPreferencesInjectable);
|
const navigateToPreferences = di.inject(navigateToPreferencesInjectable);
|
||||||
|
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: "open-preferences",
|
id: "open-preferences",
|
||||||
@ -21,9 +25,15 @@ const openPreferencesTrayItemInjectable = getInjectable({
|
|||||||
enabled: computed(() => true),
|
enabled: computed(() => true),
|
||||||
visible: computed(() => true),
|
visible: computed(() => true),
|
||||||
|
|
||||||
click: () => {
|
click: pipeline(
|
||||||
navigateToPreferences();
|
navigateToPreferences,
|
||||||
},
|
|
||||||
|
withErrorLoggingFor(() => "[TRAY]: Opening of preferences failed."),
|
||||||
|
|
||||||
|
// TODO: Find out how to improve typing so that instead of
|
||||||
|
// x => withErrorSuppression(x) there could only be withErrorSuppression
|
||||||
|
(x) => withErrorSuppression(x),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -6,12 +6,16 @@ import { getInjectable } from "@ogre-tools/injectable";
|
|||||||
import { trayMenuItemInjectionToken } from "../tray-menu-item-injection-token";
|
import { trayMenuItemInjectionToken } from "../tray-menu-item-injection-token";
|
||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
import stopServicesAndExitAppInjectable from "../../../stop-services-and-exit-app.injectable";
|
import stopServicesAndExitAppInjectable from "../../../stop-services-and-exit-app.injectable";
|
||||||
|
import { withErrorSuppression } from "../../../../common/utils/with-error-suppression/with-error-suppression";
|
||||||
|
import { pipeline } from "@ogre-tools/fp";
|
||||||
|
import withErrorLoggingInjectable from "../../../../common/utils/with-error-logging/with-error-logging.injectable";
|
||||||
|
|
||||||
const quitAppTrayItemInjectable = getInjectable({
|
const quitAppTrayItemInjectable = getInjectable({
|
||||||
id: "quit-app-tray-item",
|
id: "quit-app-tray-item",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const stopServicesAndExitApp = di.inject(stopServicesAndExitAppInjectable);
|
const stopServicesAndExitApp = di.inject(stopServicesAndExitAppInjectable);
|
||||||
|
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: "quit-app",
|
id: "quit-app",
|
||||||
@ -21,9 +25,15 @@ const quitAppTrayItemInjectable = getInjectable({
|
|||||||
enabled: computed(() => true),
|
enabled: computed(() => true),
|
||||||
visible: computed(() => true),
|
visible: computed(() => true),
|
||||||
|
|
||||||
click: () => {
|
click: pipeline(
|
||||||
stopServicesAndExitApp();
|
stopServicesAndExitApp,
|
||||||
},
|
|
||||||
|
withErrorLoggingFor(() => "[TRAY]: Quitting application failed."),
|
||||||
|
|
||||||
|
// TODO: Find out how to improve typing so that instead of
|
||||||
|
// x => withErrorSuppression(x) there could only be withErrorSuppression
|
||||||
|
(x) => withErrorSuppression(x),
|
||||||
|
),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -12,17 +12,21 @@ import type { LensMainExtension } from "../../../extensions/lens-main-extension"
|
|||||||
import type { TrayMenuItem } from "./tray-menu-item-injection-token";
|
import type { TrayMenuItem } from "./tray-menu-item-injection-token";
|
||||||
import { trayMenuItemInjectionToken } from "./tray-menu-item-injection-token";
|
import { trayMenuItemInjectionToken } from "./tray-menu-item-injection-token";
|
||||||
import type { TrayMenuRegistration } from "../tray-menu-registration";
|
import type { TrayMenuRegistration } from "../tray-menu-registration";
|
||||||
|
import { withErrorSuppression } from "../../../common/utils/with-error-suppression/with-error-suppression";
|
||||||
|
import type { WithErrorLoggingFor } from "../../../common/utils/with-error-logging/with-error-logging.injectable";
|
||||||
|
import withErrorLoggingInjectable from "../../../common/utils/with-error-logging/with-error-logging.injectable";
|
||||||
|
|
||||||
const trayMenuItemRegistratorInjectable = getInjectable({
|
const trayMenuItemRegistratorInjectable = getInjectable({
|
||||||
id: "tray-menu-item-registrator",
|
id: "tray-menu-item-registrator",
|
||||||
|
|
||||||
instantiate: (di) => (extension, installationCounter) => {
|
instantiate: (di) => (extension, installationCounter) => {
|
||||||
const mainExtension = extension as LensMainExtension;
|
const mainExtension = extension as LensMainExtension;
|
||||||
|
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
|
||||||
|
|
||||||
pipeline(
|
pipeline(
|
||||||
mainExtension.trayMenus,
|
mainExtension.trayMenus,
|
||||||
|
|
||||||
flatMap(toItemInjectablesFor(mainExtension, installationCounter)),
|
flatMap(toItemInjectablesFor(mainExtension, installationCounter, withErrorLoggingFor)),
|
||||||
|
|
||||||
(injectables) => di.register(...injectables),
|
(injectables) => di.register(...injectables),
|
||||||
);
|
);
|
||||||
@ -33,8 +37,7 @@ const trayMenuItemRegistratorInjectable = getInjectable({
|
|||||||
|
|
||||||
export default trayMenuItemRegistratorInjectable;
|
export default trayMenuItemRegistratorInjectable;
|
||||||
|
|
||||||
|
const toItemInjectablesFor = (extension: LensMainExtension, installationCounter: number, withErrorLoggingFor: WithErrorLoggingFor) => {
|
||||||
const toItemInjectablesFor = (extension: LensMainExtension, installationCounter: number) => {
|
|
||||||
const _toItemInjectables = (parentId: string | null) => (registration: TrayMenuRegistration): Injectable<TrayMenuItem, TrayMenuItem, void>[] => {
|
const _toItemInjectables = (parentId: string | null) => (registration: TrayMenuRegistration): Injectable<TrayMenuItem, TrayMenuItem, void>[] => {
|
||||||
const trayItemId = registration.id || kebabCase(registration.label || "");
|
const trayItemId = registration.id || kebabCase(registration.label || "");
|
||||||
const id = `${trayItemId}-tray-menu-item-for-extension-${extension.sanitizedExtensionId}-instance-${installationCounter}`;
|
const id = `${trayItemId}-tray-menu-item-for-extension-${extension.sanitizedExtensionId}-instance-${installationCounter}`;
|
||||||
@ -52,9 +55,17 @@ const toItemInjectablesFor = (extension: LensMainExtension, installationCounter:
|
|||||||
label: computed(() => registration.label || ""),
|
label: computed(() => registration.label || ""),
|
||||||
tooltip: registration.toolTip,
|
tooltip: registration.toolTip,
|
||||||
|
|
||||||
click: () => {
|
click: pipeline(
|
||||||
registration.click?.(registration);
|
() => {
|
||||||
},
|
registration.click?.(registration);
|
||||||
|
},
|
||||||
|
|
||||||
|
withErrorLoggingFor(() => `[TRAY]: Clicking of tray item "${trayItemId}" from extension "${extension.sanitizedExtensionId}" failed.`),
|
||||||
|
|
||||||
|
// TODO: Find out how to improve typing so that instead of
|
||||||
|
// x => withErrorSuppression(x) there could only be withErrorSuppression
|
||||||
|
(x) => withErrorSuppression(x),
|
||||||
|
),
|
||||||
|
|
||||||
enabled: computed(() => !!registration.enabled),
|
enabled: computed(() => !!registration.enabled),
|
||||||
visible: computed(() => true),
|
visible: computed(() => true),
|
||||||
|
|||||||
@ -82,14 +82,7 @@ const toTrayMenuOptions = (trayMenuItems: TrayMenuItem[]) => {
|
|||||||
submenu: _toTrayMenuOptions(trayMenuItem.id),
|
submenu: _toTrayMenuOptions(trayMenuItem.id),
|
||||||
|
|
||||||
click: () => {
|
click: () => {
|
||||||
try {
|
trayMenuItem.click?.();
|
||||||
trayMenuItem.click?.();
|
|
||||||
} catch (error) {
|
|
||||||
logger.error(
|
|
||||||
`${TRAY_LOG_PREFIX}: clicking item "${trayMenuItem.id} failed."`,
|
|
||||||
{ error },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user