mirror of
https://github.com/rhysd/Mstdn.git
synced 2025-01-21 20:52:11 +01:00
make switching tab faster
This commit is contained in:
parent
e8ab0c20e7
commit
0098a55e19
@ -12,6 +12,23 @@ function scrollable() {
|
|||||||
return scrollable;
|
return scrollable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function navigateTo(host: string, path: string) {
|
||||||
|
const url = `https://${host}${path}`;
|
||||||
|
if (window.location.href === url) {
|
||||||
|
log.info('Current URL is already', url);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const link = document.querySelector(`a[href="${path}"]`);
|
||||||
|
if (link) {
|
||||||
|
log.info('Click link by shortcut', path);
|
||||||
|
(link as HTMLAnchorElement).click();
|
||||||
|
} else {
|
||||||
|
log.info('Force navigation by shortcut', path);
|
||||||
|
window.location.href = url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const ShortcutActions = {
|
const ShortcutActions = {
|
||||||
'scroll-top': () => {
|
'scroll-top': () => {
|
||||||
scrollable().scrollTop = 0;
|
scrollable().scrollTop = 0;
|
||||||
@ -32,12 +49,8 @@ function setupKeybinds(keybinds: {[key: string]: string}, host: string) {
|
|||||||
const action = keybinds[key];
|
const action = keybinds[key];
|
||||||
if (action.startsWith('/')) {
|
if (action.startsWith('/')) {
|
||||||
Mousetrap.bind(key, e => {
|
Mousetrap.bind(key, e => {
|
||||||
const url = `https://${host}${action}`;
|
|
||||||
log.info('URL Shortcut:', url);
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (window.location.href !== url) {
|
navigateTo(host, action);
|
||||||
window.location.href = url;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const func = ShortcutActions[action];
|
const func = ShortcutActions[action];
|
||||||
@ -58,6 +71,5 @@ let config: Config | null = null;
|
|||||||
|
|
||||||
Ipc.on('mstdn:config', (c: Config, a: Account) => {
|
Ipc.on('mstdn:config', (c: Config, a: Account) => {
|
||||||
config = c;
|
config = c;
|
||||||
const host = a.host;
|
setupKeybinds(config.keymaps, a.host);
|
||||||
setupKeybinds(config.keymaps, host);
|
|
||||||
});
|
});
|
||||||
|
@ -4,7 +4,7 @@ const electron = r('electron');
|
|||||||
const ipc = electron.ipcRenderer;
|
const ipc = electron.ipcRenderer;
|
||||||
|
|
||||||
export function on(channel: IpcChannel, callback: (...args: any[]) => void) {
|
export function on(channel: IpcChannel, callback: (...args: any[]) => void) {
|
||||||
ipc.on(channel, (...args: any[]) => {
|
ipc.on(channel, (_, ...args: any[]) => {
|
||||||
log.info('IPC: Received from:', channel, args);
|
log.info('IPC: Received from:', channel, args);
|
||||||
callback(...args);
|
callback(...args);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user