Skip to content

Commit

Permalink
Added Windows Application Search settings
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverschwendener committed Feb 11, 2024
1 parent 6610b8f commit e534074
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ export class WindowsApplicationRepository implements ApplicationRepository {
) {}

public async getApplications(): Promise<Application[]> {
const stdout = await this.powershellUtility.executeScript(this.getPowershellScript());
const folderPaths = this.settings.getValue<string[]>("windowsFolders");
const fileExtensions = this.settings.getValue<string[]>("windowsFileExtensions");

if (!folderPaths.length || !fileExtensions.length) {
return [];
}

const stdout = await this.powershellUtility.executeScript(
this.getPowershellScript(folderPaths, fileExtensions),
);

const windowsApplicationRetrieverResults = <WindowsApplicationRetrieverResult[]>JSON.parse(stdout);

Expand All @@ -23,23 +32,16 @@ export class WindowsApplicationRepository implements ApplicationRepository {
);
}

private getPowershellScript(): string {
const folderPaths = this.settings
.getValue<string[]>("windowsFolders")
.map((folderPath) => `'${folderPath}'`)
.join(",");

const fileExtensions = this.settings
.getValue<string[]>("windowsFileExtensions")
.map((fileExtension) => `'*.${fileExtension}'`)
.join(",");
private getPowershellScript(folderPaths: string[], fileExtensions: string[]): string {
const concatenatedFolderPaths = folderPaths.map((folderPath) => `'${folderPath}'`).join(",");
const concatenatedFileExtensions = fileExtensions.map((fileExtension) => `'*.${fileExtension}'`).join(",");

const { extractShortcutPowershellScript, getWindowsAppsPowershellScript } = usePowershellScripts();

return `
${extractShortcutPowershellScript}
${getWindowsAppsPowershellScript}
Get-WindowsApps -FolderPaths ${folderPaths} -FileExtensions ${fileExtensions} -AppIconFolder '${this.extensionCacheFolder.path}';`;
Get-WindowsApps -FolderPaths ${concatenatedFolderPaths} -FileExtensions ${concatenatedFileExtensions} -AppIconFolder '${this.extensionCacheFolder.path}';`;
}
}
33 changes: 19 additions & 14 deletions src/renderer/Extensions/ApplicationSearch/MacOs/MacOsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,39 @@ export const MacOsSettings = () => {

const extensionId = "ApplicationSearch";

const [newValue, setNewValue] = useState<string>("");
const [newFolder, setNewFolder] = useState<string>("");

const { value, updateValue } = useExtensionSetting<string[]>({ extensionId, key: "macOsFolders" });
const { value: folders, updateValue: setFolders } = useExtensionSetting<string[]>({
extensionId,
key: "macOsFolders",
});

const removeFolder = async (indexToRemove: number) => {
await updateValue(value.filter((_, index) => index !== indexToRemove));
await setFolders(folders.filter((_, index) => index !== indexToRemove));
};

const addFolder = async () => {
if (newValue.trim().length) {
await updateValue([...value, newValue]);
setNewValue("");
if (newFolder.trim().length) {
await setFolders([...folders, newFolder]);
setNewFolder("");
}
};

const chooseFolder = async () => {
const result = await contextBridge.showOpenDialog({ properties: ["openDirectory"] });
if (!result.canceled && result.filePaths.length) {
setNewValue(result.filePaths[0]);
setNewFolder(result.filePaths[0]);
}
};

return (
<SectionList>
<Section>
<Field label="Application Folders" style={{ display: "flex", flexDirection: "column", gap: 5 }}>
{value.map((v, index) => (
{folders.map((folder, index) => (
<Input
key={`macOsFolder-${v}`}
value={v}
key={`macOsFolder-${folder}`}
value={folder}
readOnly
contentAfter={
<Tooltip content="Remove" relationship="label">
Expand All @@ -53,23 +56,25 @@ export const MacOsSettings = () => {
/>
))}
<Input
value={newValue}
value={newFolder}
placeholder="Add another folder"
onChange={(_, { value }) => setNewValue(value)}
onChange={(_, { value }) => setNewFolder(value)}
contentAfter={
<>
<Tooltip content="Choose folder" relationship="label">
<Button
appearance="subtle"
size="small"
icon={<FolderRegular fontSize={14} onClick={chooseFolder} />}
icon={<FolderRegular fontSize={14} />}
onClick={chooseFolder}
/>
</Tooltip>
<Tooltip content="Add" relationship="label">
<Button
appearance="subtle"
size="small"
icon={<AddRegular fontSize={14} onClick={addFolder} />}
icon={<AddRegular fontSize={14} />}
onClick={addFolder}
/>
</Tooltip>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { useExtensionSetting } from "@Core/Hooks";
import { Button, Field, Input, Tooltip } from "@fluentui/react-components";
import { AddRegular, DismissRegular } from "@fluentui/react-icons";
import { useState } from "react";

export const FileExtensions = () => {
const [newFileExtension, setNewFileExtension] = useState<string>("");

const { value: fileExtensions, updateValue: setFileExtensions } = useExtensionSetting<string[]>({
extensionId: "ApplicationSearch",
key: "windowsFileExtensions",
});

const removeFileExtension = (fileExtension: string) => {
setFileExtensions(fileExtensions.filter((f) => f !== fileExtension));
};

const addFileExtension = (fileExtension: string) => {
setFileExtensions([...fileExtensions, fileExtension]);
setNewFileExtension("");
};

return (
<Field label="File Extensions (e.g.: lnk, exe)">
<div style={{ display: "flex", flexDirection: "column", gap: 5 }}>
{fileExtensions.map((fileExtension) => (
<Input
readOnly
value={fileExtension}
contentAfter={
<Tooltip content="Remove" relationship="label">
<Button
size="small"
appearance="subtle"
icon={<DismissRegular />}
onClick={() => removeFileExtension(fileExtension)}
/>
</Tooltip>
}
/>
))}
<Input
value={newFileExtension}
placeholder="Add another file extension"
onChange={(_, { value }) => setNewFileExtension(value)}
contentAfter={
<Tooltip content="Add" relationship="label">
<Button
appearance="subtle"
size="small"
icon={<AddRegular />}
onClick={() => addFileExtension(newFileExtension)}
/>
</Tooltip>
}
/>
</div>
</Field>
);
};
79 changes: 79 additions & 0 deletions src/renderer/Extensions/ApplicationSearch/Windows/Folders.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { useContextBridge, useExtensionSetting } from "@Core/Hooks";
import { Button, Field, Input, Tooltip } from "@fluentui/react-components";
import { AddRegular, DismissRegular, FolderRegular } from "@fluentui/react-icons";
import { useState } from "react";

export const Folders = () => {
const { contextBridge } = useContextBridge();

const { value: folders, updateValue: setFolders } = useExtensionSetting<string[]>({
extensionId: "ApplicationSearch",
key: "windowsFolders",
});

const [newFolder, setNewFolder] = useState<string>("");

const removeFolder = (folder: string) => {
setFolders(folders.filter((f) => f !== folder));
};

const addFolder = (folder: string) => {
setFolders([...folders, folder]);
setNewFolder("");
};

const chooseFolder = async () => {
const result = await contextBridge.showOpenDialog({ properties: ["openDirectory"] });
if (!result.canceled && result.filePaths.length) {
setNewFolder(result.filePaths[0]);
}
};

return (
<Field label="Folders">
<div style={{ display: "flex", flexDirection: "column", gap: 5 }}>
{folders.map((folder) => (
<Input
readOnly
value={folder}
contentAfter={
<Tooltip content="Remove" relationship="label">
<Button
size="small"
appearance="subtle"
icon={<DismissRegular />}
onClick={() => removeFolder(folder)}
/>
</Tooltip>
}
/>
))}
<Input
value={newFolder}
placeholder="Add another folder"
onChange={(_, { value }) => setNewFolder(value)}
contentAfter={
<>
<Tooltip content="Choose folder" relationship="label">
<Button
appearance="subtle"
size="small"
icon={<FolderRegular />}
onClick={() => chooseFolder()}
/>
</Tooltip>
<Tooltip content="Add" relationship="label">
<Button
appearance="subtle"
size="small"
icon={<AddRegular />}
onClick={() => addFolder(newFolder)}
/>
</Tooltip>
</>
}
/>
</div>
</Field>
);
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
import { Section } from "@Core/Settings/Section";
import { SectionList } from "@Core/Settings/SectionList";
import { FileExtensions } from "./FileExtensions";
import { Folders } from "./Folders";

export const WindowsSettings = () => {
return <>TODO</>;
return (
<SectionList>
<Section>
<Folders />
</Section>
<Section>
<FileExtensions />
</Section>
</SectionList>
);
};

0 comments on commit e534074

Please sign in to comment.