mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 15:56:51 +00:00
refactor(core): move process endpoints to plugins-workspace (#6905)
This commit is contained in:
parent
c4171152c1
commit
60cf9ed2fc
6
.changes/move-process.md
Normal file
6
.changes/move-process.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"api": patch
|
||||
"tauri": patch
|
||||
---
|
||||
|
||||
Moved the `process` feature to its own plugin in the plugins-workspace repository.
|
||||
File diff suppressed because one or more lines are too long
@ -13,8 +13,6 @@ use serde_json::Value as JsonValue;
|
||||
use std::sync::Arc;
|
||||
|
||||
mod event;
|
||||
#[cfg(process_any)]
|
||||
mod process;
|
||||
mod window;
|
||||
|
||||
/// The context passed to the invoke handler.
|
||||
@ -51,8 +49,6 @@ impl<T: Serialize> From<T> for InvokeResponse {
|
||||
#[derive(Deserialize)]
|
||||
#[serde(tag = "module", content = "message")]
|
||||
enum Module {
|
||||
#[cfg(process_any)]
|
||||
Process(process::Cmd),
|
||||
Window(Box<window::Cmd>),
|
||||
Event(event::Cmd),
|
||||
}
|
||||
@ -71,13 +67,6 @@ impl Module {
|
||||
package_info,
|
||||
};
|
||||
match self {
|
||||
#[cfg(process_any)]
|
||||
Self::Process(cmd) => resolver.respond_async(async move {
|
||||
cmd
|
||||
.run(context)
|
||||
.and_then(|r| r.json)
|
||||
.map_err(InvokeError::from_anyhow)
|
||||
}),
|
||||
Self::Window(cmd) => resolver.respond_async(async move {
|
||||
cmd
|
||||
.run(context)
|
||||
|
||||
@ -1,58 +0,0 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use super::InvokeContext;
|
||||
#[cfg(process_relaunch)]
|
||||
use crate::Manager;
|
||||
use crate::Runtime;
|
||||
use serde::Deserialize;
|
||||
use tauri_macros::{command_enum, module_command_handler, CommandModule};
|
||||
|
||||
/// The API descriptor.
|
||||
#[command_enum]
|
||||
#[derive(Deserialize, CommandModule)]
|
||||
#[serde(tag = "cmd", rename_all = "camelCase")]
|
||||
pub enum Cmd {
|
||||
/// Relaunch application
|
||||
Relaunch,
|
||||
/// Close application with provided exit_code
|
||||
#[cmd(process_exit, "process > exit")]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
Exit { exit_code: i32 },
|
||||
}
|
||||
|
||||
impl Cmd {
|
||||
#[module_command_handler(process_relaunch)]
|
||||
fn relaunch<R: Runtime>(context: InvokeContext<R>) -> super::Result<()> {
|
||||
context.window.app_handle().restart();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(process_relaunch))]
|
||||
fn relaunch<R: Runtime>(_: InvokeContext<R>) -> super::Result<()> {
|
||||
Err(crate::Error::ApiNotAllowlisted("process > relaunch".into()).into_anyhow())
|
||||
}
|
||||
|
||||
#[module_command_handler(process_exit)]
|
||||
fn exit<R: Runtime>(context: InvokeContext<R>, exit_code: i32) -> super::Result<()> {
|
||||
// would be great if we can have a handler inside tauri
|
||||
// who close all window and emit an event that user can catch
|
||||
// if they want to process something before closing the app
|
||||
context.window.app_handle.exit(exit_code);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[tauri_macros::module_command_test(process_relaunch, "process > relaunch", runtime)]
|
||||
#[quickcheck_macros::quickcheck]
|
||||
fn relaunch() {}
|
||||
|
||||
#[tauri_macros::module_command_test(process_exit, "process > exit")]
|
||||
#[quickcheck_macros::quickcheck]
|
||||
fn exit(_exit_code: i32) {}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@ -15,7 +15,6 @@
|
||||
|
||||
import * as event from './event'
|
||||
import * as path from './path'
|
||||
import * as process from './process'
|
||||
import * as tauri from './tauri'
|
||||
import * as updater from './updater'
|
||||
import * as window from './window'
|
||||
@ -23,4 +22,4 @@ import * as window from './window'
|
||||
/** @ignore */
|
||||
const invoke = tauri.invoke
|
||||
|
||||
export { invoke, event, path, process, tauri, updater, window }
|
||||
export { invoke, event, path, tauri, updater, window }
|
||||
|
||||
@ -1,58 +0,0 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/**
|
||||
* Perform operations on the current process.
|
||||
*
|
||||
* This package is also accessible with `window.__TAURI__.process` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
|
||||
* @module
|
||||
*/
|
||||
|
||||
import { invokeTauriCommand } from './helpers/tauri'
|
||||
|
||||
/**
|
||||
* Exits immediately with the given `exitCode`.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { exit } from '@tauri-apps/api/process';
|
||||
* await exit(1);
|
||||
* ```
|
||||
*
|
||||
* @param exitCode The exit code to use.
|
||||
* @returns A promise indicating the success or failure of the operation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
async function exit(exitCode: number = 0): Promise<void> {
|
||||
return invokeTauriCommand({
|
||||
__tauriModule: 'Process',
|
||||
message: {
|
||||
cmd: 'exit',
|
||||
exitCode
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the current instance of the app then relaunches it.
|
||||
* @example
|
||||
* ```typescript
|
||||
* import { relaunch } from '@tauri-apps/api/process';
|
||||
* await relaunch();
|
||||
* ```
|
||||
*
|
||||
* @returns A promise indicating the success or failure of the operation.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
async function relaunch(): Promise<void> {
|
||||
return invokeTauriCommand({
|
||||
__tauriModule: 'Process',
|
||||
message: {
|
||||
cmd: 'relaunch'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export { exit, relaunch }
|
||||
Loading…
Reference in New Issue
Block a user