Skip to content

Commit

Permalink
Merge branch 'main' into fix/preferences-opens-on-start
Browse files Browse the repository at this point in the history
  • Loading branch information
meszarosdezso authored Feb 9, 2021
2 parents e0ae051 + 0e5175b commit fcbac87
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 28 deletions.
4 changes: 4 additions & 0 deletions css/new-design/browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ html.hide-preferences-window [data-pagelet=root] > div > div:last-child {
display: none;
opacity: 0;
visibility: hidden;

/* A utility class for temporarily hiding right sidebar */
html.hide-r-sidebar .rq0escxv.l9j0dhe7.du4w35lb.j83agx80.g5gj957u.rj1gh0hx.buofh1pr.hpfvmrgz.i1fnvgqd.gs1a9yip.owycx6da.btwxx1t3.jb3vyjys.nwf6jgls > div:nth-child(2) {
display: none;
}

/* Dragable region for macOS */
Expand Down
9 changes: 8 additions & 1 deletion css/new-design/dark-mode.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@
}

/* Right sidebar: Icon color */
.rq0escxv.l9j0dhe7.du4w35lb.j83agx80.cbu4d94t.g5gj957u.f4tghd1a.ifue306u.kuivcneq.t63ysoy8 .a8c37x1j.ms05siws.hwsy1cff.b7h9ocf4 {
.rq0escxv.l9j0dhe7.du4w35lb.j83agx80.cbu4d94t.g5gj957u.f4tghd1a.ifue306u.kuivcneq.t63ysoy8
[role=button] svg {
fill: currentColor;
color: var(--primary-text);
}
/* Right sidebar: search icon */
.rq0escxv.l9j0dhe7.du4w35lb.j83agx80.cbu4d94t.g5gj957u.f4tghd1a.ifue306u.kuivcneq.t63ysoy8
[role=button] svg[role=presentation] path {
fill: currentColor;
color: var(--primary-text);
}
Expand Down
45 changes: 43 additions & 2 deletions source/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,49 @@ ipc.answerMain('find', () => {
searchBox!.focus();
});

ipc.answerMain('search', () => {
document.querySelector<HTMLElement>('._3szo:nth-of-type(1)')!.click();
async function openSearchInConversation() {
const mainView = document.querySelector('.rq0escxv.l9j0dhe7.du4w35lb.j83agx80.g5gj957u.rj1gh0hx.buofh1pr.hpfvmrgz.i1fnvgqd.gs1a9yip.owycx6da.btwxx1t3.jb3vyjys.nwf6jgls')!;
const rightSidebarIsClosed = Boolean(mainView.querySelector<HTMLElement>('div:only-child'));

if (rightSidebarIsClosed) {
document.documentElement.classList.add('hide-r-sidebar');
document.querySelector<HTMLElement>('[aria-label="Conversation Information"]')?.click();
}

await elementReady<HTMLElement>(selectors.rightSidebarButtons, {stopOnDomReady: false});
const buttonList = document.querySelectorAll<HTMLElement>(selectors.rightSidebarButtons);
console.log(buttonList);

if (buttonList.length > 4) {
buttonList[4].click();
}

// If right sidebar was closed when shortcut was clicked, then close it back.
if (rightSidebarIsClosed) {
document.querySelector<HTMLElement>('[aria-label="Conversation Information"]')?.click();

// Observe sidebar so when it's hidden, remove the utility class. This prevents split
// display of sidebar.
const sidebarObserver = new MutationObserver(records => {
const removedRecords = records.filter(({removedNodes}) => removedNodes.length > 0 && (removedNodes[0] as HTMLElement).tagName === 'DIV');

// In case there is a div removed, hide utility class and stop observing
if (removedRecords.length > 0) {
document.documentElement.classList.remove('hide-r-sidebar');
sidebarObserver.disconnect();
}
});

sidebarObserver.observe(mainView, {childList: true, subtree: true});
}
}

ipc.answerMain('search', (isNewDesign: boolean) => {
if (isNewDesign) {
openSearchInConversation();
} else {
document.querySelector<HTMLElement>('._3szo:nth-of-type(1)')!.click();
}
});

ipc.answerMain('insert-gif', () => {
Expand Down
3 changes: 2 additions & 1 deletion source/browser/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export default {
conversationListNewDesign: '[role=navigation] [role=grid]',
conversationSelector: '._4u-c._1wfr .__i_, ._4u-c._1wfr #conversationWindow',
conversationSelectorNewDesign: '[aria-label=Messages]',
notificationCheckbox: '._374b:nth-of-type(4) ._4ng2 input'
notificationCheckbox: '._374b:nth-of-type(4) ._4ng2 input',
rightSidebarButtons: '.rq0escxv.l9j0dhe7.du4w35lb.j83agx80.cbu4d94t.g5gj957u.f4tghd1a.ifue306u.kuivcneq.t63ysoy8 [role=button]'
};
30 changes: 6 additions & 24 deletions source/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ Press Command/Ctrl+R in Caprine to see your changes.

const spellCheckerSubmenu: MenuItemConstructorOptions[] = getSpellCheckerLanguages();

const conversationOptionsSubmenu: MenuItemConstructorOptions[] = [
const conversationSubmenu: MenuItemConstructorOptions[] = [
{
label: 'Mute Conversation',
accelerator: 'CommandOrControl+Shift+M',
Expand Down Expand Up @@ -561,33 +561,21 @@ Press Command/Ctrl+R in Caprine to see your changes.
},
{
type: 'separator'
}
];

const conversationSearchOptionsSubmenu: MenuItemConstructorOptions[] = [
},
{
label: 'Find Conversation',
accelerator: 'CommandOrControl+K',
click() {
sendAction('find');
}
}
];

if (!isNewDesign) {
conversationSearchOptionsSubmenu.push({
},
{
label: 'Search in Conversation',
accelerator: 'CommandOrControl+F',
visible: isNewDesign,
click() {
sendAction('search');
sendAction('search', isNewDesign);
}
});
}

conversationSearchOptionsSubmenu.push({type: 'separator'});

const conversationMessageOptionsSubmenu: MenuItemConstructorOptions[] = [
},
{
label: 'Insert GIF',
accelerator: 'CommandOrControl+G',
Expand Down Expand Up @@ -633,12 +621,6 @@ Press Command/Ctrl+R in Caprine to see your changes.
}
];

const conversationSubmenu: MenuItemConstructorOptions[] = [
...conversationOptionsSubmenu,
...conversationSearchOptionsSubmenu,
...conversationMessageOptionsSubmenu
];

const helpSubmenu: MenuItemConstructorOptions[] = [
openUrlMenuItem({
label: 'Website',
Expand Down

0 comments on commit fcbac87

Please sign in to comment.