mirror of
https://github.com/rhysd/Mstdn.git
synced 2025-02-01 05:52:11 +01:00
add shortcuts to switch to next/previous account
This commit is contained in:
parent
2a65483779
commit
129490f4b4
51
README.md
51
README.md
@ -99,11 +99,13 @@ You need to write up this config at first.
|
||||
Object whose key is a key sequence and whose value is an action name.
|
||||
|
||||
| Action Name | Description | Default Key |
|
||||
|--------------------|---------------------------------|-------------|
|
||||
|-----------------|---------------------------------|-------------|
|
||||
| `scroll-down` | Scroll down window | `j` |
|
||||
| `scroll-up` | Scroll up window | `k` |
|
||||
| `scroll-top` | Scroll up to top of window | `i` |
|
||||
| `scroll-bottom` | Scroll down to bottom of window | `m` |
|
||||
| `next-account` | Switch to next account | N/A |
|
||||
| `prev-account` | Switch to previous account | N/A |
|
||||
|
||||
If an action name starts with `/`, it will navigate to the path. For example,
|
||||
if you set `"/web/timelines/home"` to some key shortcut and you input the key,
|
||||
@ -111,6 +113,51 @@ browser will navigate page to `https://{your host}/web/timelines/home`.
|
||||
|
||||
By default, some key shortcuts for tab items are set in addition to above table.
|
||||
|
||||
<details>
|
||||
<summary> Example of configuration </summary>
|
||||
<pre><code>
|
||||
{
|
||||
"hot_key": "F8",
|
||||
"icon_color": "black",
|
||||
"always_on_top": false,
|
||||
"normal_window": false,
|
||||
"zoom_factor": 0.9,
|
||||
"accounts": [
|
||||
{
|
||||
"name": "Linda_pp",
|
||||
"host": "mstdn.jp",
|
||||
"default_page": "/web/timelines/home"
|
||||
},
|
||||
{
|
||||
"name": "inudog",
|
||||
"host": "mastodon.social",
|
||||
"default_page": "/web/timelines/home"
|
||||
}
|
||||
],
|
||||
"keymaps": {
|
||||
"1": "/web/statuses/new",
|
||||
"2": "/web/timelines/home",
|
||||
"3": "/web/notifications",
|
||||
"4": "/web/timelines/public/local",
|
||||
"5": "/web/timelines/public",
|
||||
"6": "/web/getting-started",
|
||||
"ctrl+1": "/web/statuses/new",
|
||||
"ctrl+2": "/web/timelines/home",
|
||||
"ctrl+3": "/web/notifications",
|
||||
"ctrl+4": "/web/timelines/public/local",
|
||||
"ctrl+5": "/web/timelines/public",
|
||||
"ctrl+6": "/web/getting-started",
|
||||
"j": "scroll-down",
|
||||
"k": "scroll-up",
|
||||
"i": "scroll-top",
|
||||
"m": "scroll-bottom",
|
||||
"n": "next-account",
|
||||
"p": "prev-account"
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
</details>
|
||||
|
||||
## Multi account
|
||||
|
||||
If you set multiple accounts to `accounts` array in `config.json`, `Accounts` menu item will appear in application menu.
|
||||
@ -118,7 +165,7 @@ If you set multiple accounts to `accounts` array in `config.json`, `Accounts` me
|
||||
![multi account menu item](https://github.com/rhysd/ss/blob/master/Mstdn/multi-account.png?raw=true)
|
||||
|
||||
It will show the list of your account. Check mark is added for current user.
|
||||
When you click menu item of non-current user, application window will be rectreated and switch page to the account.
|
||||
When you click menu item of non-current user, application window will be recreated and switch page to the account.
|
||||
|
||||
[Mastodon]: https://github.com/tootsuite/mastodon
|
||||
[npm]: https://www.npmjs.com/package/mstdn
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {EventEmitter} from 'events';
|
||||
import {Menu, MenuItem} from 'electron';
|
||||
import {Menu, MenuItem, ipcMain as ipc} from 'electron';
|
||||
import log from './log';
|
||||
import {Account} from './config';
|
||||
|
||||
@ -49,6 +49,9 @@ export default class AccountSwitcher extends EventEmitter {
|
||||
menu.insert(menu.items.length - 1, item);
|
||||
Menu.setApplicationMenu(menu);
|
||||
}
|
||||
|
||||
ipc.on('mstdn:next-account' as IpcChannelFromRenderer, this.switchToNext);
|
||||
ipc.on('mstdn:prev-account' as IpcChannelFromRenderer, this.switchToPrev);
|
||||
}
|
||||
|
||||
switchTo(account: Account) {
|
||||
@ -60,4 +63,41 @@ export default class AccountSwitcher extends EventEmitter {
|
||||
this.emit('switch', account, this.current);
|
||||
this.current = account;
|
||||
}
|
||||
|
||||
getAccountIndex(account: Account) {
|
||||
for (let i = 0; i < this.accounts.length; ++i) {
|
||||
const a = this.accounts[i];
|
||||
if (a.name === account.name && a.host === account.host) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
switchToNext = () => {
|
||||
if (this.accounts.length <= 1) {
|
||||
log.debug('Skip switching account: Only one account is registered');
|
||||
return;
|
||||
}
|
||||
let idx = this.getAccountIndex(this.current) + 1;
|
||||
if (idx >= this.accounts.length) {
|
||||
idx = 0;
|
||||
}
|
||||
log.debug('Switch to next account');
|
||||
this.switchTo(this.accounts[idx]);
|
||||
}
|
||||
|
||||
switchToPrev = () => {
|
||||
if (this.accounts.length <= 1) {
|
||||
log.debug('Skip switching account: Only one account is registered');
|
||||
return;
|
||||
}
|
||||
let idx = this.getAccountIndex(this.current);
|
||||
if (idx <= 0) {
|
||||
idx = this.accounts.length;
|
||||
}
|
||||
--idx;
|
||||
log.debug('Switch to prev account');
|
||||
this.switchTo(this.accounts[idx]);
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,12 @@ const ShortcutActions = {
|
||||
'scroll-up': () => {
|
||||
scrollable().scrollTop -= window.innerHeight / 3;
|
||||
},
|
||||
'next-account': () => {
|
||||
Ipc.send('mstdn:next-account');
|
||||
},
|
||||
'prev-account': () => {
|
||||
Ipc.send('mstdn:prev-account');
|
||||
},
|
||||
} as {[action: string]: () => void};
|
||||
|
||||
function setupKeybinds(keybinds: {[key: string]: string}, host: string) {
|
||||
|
@ -3,9 +3,14 @@ import r from './require';
|
||||
const electron = r('electron');
|
||||
const ipc = electron.ipcRenderer;
|
||||
|
||||
export function on(channel: IpcChannel, callback: (...args: any[]) => void) {
|
||||
export function on(channel: IpcChannelFromMain, callback: (...args: any[]) => void) {
|
||||
ipc.on(channel, (_, ...args: any[]) => {
|
||||
log.info('IPC: Received from:', channel, args);
|
||||
callback(...args);
|
||||
});
|
||||
}
|
||||
|
||||
export function send(channel: IpcChannelFromRenderer, ...args: any[]) {
|
||||
log.info('IPC: Send:', channel, args);
|
||||
ipc.send(channel, ...args);
|
||||
}
|
||||
|
8
typings/ipc.d.ts
vendored
8
typings/ipc.d.ts
vendored
@ -1,4 +1,8 @@
|
||||
type IpcChannel
|
||||
type IpcChannelFromMain
|
||||
= 'mstdn:config'
|
||||
| 'mstdn:change-account'
|
||||
;
|
||||
|
||||
type IpcChannelFromRenderer
|
||||
= 'mstdn:next-account'
|
||||
| 'mstdn:prev-account'
|
||||
;
|
||||
|
Loading…
x
Reference in New Issue
Block a user