Skip to content

Commit

Permalink
general updates
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Lewis <[email protected]>
  • Loading branch information
lorenzolewis committed Aug 20, 2023
1 parent 1d1421f commit b0225a4
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 149 deletions.
49 changes: 25 additions & 24 deletions src/components/list/Guides.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,36 @@ import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { type CollectionEntry, getEntry } from 'astro:content';
const entries = [
'2/guide/authenticator',
'2/guide/autostart',
'2/guide/localhost',
'2/guide/persisted-scope',
'2/guide/positioner',
'2/guide/single-instance',
'2/guide/sql',
'2/guide/store',
'2/guide/stronghold',
'2/guide/upload',
'2/guide/websocket',
'2/guide/window-state',
'2/guide/authenticator',
'2/guide/autostart',
'2/guide/localhost',
'2/guide/notification',
'2/guide/persisted-scope',
'2/guide/positioner',
'2/guide/single-instance',
'2/guide/sql',
'2/guide/store',
'2/guide/stronghold',
'2/guide/upload',
'2/guide/websocket',
'2/guide/window-state',
];
const list = (await Promise.all(
entries.flatMap((entry) => getEntry('docs', entry))
entries.flatMap((entry) => getEntry('docs', entry))
)) as CollectionEntry<'docs'>[];
---

<CardGrid>
{
list
.sort((a, b) => a.data.title.localeCompare(b.data.title))
.map((item) => (
<LinkCard
title={item.data.title}
href={`/${item.slug}`}
description={item.data.description}
/>
))
}
{
list
.sort((a, b) => a.data.title.localeCompare(b.data.title))
.map((item) => (
<LinkCard
title={item.data.title}
href={`/${item.slug}`}
description={item.data.description}
/>
))
}
</CardGrid>
26 changes: 13 additions & 13 deletions src/components/list/Recipes.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
import { LinkCard, CardGrid } from '@astrojs/starlight/components';
import { type CollectionEntry, getEntry } from 'astro:content';
const entries = ['2/guide/recipe/notifications'];
const entries = ['2/guide/recipe/stub'];
const list = (await Promise.all(
entries.flatMap((entry) => getEntry('docs', entry))
entries.flatMap((entry) => getEntry('docs', entry))
)) as CollectionEntry<'docs'>[];
---

<CardGrid>
{
list
.sort((a, b) => a.data.title.localeCompare(b.data.title))
.map((item) => (
<LinkCard
title={item.data.title}
href={`/${item.slug}`}
description={item.data.description}
/>
))
}
{
list
.sort((a, b) => a.data.title.localeCompare(b.data.title))
.map((item) => (
<LinkCard
title={item.data.title}
href={`/${item.slug}`}
description={item.data.description}
/>
))
}
</CardGrid>
101 changes: 101 additions & 0 deletions src/content/docs/2/guide/notification.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
title: Notification
description: Send user notifications. Can also be used with the Notification Web API.
---

import { Tabs, TabItem } from '@astrojs/starlight/components';

Send user notifications using the operating system's native notifications using `tauri-plugin-notification`.

{/* TODO: Add demo here */}
{/* ## Preview */}

## Setup

Install the plugin automatically using the Tauri CLI (recommended) or manually:

<Tabs>
<TabItem label="Automatic">
```bash
tauri plugin add notification
```
</TabItem>
<TabItem label="Manual">

`Cargo.toml`

```toml
[dependencies]
tauri-plugin-notification = "2.0.0-alpha"
```

{/* TODO: 2.0 */}

`lib.rs`

```rust
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
// Initialize the plugin
.plugin(tauri_plugin_notification::init())
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
```

{/* TODO: add package.json if using node */}

</TabItem>

</Tabs>

## Usage

You can use notifications in both JavaScript and Rust. Usage in both is similar where you should:

1. Check if the user has granted notification permission
2. Request permission if not granted
3. Send the notification

### JavaScript

```js
import {
isPermissionGranted,
requestPermission,
sendNotification,
} from '@tauri-apps/plugin-notification';

// Do you have permission to send a notification?
let permissionGranted = await isPermissionGranted();

// If not we need to request it
if (!permissionGranted) {
const permission = await requestPermission();
permissionGranted = permission === 'granted';
}

// Once permission has been granted we can send the notification
if (permissionGranted) {
sendNotification({ title: 'Tauri', body: 'Tauri is awesome!' });
}
```

### Rust

{/* TODO: Cover checking and requesting permission? */}

```rust
use tauri_plugin_notification::Notification;

#[tauri::command]
async fn notify(app: AppHandle) -> Result<(), ()> {
Notification::new(&app.config().tauri.bundle.identifier)
.title("Tauri")
.body("Tauri is awesome!")
.show()
}
```

{/* Could a troubleshooting/common issues section be useful to have on all of these pages? */}
112 changes: 0 additions & 112 deletions src/content/docs/2/guide/recipe/notifications.mdx

This file was deleted.

0 comments on commit b0225a4

Please sign in to comment.