Skip to content

Commit

Permalink
feat: enabled typescript strict mode (#1233)
Browse files Browse the repository at this point in the history
* feat: enabled typescript strict mode

* Resolved type issues

* Added undefined check

* Adjusted JetBrainsToolbox and VSCode extension

* Refactored LinuxApplicationRepository

* Throw error instead of returning rejected promise

* Refactored LinuxAppIconExtractor

* Ignore ts error

* Fixed bug
  • Loading branch information
oliverschwendener authored Oct 22, 2024
1 parent 5f7e1bc commit c66407a
Show file tree
Hide file tree
Showing 68 changed files with 594 additions and 293 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe(WindowsStoreAutostartManager, () => {
"Ueli.lnk",
);

new WindowsStoreAutostartManager(app, shell, process, fileSystemUtility, null).setAutostartOptions(
new WindowsStoreAutostartManager(app, shell, process, fileSystemUtility, <Logger>{}).setAutostartOptions(
openAtLogin,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ describe(DefaultBrowserWindowConstructorOptionsProvider, () => {
appIconFilePathResolver,
).get();

expect(webPreferences.webSecurity).toBe(false);
expect(webPreferences.allowRunningInsecureContent).toBe(true);
expect(webPreferences.devTools).toBe(true);
expect(webPreferences?.webSecurity).toBe(false);
expect(webPreferences?.allowRunningInsecureContent).toBe(true);
expect(webPreferences?.devTools).toBe(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe(MacOsBrowserWindowConstructorOptionsProvider, () => {
it("should return the macOS window options", () => {
const defaultOptions = <BrowserWindowConstructorOptions>{
alwaysOnTop: true,
vibrancy: null,
vibrancy: undefined,
};

const getVibrancyMock = vi.fn().mockReturnValue("content");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class MacOsBrowserWindowConstructorOptionsProvider implements BrowserWind
return {
...this.defaultOptions,
...{
vibrancy: this.vibrancyProvider.get(),
vibrancy: this.vibrancyProvider.get() ?? undefined,
backgroundColor: "rgba(0,0,0,0)",
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe(VibrancyProvider, () => {
expected,
vibrancy,
}: {
expected: BrowserWindowConstructorOptions["vibrancy"];
expected: BrowserWindowConstructorOptions["vibrancy"] | null;
vibrancy: string;
}) => {
const settingsManager = <SettingsManager>{
Expand Down
30 changes: 19 additions & 11 deletions src/main/Core/BrowserWindow/BrowserWindowModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ export class BrowserWindowModule {
.getValue("window.hideWindowOn", BrowserWindowModule.DefaultHideWindowOnOptions)
.includes("escapePressed");

eventSubscriber.subscribe(
"actionInvoked",
({ action }: { action: SearchResultItemAction }) =>
shouldHideWindowAfterInvocation(action) && browserWindowToggler.hide(),
);
eventSubscriber.subscribe("actionInvoked", ({ action }: { action: SearchResultItemAction }) => {
if (shouldHideWindowAfterInvocation(action)) {
browserWindowToggler.hide();
}
});

eventSubscriber.subscribe("hotkeyPressed", () =>
browserWindowToggler.toggle(windowBoundsMemory.getBoundsNearestToCursor()),
Expand All @@ -160,7 +160,11 @@ export class BrowserWindowModule {
});

eventSubscriber.subscribe("settingUpdated[window.backgroundMaterial]", () => {
browserWindow.setBackgroundMaterial(backgroundMaterialProvider.get());
const backgroundMaterial = backgroundMaterialProvider.get();

if (backgroundMaterial) {
browserWindow.setBackgroundMaterial(backgroundMaterial);
}
});

eventSubscriber.subscribe("settingUpdated[window.vibrancy]", () => {
Expand Down Expand Up @@ -189,9 +193,9 @@ export class BrowserWindowModule {
const eventHandlers: { ueliCommands: UeliCommand[]; handler: (argument: unknown) => void }[] = [
{
ueliCommands: ["openAbout", "openExtensions", "openSettings", "show"],
handler: ({ pathname }: { pathname: string }) => {
handler: (argument) => {
browserWindowToggler.showAndFocus();
sendToBrowserWindow(browserWindow, "navigateTo", { pathname });
sendToBrowserWindow(browserWindow, "navigateTo", argument);
},
},
{
Expand All @@ -213,8 +217,12 @@ export class BrowserWindowModule {
browserWindow: BrowserWindow,
environmentVariableProvider: EnvironmentVariableProvider,
) {
await (environmentVariableProvider.get("VITE_DEV_SERVER_URL")
? browserWindow.loadURL(environmentVariableProvider.get("VITE_DEV_SERVER_URL"))
: browserWindow.loadFile(join(__dirname, "..", "dist-renderer", "index.html")));
const viteDevServerUrl = environmentVariableProvider.get("VITE_DEV_SERVER_URL");

if (viteDevServerUrl) {
await browserWindow.loadURL(viteDevServerUrl);
} else {
await browserWindow.loadFile(join(__dirname, "..", "dist-renderer", "index.html"));
}
}
}
2 changes: 1 addition & 1 deletion src/main/Core/BrowserWindow/BrowserWindowToggler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class BrowserWindowToggler {
this.browserWindow.webContents.send("windowFocused");
}

private repositionWindow(bounds: Rectangle): void {
private repositionWindow(bounds?: Rectangle): void {
this.browserWindow.setBounds(bounds ?? this.defaultSize);

if (!bounds || this.alwaysCenter()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { BrowserWindow } from "electron";
import type { BrowserWindowNotifier as BrowserWindowNotifierInterface } from "./Contract";

export class BrowserWindowNotifier implements BrowserWindowNotifierInterface {
private browserWindow: BrowserWindow;
private browserWindow?: BrowserWindow;

public setBrowserWindow(browserWindow: BrowserWindow) {
this.browserWindow = browserWindow;
Expand Down
86 changes: 43 additions & 43 deletions src/main/Core/Dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@ import type { Emitter } from "mitt";
import type * as Core from ".";

export type Dependencies = {
ActionHandlerRegistry?: Core.ActionHandlerRegistry;
App?: Electron.App;
AppleScriptUtility?: Core.AppleScriptUtility;
AssetPathResolver?: Core.AssetPathResolver;
BrowserWindowNotifier?: Core.BrowserWindowNotifier;
Clipboard?: Electron.Clipboard;
CommandlineUtility?: Core.CommandlineUtility;
DateProvider?: Core.DateProvider;
Dialog?: Electron.Dialog;
Emitter?: Emitter<Record<string, unknown>>;
EnvironmentVariableProvider?: Core.EnvironmentVariableProvider;
EventEmitter?: Core.EventEmitter;
EventSubscriber?: Core.EventSubscriber;
ExtensionRegistry?: Core.ExtensionRegistry;
FileImageGenerator?: Core.FileImageGenerator;
FileSystemUtility?: Core.FileSystemUtility;
GlobalShortcut?: Electron.GlobalShortcut;
IniFileParser?: Core.IniFileParser;
IpcMain?: Electron.IpcMain;
LinuxDesktopEnvironmentResolver?: Core.LinuxDesktopEnvironmentResolver;
Logger?: Core.Logger;
NativeTheme?: Electron.NativeTheme;
Net?: Electron.Net;
OperatingSystem?: CommonCore.OperatingSystem;
Platform?: string;
PowershellUtility?: Core.PowershellUtility;
RandomStringProvider?: Core.RandomStringProvider;
SafeStorage?: Electron.SafeStorage;
SafeStorageEncryption?: Core.SafeStorageEncryption;
Screen?: Electron.Screen;
SearchIndex?: Core.SearchIndex;
SettingsFile?: Core.SettingsFile;
SettingsManager?: Core.SettingsManager;
SettingsReader?: Core.SettingsReader;
SettingsWriter?: Core.SettingsWriter;
Shell?: Electron.Shell;
SystemPreferences?: Electron.SystemPreferences;
TaskScheduler?: Core.TaskScheduler;
TerminalRegistry?: Core.TerminalRegistry;
Translator?: Core.Translator;
UeliCommandInvoker?: Core.UeliCommandInvoker;
UrlImageGenerator?: Core.UrlImageGenerator;
XmlParser?: Core.XmlParser;
ActionHandlerRegistry: Core.ActionHandlerRegistry;
App: Electron.App;
AppleScriptUtility: Core.AppleScriptUtility;
AssetPathResolver: Core.AssetPathResolver;
BrowserWindowNotifier: Core.BrowserWindowNotifier;
Clipboard: Electron.Clipboard;
CommandlineUtility: Core.CommandlineUtility;
DateProvider: Core.DateProvider;
Dialog: Electron.Dialog;
Emitter: Emitter<Record<string, unknown>>;
EnvironmentVariableProvider: Core.EnvironmentVariableProvider;
EventEmitter: Core.EventEmitter;
EventSubscriber: Core.EventSubscriber;
ExtensionRegistry: Core.ExtensionRegistry;
FileImageGenerator: Core.FileImageGenerator;
FileSystemUtility: Core.FileSystemUtility;
GlobalShortcut: Electron.GlobalShortcut;
IniFileParser: Core.IniFileParser;
IpcMain: Electron.IpcMain;
LinuxDesktopEnvironmentResolver: Core.LinuxDesktopEnvironmentResolver;
Logger: Core.Logger;
NativeTheme: Electron.NativeTheme;
Net: Electron.Net;
OperatingSystem: CommonCore.OperatingSystem;
Platform: string;
PowershellUtility: Core.PowershellUtility;
RandomStringProvider: Core.RandomStringProvider;
SafeStorage: Electron.SafeStorage;
SafeStorageEncryption: Core.SafeStorageEncryption;
Screen: Electron.Screen;
SearchIndex: Core.SearchIndex;
SettingsFile: Core.SettingsFile;
SettingsManager: Core.SettingsManager;
SettingsReader: Core.SettingsReader;
SettingsWriter: Core.SettingsWriter;
Shell: Electron.Shell;
SystemPreferences: Electron.SystemPreferences;
TaskScheduler: Core.TaskScheduler;
TerminalRegistry: Core.TerminalRegistry;
Translator: Core.Translator;
UeliCommandInvoker: Core.UeliCommandInvoker;
UrlImageGenerator: Core.UrlImageGenerator;
XmlParser: Core.XmlParser;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { EnvironmentVariableProvider } from "./EnvironmentVariableProvider";

export class EnvironmentVariableProviderModule {
public static bootstrap(dependencyRegistry: DependencyRegistry<Dependencies>): void {
dependencyRegistry.register("EnvironmentVariableProvider", new EnvironmentVariableProvider(process.env));
dependencyRegistry.register(
"EnvironmentVariableProvider",
new EnvironmentVariableProvider(<Record<string, string>>process.env),
);
}
}
2 changes: 1 addition & 1 deletion src/main/Core/EventSubscriber/Contract/EventSubscriber.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface EventSubscriber {
subscribe<T>(event: string, eventHandler: (data?: T) => void): void;
subscribe<T>(event: string, eventHandler: (data: T) => void): void;
}
4 changes: 3 additions & 1 deletion src/main/Core/EventSubscriber/MittEventSubscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import type { EventSubscriber } from "./Contract";
export class MittEventSubscriber implements EventSubscriber {
public constructor(private readonly emitter: Emitter<Record<string, unknown>>) {}

public subscribe<T>(event: string, eventHandler: (data?: T) => void): void {
public subscribe<T>(event: string, eventHandler: (data: T) => void): void {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
this.emitter.on(event, eventHandler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface ExtensionRegistry {
* @param extension The extension to register.
* @throws If an extension with the same ID is already registered.
*/
register(extension: Extension);
register(extension: Extension): void;

/**
* Gets an extension by its ID.
Expand Down
7 changes: 4 additions & 3 deletions src/main/Core/ImageGenerator/ImageGeneratorModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ export class ImageGeneratorModule {
): FileIconExtractor[] {
const cacheFileNameGenerator = new CacheFileNameGenerator();

const currentDesktopEnvironment = dependencyRegistry.get("LinuxDesktopEnvironmentResolver").resolve();

// To prevent the execution of all icon extractor constructors, we use a function here that is only invoked
// for the current operating system.
const operatingSystemSpecificIconExtractors: Record<OperatingSystem, () => FileIconExtractor[]> = {
Linux: () =>
["Cinnamon", "GNOME", "KDE", "MATE", "XFCE", "Pantheon"].includes(
dependencyRegistry.get("LinuxDesktopEnvironmentResolver").resolve(),
)
currentDesktopEnvironment &&
["Cinnamon", "GNOME", "KDE", "MATE", "XFCE", "Pantheon"].includes(currentDesktopEnvironment)
? [
new LinuxAppIconExtractor(
dependencyRegistry.get("FileSystemUtility"),
Expand Down
Loading

0 comments on commit c66407a

Please sign in to comment.