Example of configuration
{
"hot_key": "F8",
"icon_color": "black",
"always_on_top": false,
"normal_window": false,
"zoom_factor": 0.9,
"chromium_sandbox": true,
"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"
}
}
## Multi account
If you set multiple accounts to `accounts` array in `config.json`, `Accounts` menu item will appear
in application menu.
![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 recreated and switch page
to the account.
## Key Shortcut Plugin
By specifying JavaScript file to action name in `keymaps` of `config.json`, you can write your
favorite behavior with JavaScript directly. Please note that `"chromium_sandbox" : true`
is also required (if you don't know what happens with `"chromium_sandbox" : true`, please read
above config section).
```json
{
...
"chromium_sandbox": false,
...
"keymaps": {
"r": "hello.js"
}
}
```
The script file path is a relative path from your `Mstdn` application directory. For example,
Specifying `hello.js` will run `/Users/You/Application Support/Mstdn/hello.js` on Mac.
The plugin script MUST export one function. Function receives configuration object and current
account object as its parameters. So above `hello.js` would look like:
```js
module.exports = function (config, account) {
alert('Hello, ' + account.name);
}
```
With above example config, typing `r` will show 'Hello, {your name}' alert dialog. You can use any
DOM APIs, Node.js's standard libraries and Electron APIs in plugin script.
## User CSS
When `user.css` is put in your `Mstdn` application directory, it will be loaded automatically.
To enable this feature, `"chromium_sandbox" : true` is also required (if you don't know what happens
with `"chromium_sandbox" : true`, please read above config section).
For example, below `/Users/You/Application Support/Mstdn/user.css` will change font color to red on Mac.
```css
body {
color: red !important;
}
```
## Preload Plugin
You can make a Node.js package which is preloaded before loading inner mastodon page.
Preload plugin is enabled if `chromium_sandbox` option is set to `false`. Please read above
configuration section before using any plugin.
### How to make
Create `node_modules` directory in your application directory at first. And then, please make
`mstdn-preload-hello` directory. It consists a node package.
Package name must start with `mastdn-preload-`.
Make `package.json` manually or by `$ npm init` in the directory.
```json
{
"name": "mstdn-preload-hello",
"version": "0.0.0",
"description": "sample of preload plugin of Mstdn.app",
"main": "index.js",
"author": "Your name",
"license": "Some license"
}
```
Finally make `index.js` as below:
```javascript
module.exports = (config, account) => {
console.log('Hello from plugin!', config, account);
}
```
Package must export one function which receives two parameters `config` and `account`.
Note that you can use below APIs in the script.
- [Node.js standard libraries][] via `require` (e.g. `require('fs')`)
- Dependant node packages listed in `package.json` of the plugin
- [Electron Renderer APIs][Electron APIs]
- All Web APIs on browser (including DOM API)
#### !!! Security Notice !!!
Do not leak Node.js stuff to global namespace like below.
```javascript
// Never do things like this!
window.my_require = require;
```
### How to use
If you didn't try above 'How to make' section, please install plugin package at first.
Below will install 'hello' plugin to `{app directory}/node_modules/mstdn-preload-hello`.
```
$ cd {Your application directory}
$ npm install mstdn-preload-hello
```
And then write what plugin should be loaded to `"preload"` section of your `config.json`.
`"hello"` should be added to the list.
```json
{
...
"preload" [
"hello"
],
...
}
```
Finally open Mstdn.app and see DevTools via [Menu] -> [View] -> [Developper Tools] -> console.
If window is too small to see DevTools, please make window size bigger.
In console, the message 'Hello from plugin!', config information and account information should be output.
### List of Plugins
To be made
## How to Debug
By setting `NODE_ENV` environment variable to `development`, Mstdn will start in debug mode.
In debug mode, app outputs all logs to stdout and opens DevTools for a page rendered in a window
automatically. You can also see logs in 'console' tab of DevTools for debugging renderer process.
```sh
# If you installed this app via npm
$ NODE_ENV=development open-mstdn-app
# Package on macOS
$ NODE_ENV=development /path/to/Mstdn.app/Contents/MacOS/Mstdn
# Package on Linux
$ NODE_ENV=development /path/to/Mstdn-linux-xxx-x.y.z/Mstdn
# Package on cmd.exe on Windows
$ set NODE_ENV=development
$ \path\to\Mstdn-win32-xxx-x.y.z\Mstdn.exe
```
## Contact to the Author
Please feel free to make an issue on GitHub or mention on Mastodon/Twitter.
- [@Linda\_pp@mstdn.jp](https://mstdn.jp/@Linda_pp) (Japanese account. English is also OK)
- [@inudog@mastodon.social](https://mastodon.social/@inudog) (English account)
[Mastodon]: https://github.com/tootsuite/mastodon
[npm]: https://www.npmjs.com/package/mstdn
[Release page]: https://github.com/rhysd/Mstdn/releases
[Electron]: electron.atom.io
[sandbox doc]: https://github.com/electron/electron/blob/master/docs/api/sandbox-option.md
[npm version badge]: https://badge.fury.io/js/mstdn.svg
[Node.js standard libraries]: https://nodejs.org/api/
[Electron APIs]: https://electron.atom.io/docs/api/