Skip to content

Commit 0e4ed35

Browse files
committed
Fix conversation controls
1 parent 5045a10 commit 0e4ed35

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

css/browser.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ body::-webkit-scrollbar {
102102
}
103103

104104
/* A utility class for temporarily hiding all dropdown menus */
105-
html.hide-dropdowns [role='menu'].l9j0dhe7.swg4t2nn {
105+
html.hide-dropdowns [role='menu'].x1n2onr6.xi5betq {
106106
visibility: hidden !important;
107107
}
108108

source/browser.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ async function withMenu(
2121
menuButtonElement.click();
2222

2323
// Wait for the menu to close before removing the 'hide-dropdowns' class
24-
const menuLayer = document.querySelector('.j83agx80.cbu4d94t.l9j0dhe7.jgljxmt5.be9z9djy > div:nth-child(2) > div');
24+
await elementReady('.x78zum5.xdt5ytf.x1n2onr6.xat3117.xxzkxad > div:nth-child(2) > div', {stopOnDomReady: false});
25+
const menuLayer = document.querySelector('.x78zum5.xdt5ytf.x1n2onr6.xat3117.xxzkxad > div:nth-child(2) > div');
2526

2627
if (menuLayer) {
2728
const observer = new MutationObserver(() => {
@@ -228,11 +229,11 @@ ipc.answerMain('delete-conversation', async () => {
228229
await deleteSelectedConversation();
229230
});
230231

231-
ipc.answerMain('hide-conversation', async () => {
232+
ipc.answerMain('archive-conversation', async () => {
232233
const index = selectedConversationIndex();
233234

234235
if (index !== -1) {
235-
await hideSelectedConversation();
236+
await archiveSelectedConversation();
236237

237238
const key = index + 1;
238239
await jumpToConversation(key);
@@ -594,7 +595,7 @@ function selectedConversationIndex(offset = 0): number {
594595
return -1;
595596
}
596597

597-
const newSelected = selected.parentNode!.parentNode!.parentNode! as HTMLElement;
598+
const newSelected = selected.closest(`${selectors.conversationList} > div`)!;
598599

599600
const list = [...newSelected.parentNode!.children];
600601
const index = list.indexOf(newSelected) + offset;
@@ -611,7 +612,7 @@ async function setZoom(zoomFactor: number): Promise<void> {
611612
async function withConversationMenu(callback: () => void): Promise<void> {
612613
// eslint-disable-next-line @typescript-eslint/ban-types
613614
let menuButton: HTMLElement | null = null;
614-
const conversation = document.querySelector<HTMLElement>(`${selectors.selectedConversation}`)?.parentElement?.parentElement?.parentElement?.parentElement;
615+
const conversation = document.querySelector<HTMLElement>(selectors.selectedConversation)!.closest(`${selectors.conversationList} > div`);
615616

616617
menuButton = conversation?.querySelector('[aria-label=Menu][role=button]') ?? null;
617618

@@ -637,16 +638,16 @@ function isSelectedConversationGroup(): boolean {
637638
return Boolean(document.querySelector<HTMLElement>(`${selectors.conversationMenuSelectorNewDesign} [role=menuitem]:nth-child(4)`));
638639
}
639640

640-
async function hideSelectedConversation(): Promise<void> {
641+
async function archiveSelectedConversation(): Promise<void> {
641642
await withConversationMenu(() => {
642-
const [isGroup, isNotGroup] = [5, 6];
643+
const [isGroup, isNotGroup] = [-4, -3];
643644
selectMenuItem(isSelectedConversationGroup() ? isGroup : isNotGroup);
644645
});
645646
}
646647

647648
async function deleteSelectedConversation(): Promise<void> {
648649
await withConversationMenu(() => {
649-
const [isGroup, isNotGroup] = [6, 7];
650+
const [isGroup, isNotGroup] = [-3, -2];
650651
selectMenuItem(isSelectedConversationGroup() ? isGroup : isNotGroup);
651652
});
652653
}

source/browser/selectors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default {
1717
userMenu: '.qi72231t.o9w3sbdw.nu7423ey.tav9wjvu.flwp5yud.tghlliq5.gkg15gwv.s9ok87oh.s9ljgwtm.lxqftegz.bf1zulr9.frfouenu.bonavkto.djs4p424.r7bn319e.bdao358l.fsf7x5fv.tgm57n0e.jez8cy9q.s5oniofx.m8h3af8h.l7ghb35v.kjdc1dyq.kmwttqpk.dnr7xe2t.aeinzg81.srn514ro.oxkhqvkx.rl78xhln.nch0832m.om3e55n1.cr00lzj9.rn8ck1ys.s3jn8y49.g4tp4svg.o9erhkwx.dzqi5evh.hupbnkgi.hvb2xoa8.fxk3tzhb.jl2a5g8c.f14ij5to.l3ldwz01.icdlwmnq > .aglvbi8b.om3e55n1.i8zpp7h3.g4tp4svg',
1818
userMenuNewSidebar: '[role=navigation] > div > div:nth-child(2) > div > div > div:nth-child(1) [role=button]',
1919
viewsMenu: '.x9f619.x1n2onr6.x1ja2u2z.x78zum5.xdt5ytf.x2lah0s.x193iq5w.xurb0ha.x1sxyh0.xdj266r',
20-
selectedConversation: '[role=navigation] [role=grid] [role=row] [role=gridcell] [role=link][aria-current]',
20+
selectedConversation: '[role=navigation] [role=grid] [role=row] [role=gridcell] [role=link][aria-current=page]',
2121
// ! Very fragile selector (most likely cause of hidden dialog issue)
2222
preferencesSelector: 'div[role=dialog][class="x1n2onr6 x1ja2u2z x1afcbsf x78zum5 xdt5ytf x1a2a7pz x6ikm8r x10wlt62 x71s49j x1jx94hy x1g2kw80 xxadwq3 x16n5opg x3hh19s xl7ujzl x1kl8bxo xhkep3z xb3b7hn xwhkkir xeb55yp x17omtbh"]',
2323
// TODO: Fix this selector for new design

source/menu.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -584,45 +584,35 @@ Press Command/Ctrl+R in Caprine to see your changes.
584584

585585
const conversationSubmenu: MenuItemConstructorOptions[] = [
586586
{
587-
/* TODO: Fix conversation controls */
588587
label: 'Mute Conversation',
589-
visible: is.development,
590588
accelerator: 'CommandOrControl+Shift+M',
591589
click() {
592590
sendAction('mute-conversation');
593591
},
594592
},
595593
{
596-
/* TODO: Fix conversation controls */
597-
label: 'Hide Conversation',
598-
visible: is.development,
594+
label: 'Archive Conversation',
599595
accelerator: 'CommandOrControl+Shift+H',
600596
click() {
601-
sendAction('hide-conversation');
597+
sendAction('archive-conversation');
602598
},
603599
},
604600
{
605-
/* TODO: Fix conversation controls */
606601
label: 'Delete Conversation',
607-
visible: is.development,
608602
accelerator: 'CommandOrControl+Shift+D',
609603
click() {
610604
sendAction('delete-conversation');
611605
},
612606
},
613607
{
614-
/* TODO: Fix conversation controls */
615608
label: 'Select Next Conversation',
616-
visible: is.development,
617609
accelerator: 'Control+Tab',
618610
click() {
619611
sendAction('next-conversation');
620612
},
621613
},
622614
{
623-
/* TODO: Fix conversation controls */
624615
label: 'Select Previous Conversation',
625-
visible: is.development,
626616
accelerator: 'Control+Shift+Tab',
627617
click() {
628618
sendAction('previous-conversation');
@@ -637,7 +627,6 @@ Press Command/Ctrl+R in Caprine to see your changes.
637627
},
638628
{
639629
label: 'Search in Conversation',
640-
visible: is.development,
641630
accelerator: 'CommandOrControl+F',
642631
click() {
643632
sendAction('search');

0 commit comments

Comments
 (0)