mirror of
https://github.com/rhysd/Mstdn.git
synced 2025-01-20 19:52:10 +01:00
enable key shortcuts
This commit is contained in:
parent
3b41501656
commit
d27a152d3a
@ -4,7 +4,7 @@ Web-based Desktop Client for [Mastodon][]
|
|||||||
Features:
|
Features:
|
||||||
|
|
||||||
- [x] Small window on your menubar (or isolated window)
|
- [x] Small window on your menubar (or isolated window)
|
||||||
- [ ] Desktop notification
|
- [x] Desktop notification
|
||||||
- [ ] Customizable shortcut keybinds
|
- [ ] Customizable shortcut keybinds
|
||||||
- [ ] Multi-account
|
- [ ] Multi-account
|
||||||
|
|
||||||
|
@ -34,7 +34,17 @@ function makeDefaultConfig(): Config {
|
|||||||
host: '',
|
host: '',
|
||||||
default_page: '/web/timelines/home',
|
default_page: '/web/timelines/home',
|
||||||
}],
|
}],
|
||||||
keymaps: {},
|
keymaps: {
|
||||||
|
j: 'scroll-down',
|
||||||
|
k: 'scroll-up',
|
||||||
|
i: 'scroll-top',
|
||||||
|
m: 'scroll-bottom',
|
||||||
|
1: '/web/timelines/home',
|
||||||
|
2: '/web/notifications',
|
||||||
|
3: '/web/timelines/public/local',
|
||||||
|
4: '/web/timelines/public',
|
||||||
|
5: '/web/getting-started'
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,5 +5,6 @@ if (process.env.NODE_ENV === 'development') {
|
|||||||
} else {
|
} else {
|
||||||
log.setLevel('info');
|
log.setLevel('info');
|
||||||
}
|
}
|
||||||
|
log.setLevel('debug');
|
||||||
|
|
||||||
export default log;
|
export default log;
|
||||||
|
@ -1,10 +1,59 @@
|
|||||||
// import * as Mousetrap from 'mousetrap';
|
import * as Mousetrap from 'mousetrap';
|
||||||
import {Config} from '../main/config';
|
import {Config} from '../main/config';
|
||||||
import * as Ipc from './ipc';
|
import * as Ipc from './ipc';
|
||||||
import log from './log';
|
import log from './log';
|
||||||
|
|
||||||
|
function scrollable() {
|
||||||
|
const scrollable = document.querySelector('.scrollable');
|
||||||
|
if (!scrollable) {
|
||||||
|
log.error('Scrollable element was not found!');
|
||||||
|
return {scrollTop: 0};
|
||||||
|
}
|
||||||
|
return scrollable;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ShortcutActions = {
|
||||||
|
'scroll-top': () => {
|
||||||
|
scrollable().scrollTop = 0;
|
||||||
|
},
|
||||||
|
'scroll-bottom': () => {
|
||||||
|
scrollable().scrollTop = document.body.scrollHeight;
|
||||||
|
},
|
||||||
|
'scroll-down': () => {
|
||||||
|
scrollable().scrollTop += window.innerHeight / 3;
|
||||||
|
},
|
||||||
|
'scroll-up': () => {
|
||||||
|
scrollable().scrollTop -= window.innerHeight / 3;
|
||||||
|
},
|
||||||
|
} as {[action: string]: () => void}
|
||||||
|
|
||||||
|
function setupKeybinds(keybinds: {[key: string]: string}, host: string) {
|
||||||
|
for (const key in keybinds) {
|
||||||
|
const action = keybinds[key];
|
||||||
|
if (action.startsWith('/')) {
|
||||||
|
Mousetrap.bind(key, e => {
|
||||||
|
const url = `https://${host}${action}`;
|
||||||
|
log.info('URL Shortcut:', url);
|
||||||
|
e.preventDefault();
|
||||||
|
window.location.href = url;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const func = ShortcutActions[action];
|
||||||
|
if (func === undefined) {
|
||||||
|
log.error('Unknown shortcut action:', action);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Mousetrap.bind(key, e => {
|
||||||
|
log.info('Shortcut:', action);
|
||||||
|
e.preventDefault();
|
||||||
|
func();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ipc.on('mstdn:config', (config: Config) => {
|
Ipc.on('mstdn:config', (config: Config) => {
|
||||||
log.info('FOOOOOO', config);
|
// TODO: Temporary. It should be fixed on supporting multi-account.
|
||||||
|
const host = config.accounts[0].host;
|
||||||
|
setupKeybinds(config.keymaps, host);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user