Sync source to CNB / Sync Git ref (push) Skipped
将崩溃弹窗替换为双栏布局:左侧展示诊断摘要与分享入口, 右侧提供日志文件浏览器与 LogAgent 流式分析输出。 - MinecraftCrashModal 改用新版的分享票据、结构化摘要与 AI 事件流 - 新增 minecraft-crash-logs 工具函数,用于筛选与合并崩溃日志 - 事件层新增 logshare_ai_listener 监听 AI 分析进度 - log-share 工具更新为支持 provider 路由的新版 - Button 组件对齐新版(补 icon-only、circular、2xs 与 chip/highlight 变体) - console 导出 LogViewport,供日志浏览器复用 - 补齐 en-US / zh-CN 相关文案
186 lines
6.0 KiB
JavaScript
186 lines
6.0 KiB
JavaScript
/*
|
|
Event listeners for interacting with the Rust api
|
|
These are all async functions that return a promise that resolves to the payload object (whatever Rust is trying to deliver)
|
|
*/
|
|
|
|
/*
|
|
callback is a function that takes a single argument, which is the payload object (whatever Rust is trying to deliver)
|
|
|
|
You can call these to await any kind of emitted signal from Rust, and then do something with the payload object
|
|
An example place to put this is at the start of main.js before the state is initialized- that way
|
|
you can listen for any emitted signal from Rust and do something with it as the state is being initialized
|
|
|
|
Example:
|
|
import { loading_listener } from '@/helpers/events'
|
|
await loading_listener((event) => {
|
|
// event.event is the event name (useful if you want to use a single callback fn for multiple event types)
|
|
// event.payload is the payload object
|
|
console.log(event)
|
|
})
|
|
|
|
Putting that in a script will print any emitted signal from rust
|
|
*/
|
|
import { listen } from '@tauri-apps/api/event'
|
|
|
|
/// Payload for the 'loading' event
|
|
/*
|
|
LoadingPayload {
|
|
event: {
|
|
type: string, one of "StateInit", "PackDownload", etc
|
|
(Optional fields depending on event type)
|
|
pack_name: name of the pack
|
|
pack_id, optional, the id of the modpack
|
|
pack_version, optional, the version of the modpack
|
|
instance_name: name of the instance
|
|
instance_id: unique identification of the instance
|
|
|
|
}
|
|
loader_uuid: unique identification of the loading bar
|
|
fraction: number, (as a fraction of 1, how much we've loaded so far). If null, by convention, loading is finished
|
|
message: message to display to the user
|
|
}
|
|
*/
|
|
export async function loading_listener(callback) {
|
|
return await listen('loading', (event) => callback(event.payload))
|
|
}
|
|
|
|
/// Payload for the 'process' event
|
|
/*
|
|
ProcessPayload {
|
|
uuid: unique identification of the process in the state (currently identified by PID, but that will change)
|
|
pid: process ID
|
|
event: event type ("Launched", "Finished")
|
|
message: message to display to the user
|
|
crashed: whether a finished process exited unexpectedly
|
|
}
|
|
*/
|
|
export async function process_listener(callback) {
|
|
return await listen('process', (event) => callback(event.payload))
|
|
}
|
|
|
|
/// Payload for the 'instance' event
|
|
/*
|
|
InstancePayload {
|
|
instance_id: unique identification of the instance
|
|
event: event type ("Created", "Added", "Edited", "Removed")
|
|
}
|
|
*/
|
|
export async function instance_listener(callback) {
|
|
return await listen('instance', (event) => callback(event.payload))
|
|
}
|
|
|
|
/// Payload for the 'instance_bulk_update_progress' event
|
|
/*
|
|
InstanceBulkUpdateProgress {
|
|
instanceId: string
|
|
stage: "resolving_versions" | "downloading" | "finishing"
|
|
current: number
|
|
total: number
|
|
}
|
|
*/
|
|
export async function instance_bulk_update_progress_listener(callback) {
|
|
return await listen('instance_bulk_update_progress', (event) => callback(event.payload))
|
|
}
|
|
|
|
/// Payload for the 'instance_groups_changed' event
|
|
/*
|
|
InstanceGroupsChangedPayload {
|
|
instance_ids: string[]
|
|
}
|
|
*/
|
|
export async function instance_groups_listener(callback) {
|
|
return await listen('instance_groups_changed', (event) => callback(event.payload))
|
|
}
|
|
|
|
export async function install_job_listener(callback) {
|
|
return await listen('install_job', (event) => callback(event.payload))
|
|
}
|
|
|
|
export async function import_plan_listener(callback) {
|
|
return await listen('import_plan', (event) => callback(event.payload))
|
|
}
|
|
|
|
export async function drop_classify_progress_listener(callback) {
|
|
return await listen('drop_classify_progress', (event) => callback(event.payload))
|
|
}
|
|
|
|
export async function download_request_listener(callback) {
|
|
return await listen('download_request', (event) => callback(event.payload))
|
|
}
|
|
|
|
/// Payload for the 'command' event
|
|
/*
|
|
CommandPayload {
|
|
event: event type ("InstallMod", "InstallModpack", "InstallVersion"),
|
|
id: string id of the mod/modpack/version to install
|
|
}
|
|
*/
|
|
export async function command_listener(callback) {
|
|
return await listen('command', (event) => {
|
|
callback(event.payload)
|
|
})
|
|
}
|
|
|
|
/// Payload for the 'warning' event
|
|
/*
|
|
WarningPayload {
|
|
message: message to display to the user
|
|
}
|
|
*/
|
|
export async function warning_listener(callback) {
|
|
return await listen('warning', (event) => callback(event.payload))
|
|
}
|
|
|
|
export async function friend_listener(callback) {
|
|
return await listen('friend', (event) => callback(event.payload))
|
|
}
|
|
|
|
/// Payload for the 'java_discovery_update' event
|
|
/*
|
|
JavaDiscoveryPayload {
|
|
count: number of Java installations found by the background rescan
|
|
}
|
|
*/
|
|
export async function java_discovery_listener(callback) {
|
|
return await listen('java_discovery_update', (event) => callback(event.payload))
|
|
}
|
|
|
|
/// Payload for the 'java_download_confirmation' event
|
|
/*
|
|
JavaDownloadConfirmationPayload {
|
|
requestId: unique identifier for the confirmation request
|
|
version: required Java major version
|
|
}
|
|
*/
|
|
export async function java_download_confirmation_listener(callback) {
|
|
return await listen('java_download_confirmation', (event) => callback(event.payload))
|
|
}
|
|
|
|
export async function notification_listener(callback) {
|
|
return await listen('notification', (event) => callback(event.payload))
|
|
}
|
|
|
|
export async function logshare_ai_listener(callback) {
|
|
return await listen('logshare_ai', (event) => callback(event.payload))
|
|
}
|
|
|
|
/// Payload for the 'log' event
|
|
/*
|
|
LogPayload {
|
|
instance_id: string,
|
|
type: "log4j" | "legacy",
|
|
// log4j fields (when type === "log4j"):
|
|
timestamp_millis?: number,
|
|
logger_name?: string,
|
|
level?: string,
|
|
thread_name?: string,
|
|
message?: string,
|
|
throwable?: string,
|
|
// legacy fields (when type === "legacy"):
|
|
message?: string,
|
|
}
|
|
*/
|
|
export async function log_listener(callback) {
|
|
return await listen('log', (event) => callback(event.payload))
|
|
}
|