-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
170 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import deepmerge from "deepmerge"; | ||
import { Storage } from "@plasmohq/storage"; | ||
const storage = new Storage(); | ||
|
||
//We want to have everything as Partial (deep too) as the deepmerge will take care of matching with the default/stored configuration. | ||
type DeepPartial<T> = { | ||
[P in keyof T]?: DeepPartial<T[P]>; | ||
}; | ||
|
||
export const defaultGlobalConfig = { | ||
selectionMenu: { | ||
display: true, | ||
}, | ||
}; | ||
|
||
export async function getGlobalConfig() { | ||
let storagedConfig = {}; | ||
try { | ||
storagedConfig = await storage.get("globalConfig"); | ||
} catch (error) {} | ||
return deepmerge( | ||
{}, | ||
defaultGlobalConfig, | ||
storagedConfig | ||
) as typeof defaultGlobalConfig; | ||
} | ||
|
||
export async function setGlobalConfig( | ||
config: DeepPartial<typeof defaultGlobalConfig> | ||
) { | ||
let storagedConfig: DeepPartial<typeof defaultGlobalConfig>; | ||
try { | ||
storagedConfig = (await storage.get("globalConfig")) as Partial< | ||
typeof defaultGlobalConfig | ||
>; | ||
} catch (error) {} | ||
config = deepmerge< | ||
DeepPartial<typeof defaultGlobalConfig>, | ||
DeepPartial<typeof defaultGlobalConfig> | ||
>(storagedConfig, config); | ||
await storage.set("globalConfig", config); | ||
return config; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
Card, | ||
CardContent, | ||
CardHeader, | ||
} from "@/components/ui/card" | ||
import { useStorage } from "@plasmohq/storage/hook" | ||
import deepmerge from "deepmerge" | ||
import CardHeaderIntro from "~components/blocks/CardHeaderIntro" | ||
import { Checkbox } from "~components/ui/checkbox" | ||
import { defaultGlobalConfig, setGlobalConfig } from "~lib/configurations/globalConfig" | ||
|
||
export default function OptionsSettings() { | ||
//We're setting to the default if nothing exists. | ||
let [config] = useStorage("globalConfig", defaultGlobalConfig) | ||
config = deepmerge(defaultGlobalConfig, config) | ||
|
||
return ( | ||
<div className="grid gap-6 text-lg"> | ||
<Card x-chunk="dashboard-04-chunk-2"> | ||
<CardHeader> | ||
<CardHeaderIntro title={"Settings"} description={"Customise the look and feel of Extension | OS"} /> | ||
</CardHeader> | ||
<CardContent> | ||
Experience the perfect blend of simplicity and power with our tool—designed to be user-friendly while effortlessly handling complex tasks. | ||
</CardContent> | ||
</Card> | ||
|
||
<Card x-chunk="dashboard-04-chunk-2"> | ||
<CardHeader> | ||
<CardHeaderIntro title={"Selection Menu"} description={"The Selection menu shows when you select a text in any webpage"} /> | ||
</CardHeader> | ||
<CardContent> | ||
<div className="flex items-center space-x-2"> | ||
<Checkbox id="display-selection-menu" checked={config.selectionMenu.display} | ||
onCheckedChange={(checked) => { | ||
const result = checked === true ? true : false | ||
setGlobalConfig({ | ||
selectionMenu: { | ||
display: result, | ||
} | ||
}) | ||
}} /> | ||
<label | ||
htmlFor="display-selection-menu" | ||
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" | ||
> | ||
Display Selection Menu when two words are underlined. | ||
</label> | ||
</div> | ||
|
||
</CardContent> | ||
</Card> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "extension-os", | ||
"displayName": "Extension-OS: Your AI Partner", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"description": "AI at Your Fingertips, Anytime, Anywhere.", | ||
"author": "[email protected]", | ||
"scripts": { | ||
|
@@ -24,6 +24,7 @@ | |
"class-variance-authority": "^0.7.0", | ||
"clsx": "^2.1.1", | ||
"cmdk": "1.0.0", | ||
"deepmerge": "^4.3.1", | ||
"install": "^0.13.0", | ||
"lucide-react": "^0.414.0", | ||
"plasmo": "0.88.0", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { test, expect } from "./fixtures"; | ||
|
||
test("Selection Menu: Must show with the default config", async ({ page }) => { | ||
await page.waitForTimeout(1000); | ||
await page.goto("https://www.york.ac.uk/teaching/cws/wws/webpage1.html"); | ||
const pageTitle = await page.title(); | ||
await expect(pageTitle).toBe("webpage1"); | ||
await page.mouse.move(100, 100); // Move the mouse to the starting position (x: 100, y: 100) | ||
await page.mouse.down(); // Press the mouse button down to start selecting | ||
await page.mouse.move(300, 300); // Move the mouse to the end position (x: 300, y: 300) to select text | ||
await page.mouse.up(); // Release the mouse button to complete the selection | ||
|
||
const options = await page.getByRole("option"); | ||
const optionsCount = await options.count(); | ||
//Must be 7 as you have to count the +2 (separator + Setup Your Own Prompt) | ||
expect(optionsCount).toBe(7); | ||
|
||
const isGrammarFixerPresent = await page | ||
.getByRole("option", { name: "❗Grammar Fixer" }) | ||
.isVisible(); | ||
expect(isGrammarFixerPresent).toBe(true); | ||
}); | ||
|
||
test("Selection Menu: Must NOT show when the config is set to false", async ({ | ||
page, | ||
}) => { | ||
await page.waitForTimeout(1000); | ||
|
||
await page.click("#settings"); | ||
await page.waitForTimeout(1000); | ||
await page.uncheck("#display-selection-menu"); | ||
await page.goto("https://www.york.ac.uk/teaching/cws/wws/webpage1.html"); | ||
const pageTitle = await page.title(); | ||
await expect(pageTitle).toBe("webpage1"); | ||
await page.mouse.move(100, 100); // Move the mouse to the starting position (x: 100, y: 100) | ||
await page.mouse.down(); // Press the mouse button down to start selecting | ||
await page.mouse.move(300, 300); // Move the mouse to the end position (x: 300, y: 300) to select text | ||
await page.mouse.up(); // Release the mouse button to complete the selection | ||
|
||
const options = await page.getByRole("option"); | ||
const optionsCount = await options.count(); | ||
//Must be 0 as the configuration is NOT Showing the menu! | ||
expect(optionsCount).toBe(0); | ||
}); |