-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
299 additions
and
159 deletions.
There are no files selected for viewing
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
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,45 @@ | ||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-License-Identifier: MIT | ||
|
||
// pub use tauri_macros::; | ||
use tauri::{ | ||
menu::{Menu, MenuItem}, | ||
tray::TrayIconBuilder, | ||
Manager, Runtime, | ||
}; | ||
|
||
pub fn create_tray<R: Runtime>(app: &tauri::AppHandle<R>) -> tauri::Result<()> { | ||
let toggle_i = MenuItem::with_id(app, "toggle", "Toggle", true, None::<&str>)?; | ||
let quit_i = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?; | ||
let menu1 = Menu::with_items(app, &[&toggle_i, &quit_i])?; | ||
let _ = TrayIconBuilder::with_id("tray-1") | ||
.tooltip("Tauri") | ||
.icon(app.default_window_icon().unwrap().clone()) | ||
.menu(&menu1) | ||
.menu_on_left_click(true) | ||
.on_menu_event(move |app, event| match event.id.as_ref() { | ||
"quit" => { | ||
app.exit(0); | ||
} | ||
"toggle" => { | ||
if let Some(window) = app.get_webview_window("main") { | ||
let visible = window.is_visible().unwrap(); | ||
println!("visible: {}", visible); | ||
let new_title = if window.is_visible().unwrap_or_default() { | ||
let _ = window.hide(); | ||
"Show" | ||
} else { | ||
let _ = window.show(); | ||
let _ = window.set_focus(); | ||
"Hide" | ||
}; | ||
toggle_i.set_text(new_title).unwrap(); | ||
} | ||
} | ||
_ => {} | ||
}) | ||
.build(app); | ||
|
||
Ok(()) | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"clipboard": "clipboard", | ||
"clipboard": "Clipboard", | ||
"http": "Http", | ||
"runAppleScript": "runAppleScript" | ||
"fs": "File System" | ||
} |
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,3 +1,37 @@ | ||
# clipboard | ||
# Clipboard | ||
|
||
wip... | ||
Access clipboard text/image/files/HTML/RTF. | ||
|
||
## Sample Code | ||
|
||
```ts | ||
import { clipboard } from '@penxio/api' | ||
|
||
await clipboard.writeText('Hello, PenX!') | ||
const text = await clipboard.readText() | ||
|
||
const imageBase64 = await clipboard.readImageBase64() | ||
``` | ||
|
||
## APIs | ||
|
||
https://penx-api.penx.io/interfaces/IClipboard.html | ||
|
||
- `hasFiles` | ||
- `hasHTML` | ||
- `hasImage` | ||
- `hasRTF` | ||
- `hasText` | ||
- `readFiles` | ||
- `readHtml` | ||
- `readImageBase64` | ||
- `readImageBinary` | ||
- `readRtf` | ||
- `readText` | ||
- `writeFiles` | ||
- `writeHtml` | ||
- `writeHtmlAndText` | ||
- `writeImageBase64` | ||
- `writeImageBinary` | ||
- `writeRtf` | ||
- `writeText` |
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,25 @@ | ||
# Dialog | ||
|
||
Dialog API provides functions to interact with user, get user input, and more. | ||
|
||
https://penx-api.penx.io/interfaces/IDialog.html | ||
|
||
|
||
```ts | ||
import { dialog } from '@penxio/api' | ||
|
||
const name = await dialog.ask("What's your name?") | ||
const confirmed = await dialog.confirm('Are you sure you want to delete this file?') | ||
|
||
// Ask for save path | ||
const savePath = await dialog.save() | ||
console.log(savePath); | ||
``` | ||
|
||
## APIs | ||
|
||
- `ask` | ||
- `confirm` | ||
- `message` | ||
- `open` | ||
- `save` |
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,34 @@ | ||
# File System | ||
|
||
https://penx-api.penx.io/interfaces/IFs.html | ||
|
||
```ts | ||
import { fs } from '@penxio/api' | ||
|
||
const fileContent = await fs.readFile('/home/penx/package.json') | ||
|
||
const fileExists = await fs.exists('/home/penx/package.json') | ||
|
||
await fs.rename('/home/a.txt', '/home/q.txt') | ||
|
||
await fs.writeTextFile('/home/b.txt', 'Hello from PenX!') | ||
|
||
await fs.copyFile('/home/b.txt', '/home/c.txt') | ||
``` | ||
|
||
## APIs | ||
|
||
- `copyFile` | ||
- `create` | ||
- `exists` | ||
- `lstat` | ||
- `mkdir` | ||
- `readDir` | ||
- `readFile` | ||
- `readTextFile` | ||
- `remove` | ||
- `rename` | ||
- `stat` | ||
- `truncate` | ||
- `writeFile` | ||
- `writeTextFile` |
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,68 +1,21 @@ | ||
# HTTP | ||
|
||
Sending HTTP Requests in Command App. | ||
Sending HTTP requests and bypass CORS restrictions. | ||
|
||
## Using `fetch` | ||
https://penx-api.penx.io/functions/fetch.html | ||
|
||
In most cases, you can use web standarn API [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). And this is the recommanded way to send a HTTP request. | ||
|
||
```js | ||
import { MarkdownBuilder, render } from '@penxio/api' | ||
|
||
export async function main() { | ||
const res = await fetch('https://jsonplaceholder.typicode.com/todos/1').then( | ||
(res) => res.json(), | ||
) | ||
|
||
const md = new MarkdownBuilder(JSON.stringify(res, null, 2)) | ||
render(md) | ||
} | ||
``` | ||
|
||
## Using `request` | ||
|
||
If you encounter a CORS error, you can use the `request` API instead. | ||
|
||
![cors](/images/cors-error.webp) | ||
|
||
### GET | ||
|
||
To send a GET request: | ||
> Sending request from browser may be restricted by CORS policy. You can use the provided `fetch` API to bypass this restriction. | ||
> | ||
> The `fetch` API works just like a regular `fetch` function provided in browser. | ||
> | ||
> If you don't need to bypass CORS, you can use the regular `fetch` function provided by the browser, or other libraries like `axios`. | ||
```ts | ||
import { MarkdownBuilder, request } from '@penxio/api' | ||
|
||
export async function main() { | ||
const res = await request({ | ||
method: 'GET', | ||
url: 'https://jsonplaceholder.typicode.com/todos/1', | ||
}) | ||
|
||
const md = new MarkdownBuilder(JSON.stringify(res.data, null, 2)) | ||
render(md) | ||
} | ||
``` | ||
|
||
### POST | ||
|
||
To send a POST request: | ||
|
||
```ts | ||
import { MarkdownBuilder, request } from '@penxio/api' | ||
|
||
export async function main() { | ||
const res = await request({ | ||
method: 'POST', | ||
url: 'https://jsonplaceholder.typicode.com/psots', | ||
json: { | ||
title: 'This is a title', | ||
content: 'foo...', | ||
}, | ||
}) | ||
import { fetch } from '@penxio/api' | ||
|
||
const md = new MarkdownBuilder(JSON.stringify(res.data, null, 2)) | ||
render(md) | ||
} | ||
fetch('https://jsonplaceholder.typicode.com/todos/1').then(console.log) | ||
fetch('https://jsonplaceholder.typicode.com/posts', { | ||
method: 'POST', | ||
}).then(console.log) | ||
``` | ||
|
||
Of course, You can other methods like: PUT, PATCH, DELETE.. |
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,14 @@ | ||
# Notification | ||
|
||
Display system notification. | ||
|
||
https://penx-api.penx.io/interfaces/INotification.html | ||
|
||
```ts | ||
import { notification } from '@penxio/api' | ||
|
||
const permissionGranted = await notification.isPermissionGranted() | ||
if (permissionGranted) { | ||
await notification.sendNotification('Hello from Penx') | ||
} | ||
``` |
Oops, something went wrong.