chore(desktop): Question Tools Updates
This commit is contained in:
@@ -161,53 +161,64 @@ export default function Layout(props: ParentProps) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
const alerts = {
|
||||||
|
"permission.asked": {
|
||||||
|
title: "Permission required",
|
||||||
|
icon: "checklist" as const,
|
||||||
|
description: (sessionTitle: string, projectName: string) =>
|
||||||
|
`${sessionTitle} in ${projectName} needs permission`,
|
||||||
|
},
|
||||||
|
"question.asked": {
|
||||||
|
title: "Question",
|
||||||
|
icon: "bubble-5" as const,
|
||||||
|
description: (sessionTitle: string, projectName: string) => `${sessionTitle} in ${projectName} has a question`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
const toastBySession = new Map<string, number>()
|
const toastBySession = new Map<string, number>()
|
||||||
const alertedAtBySession = new Map<string, number>()
|
const alertedAtBySession = new Map<string, number>()
|
||||||
const permissionAlertCooldownMs = 5000
|
const cooldownMs = 5000
|
||||||
|
|
||||||
const unsub = globalSDK.event.listen((e) => {
|
const unsub = globalSDK.event.listen((e) => {
|
||||||
if (e.details?.type !== "permission.asked") return
|
if (e.details?.type !== "permission.asked" && e.details?.type !== "question.asked") return
|
||||||
|
const config = alerts[e.details.type]
|
||||||
const directory = e.name
|
const directory = e.name
|
||||||
const perm = e.details.properties
|
const props = e.details.properties
|
||||||
if (permission.autoResponds(perm, directory)) return
|
if (e.details.type === "permission.asked" && permission.autoResponds(e.details.properties, directory)) return
|
||||||
|
|
||||||
const [store] = globalSync.child(directory)
|
const [store] = globalSync.child(directory)
|
||||||
const session = store.session.find((s) => s.id === perm.sessionID)
|
const session = store.session.find((s) => s.id === props.sessionID)
|
||||||
const sessionKey = `${directory}:${perm.sessionID}`
|
const sessionKey = `${directory}:${props.sessionID}`
|
||||||
|
|
||||||
const sessionTitle = session?.title ?? "New session"
|
const sessionTitle = session?.title ?? "New session"
|
||||||
const projectName = getFilename(directory)
|
const projectName = getFilename(directory)
|
||||||
const description = `${sessionTitle} in ${projectName} needs permission`
|
const description = config.description(sessionTitle, projectName)
|
||||||
const href = `/${base64Encode(directory)}/session/${perm.sessionID}`
|
const href = `/${base64Encode(directory)}/session/${props.sessionID}`
|
||||||
|
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
const lastAlerted = alertedAtBySession.get(sessionKey) ?? 0
|
const lastAlerted = alertedAtBySession.get(sessionKey) ?? 0
|
||||||
if (now - lastAlerted < permissionAlertCooldownMs) return
|
if (now - lastAlerted < cooldownMs) return
|
||||||
alertedAtBySession.set(sessionKey, now)
|
alertedAtBySession.set(sessionKey, now)
|
||||||
|
|
||||||
void platform.notify("Permission required", description, href)
|
void platform.notify(config.title, description, href)
|
||||||
|
|
||||||
const currentDir = params.dir ? base64Decode(params.dir) : undefined
|
const currentDir = params.dir ? base64Decode(params.dir) : undefined
|
||||||
const currentSession = params.id
|
const currentSession = params.id
|
||||||
if (directory === currentDir && perm.sessionID === currentSession) return
|
if (directory === currentDir && props.sessionID === currentSession) return
|
||||||
if (directory === currentDir && session?.parentID === currentSession) return
|
if (directory === currentDir && session?.parentID === currentSession) return
|
||||||
|
|
||||||
const existingToastId = toastBySession.get(sessionKey)
|
const existingToastId = toastBySession.get(sessionKey)
|
||||||
if (existingToastId !== undefined) {
|
if (existingToastId !== undefined) toaster.dismiss(existingToastId)
|
||||||
toaster.dismiss(existingToastId)
|
|
||||||
}
|
|
||||||
|
|
||||||
const toastId = showToast({
|
const toastId = showToast({
|
||||||
persistent: true,
|
persistent: true,
|
||||||
icon: "checklist",
|
icon: config.icon,
|
||||||
title: "Permission required",
|
title: config.title,
|
||||||
description,
|
description,
|
||||||
actions: [
|
actions: [
|
||||||
{
|
{
|
||||||
label: "Go to session",
|
label: "Go to session",
|
||||||
onClick: () => {
|
onClick: () => navigate(href),
|
||||||
navigate(href)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Dismiss",
|
label: "Dismiss",
|
||||||
|
|||||||
@@ -416,7 +416,30 @@
|
|||||||
box-shadow: var(--shadow-xs-border-base);
|
box-shadow: var(--shadow-xs-border-base);
|
||||||
background-color: var(--surface-raised-base);
|
background-color: var(--surface-raised-base);
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
|
overflow-anchor: none;
|
||||||
|
|
||||||
|
& > *:first-child {
|
||||||
|
border-top-left-radius: 6px;
|
||||||
|
border-top-right-radius: 6px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
& > *:last-child {
|
||||||
|
border-bottom-left-radius: 6px;
|
||||||
|
border-bottom-right-radius: 6px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-component="collapsible"] {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-component="card"] {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&[data-permission="true"] {
|
||||||
&::before {
|
&::before {
|
||||||
content: "";
|
content: "";
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -438,26 +461,11 @@
|
|||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
z-index: -1;
|
z-index: -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
& > *:first-child {
|
&[data-question="true"] {
|
||||||
border-top-left-radius: 6px;
|
background: var(--background-base);
|
||||||
border-top-right-radius: 6px;
|
border: 1px solid var(--border-base);
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
& > *:last-child {
|
|
||||||
border-bottom-left-radius: 6px;
|
|
||||||
border-bottom-right-radius: 6px;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
[data-component="collapsible"] {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
[data-component="card"] {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user