Skip to content

Commit

Permalink
✨ added commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Swaggeroo committed Jul 12, 2024
1 parent a6199b7 commit c960e53
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 62 deletions.
49 changes: 0 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,52 +54,3 @@ Quick starting guide for new plugin devs:
- Publish an initial version.
- Make sure you have a `README.md` file in the root of your repo.
- Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin.

## How to use

- Clone this repo.
- Make sure your NodeJS is at least v16 (`node --version`).
- `npm i` or `yarn` to install dependencies.
- `npm run dev` to start compilation in watch mode.

## Manually installing the plugin

- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.

## Improve code quality with eslint (optional)
- [ESLint](https://eslint.org/) is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code.
- To use eslint with this project, make sure to install eslint from terminal:
- `npm install -g eslint`
- To use eslint to analyze this project use this command:
- `eslint main.ts`
- eslint will then create a report with suggestions for code improvement by file and line number.
- If your source code is in a folder, such as `src`, you can use eslint with this command to analyze all files in that folder:
- `eslint .\src\`

## Funding URL

You can include funding URLs where people who use your plugin can financially support it.

The simple way is to set the `fundingUrl` field to your link in your `manifest.json` file:

```json
{
"fundingUrl": "https://buymeacoffee.com"
}
```

If you have multiple URLs, you can also do:

```json
{
"fundingUrl": {
"Buy Me a Coffee": "https://buymeacoffee.com",
"GitHub Sponsor": "https://github.com/sponsors",
"Patreon": "https://www.patreon.com/"
}
}
```

## API Documentation

See https://github.com/obsidianmd/obsidian-api
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 30 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class AIImageAnalyzerPlugin extends Plugin {
id: 'analyze-image-to-clipboard',
name: 'Analyze image to clipboard',
callback: () => {
const file = getActiveFile(this.app)
const file = getActiveFile()
if (file != null && isImageFile(file)) {
analyzeToClipboard(file);
} else {
Expand All @@ -64,6 +64,33 @@ export default class AIImageAnalyzerPlugin extends Plugin {
}
});

this.addCommand({
id: 'analyze-image',
name: 'Analyze image',
callback: () => {
const file = getActiveFile()
if (file != null && isImageFile(file)) {
analyzeImageWithNotice(file);
} else {
new Notice('No image found');
}
}
});

this.addCommand({
id: 'clear-cache-of-active-image',
name: 'Clear cache of active image',
callback: () => {
const file = getActiveFile()
if (file != null && isImageFile(file)) {
removeFromCache(file);
new Notice('Cache cleared');
} else {
new Notice('No image found');
}
}
});

this.registerEvent(
this.app.workspace.on('file-menu', (menu, file, _source) => {
if (file instanceof TFile && isImageFile(file)) {
Expand Down Expand Up @@ -200,8 +227,8 @@ class AIImageAnalyzerSettingsTab extends PluginSettingTab {
}
}

function getActiveFile(app: App): TFile | null {
return app.workspace.activeEditor?.file ?? app.workspace.getActiveFile();
function getActiveFile(): TFile | null {
return this.app.workspace.activeEditor?.file ?? this.app.workspace.getActiveFile();
}

function isImageFile(file: TFile): boolean {
Expand Down
8 changes: 0 additions & 8 deletions styles.css

This file was deleted.

0 comments on commit c960e53

Please sign in to comment.