mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-11 05:57:07 +03:00
This commit is contained in:
parent
a0a2d86565
commit
660a2d87d6
7
.changes/taurijs_move_api_types_into_api.md
Normal file
7
.changes/taurijs_move_api_types_into_api.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
"tauri.js": minor
|
||||
---
|
||||
|
||||
Move types exported in the `tauri` js api into the modules that use them. For
|
||||
example, `Event` is now available from `tauri/api/event` instead of
|
||||
`tauri/api/types/event`.
|
@ -1,6 +1,28 @@
|
||||
import { CliMatches } from './types/cli'
|
||||
import { promisified } from './tauri'
|
||||
|
||||
export interface ArgMatch {
|
||||
/**
|
||||
* string if takes value
|
||||
* boolean if flag
|
||||
* string[] or null if takes multiple values
|
||||
*/
|
||||
value: string | boolean | string[] | null
|
||||
/**
|
||||
* number of occurrences
|
||||
*/
|
||||
occurrences: number
|
||||
}
|
||||
|
||||
export interface SubcommandMatch {
|
||||
name: string
|
||||
matches: CliMatches
|
||||
}
|
||||
|
||||
export interface CliMatches {
|
||||
args: { [name: string]: ArgMatch }
|
||||
subcommand: SubcommandMatch | null
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the CLI matches
|
||||
*/
|
||||
|
@ -1,6 +1,14 @@
|
||||
import { OpenDialogOptions, SaveDialogOptions } from './types/dialog'
|
||||
import { promisified } from './tauri'
|
||||
|
||||
export interface OpenDialogOptions {
|
||||
filter?: string
|
||||
defaultPath?: string
|
||||
multiple?: boolean
|
||||
directory?: boolean
|
||||
}
|
||||
|
||||
export type SaveDialogOptions = Pick<OpenDialogOptions, 'filter' | 'defaultPath'>
|
||||
|
||||
/**
|
||||
* @name openDialog
|
||||
* @description Open a file/directory selection dialog
|
||||
|
@ -1,5 +1,11 @@
|
||||
import { invoke, transformCallback } from './tauri'
|
||||
import { EventCallback } from './types/event'
|
||||
|
||||
export interface Event<T> {
|
||||
type: string
|
||||
payload: T
|
||||
}
|
||||
|
||||
export type EventCallback<T> = (event: Event<T>) => void
|
||||
|
||||
/**
|
||||
* listen to an event from the backend
|
||||
|
@ -1,5 +1,48 @@
|
||||
import { promisified } from './tauri'
|
||||
import { BaseDirectory, FsOptions, FsTextFileOption, FsBinaryFileOption, FileEntry } from './types/fs'
|
||||
|
||||
export enum BaseDirectory {
|
||||
Audio = 1,
|
||||
Cache,
|
||||
Config,
|
||||
Data,
|
||||
LocalData,
|
||||
Desktop,
|
||||
Document,
|
||||
Download,
|
||||
Executable,
|
||||
Font,
|
||||
Home,
|
||||
Picture,
|
||||
Public,
|
||||
Runtime,
|
||||
Template,
|
||||
Video,
|
||||
Resource,
|
||||
App,
|
||||
}
|
||||
|
||||
export interface FsOptions {
|
||||
dir?: BaseDirectory
|
||||
}
|
||||
|
||||
export interface FsTextFileOption {
|
||||
path: string
|
||||
contents: string
|
||||
}
|
||||
|
||||
export interface FsBinaryFileOption {
|
||||
path: string
|
||||
contents: ArrayBuffer
|
||||
}
|
||||
|
||||
export interface FileEntry {
|
||||
path: string
|
||||
// name of the directory/file
|
||||
// can be null if the path terminates with `..`
|
||||
name?: string
|
||||
// children of this entry if it's a directory; null otherwise
|
||||
children?: FileEntry[]
|
||||
}
|
||||
|
||||
/**
|
||||
* reads a file as text
|
||||
|
@ -1,5 +1,38 @@
|
||||
import { promisified } from './tauri'
|
||||
import { HttpOptions, Body, BodyType, ResponseType, PartialOptions } from './types/http'
|
||||
|
||||
export enum ResponseType {
|
||||
JSON = 1,
|
||||
Text = 2,
|
||||
Binary = 3
|
||||
}
|
||||
|
||||
export enum BodyType {
|
||||
Form = 1,
|
||||
File = 2,
|
||||
Auto = 3
|
||||
}
|
||||
|
||||
export type Body = object | string | BinaryType
|
||||
|
||||
export type HttpVerb = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE'
|
||||
|
||||
export interface HttpOptions {
|
||||
method: HttpVerb
|
||||
url: string
|
||||
headers?: Record<string, any>
|
||||
params?: Record<string, any>
|
||||
body?: Body
|
||||
followRedirects: boolean
|
||||
maxRedirections: boolean
|
||||
connectTimeout: number
|
||||
readTimeout: number
|
||||
timeout: number
|
||||
allowCompression: boolean
|
||||
responseType?: ResponseType
|
||||
bodyType: BodyType
|
||||
}
|
||||
|
||||
export type PartialOptions = Omit<HttpOptions, 'method' | 'url'>
|
||||
|
||||
/**
|
||||
* makes a HTTP request
|
||||
|
@ -1,6 +1,14 @@
|
||||
import { Options, Permission } from './types/notification'
|
||||
import { promisified } from './tauri'
|
||||
|
||||
export interface Options {
|
||||
title: string
|
||||
body?: string
|
||||
icon?: string
|
||||
}
|
||||
|
||||
export type PartialOptions = Omit<Options, 'title'>
|
||||
export type Permission = 'granted' | 'denied' | 'default'
|
||||
|
||||
async function isPermissionGranted(): Promise<boolean | null> {
|
||||
if (window.Notification.permission !== 'default') {
|
||||
return await Promise.resolve(window.Notification.permission === 'granted')
|
||||
|
@ -1,22 +0,0 @@
|
||||
export interface ArgMatch {
|
||||
/**
|
||||
* string if takes value
|
||||
* boolean if flag
|
||||
* string[] or null if takes multiple values
|
||||
*/
|
||||
value: string | boolean | string[] | null
|
||||
/**
|
||||
* number of occurrences
|
||||
*/
|
||||
occurrences: number
|
||||
}
|
||||
|
||||
export interface SubcommandMatch {
|
||||
name: string
|
||||
matches: CliMatches
|
||||
}
|
||||
|
||||
export interface CliMatches {
|
||||
args: { [name: string]: ArgMatch }
|
||||
subcommand: SubcommandMatch | null
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
export interface OpenDialogOptions {
|
||||
filter?: string
|
||||
defaultPath?: string
|
||||
multiple?: boolean
|
||||
directory?: boolean
|
||||
}
|
||||
|
||||
export type SaveDialogOptions = Pick<OpenDialogOptions, 'filter' | 'defaultPath'>
|
@ -1,6 +0,0 @@
|
||||
export interface Event<T> {
|
||||
type: string
|
||||
payload: T
|
||||
}
|
||||
|
||||
export type EventCallback<T> = (event: Event<T>) => void
|
@ -1,43 +0,0 @@
|
||||
export enum BaseDirectory {
|
||||
Audio = 1,
|
||||
Cache,
|
||||
Config,
|
||||
Data,
|
||||
LocalData,
|
||||
Desktop,
|
||||
Document,
|
||||
Download,
|
||||
Executable,
|
||||
Font,
|
||||
Home,
|
||||
Picture,
|
||||
Public,
|
||||
Runtime,
|
||||
Template,
|
||||
Video,
|
||||
Resource,
|
||||
App,
|
||||
}
|
||||
|
||||
export interface FsOptions {
|
||||
dir?: BaseDirectory
|
||||
}
|
||||
|
||||
export interface FsTextFileOption {
|
||||
path: string
|
||||
contents: string
|
||||
}
|
||||
|
||||
export interface FsBinaryFileOption {
|
||||
path: string
|
||||
contents: ArrayBuffer
|
||||
}
|
||||
|
||||
export interface FileEntry {
|
||||
path: string
|
||||
// name of the directory/file
|
||||
// can be null if the path terminates with `..`
|
||||
name?: string
|
||||
// children of this entry if it's a directory; null otherwise
|
||||
children?: FileEntry[]
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
export enum ResponseType {
|
||||
JSON = 1,
|
||||
Text = 2,
|
||||
Binary = 3
|
||||
}
|
||||
|
||||
export enum BodyType {
|
||||
Form = 1,
|
||||
File = 2,
|
||||
Auto = 3
|
||||
}
|
||||
|
||||
export type Body = object | string | BinaryType
|
||||
|
||||
export type HttpVerb = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | 'CONNECT' | 'TRACE'
|
||||
|
||||
export interface HttpOptions {
|
||||
method: HttpVerb
|
||||
url: string
|
||||
headers?: Record<string, any>
|
||||
params?: Record<string, any>
|
||||
body?: Body
|
||||
followRedirects: boolean
|
||||
maxRedirections: boolean
|
||||
connectTimeout: number
|
||||
readTimeout: number
|
||||
timeout: number
|
||||
allowCompression: boolean
|
||||
responseType?: ResponseType
|
||||
bodyType: BodyType
|
||||
}
|
||||
|
||||
export type PartialOptions = Omit<HttpOptions, 'method' | 'url'>
|
@ -1,8 +0,0 @@
|
||||
export interface Options {
|
||||
title: string
|
||||
body?: string
|
||||
icon?: string
|
||||
}
|
||||
|
||||
export type PartialOptions = Omit<Options, 'title'>
|
||||
export type Permission = 'granted' | 'denied' | 'default'
|
Loading…
Reference in New Issue
Block a user