Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Default servers improvements #490

Merged
merged 12 commits into from
Aug 7, 2017
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,35 +139,35 @@ docker run --rm -ti -v ${PWD}:/project -v ${PWD##*/}-node-modules:/project/node_

All packaging actions are handled by [electron-builder](https://github.com/electron-userland/electron-builder). It has a lot of [customization options](https://github.com/electron-userland/electron-builder/wiki/Options), which you can declare under ["build" key in package.json file](https://github.com/szwacz/electron-boilerplate/blob/master/package.json#L2).

# Post Release Configuration
## Deploying with pre-configured servers
You can bundle a `servers.json` with the install which will define what servers the client will connect to and will populate the server list in the sidebar.

If this file is found, the initial "Connect to server" screen will be skipped and it will attempt to connect to the first server in the array that has been defined and drop the user right at the login screen.

The `servers.json` file needs to be placed in the `%APPDATA%` folder for the User not the System wide one. The servers.json will only be checked if no other servers have already be added. It should be copied to the correct location after the install.
# Default servers

```
%APPDATA%/Rocket.Chat+/servers.json
```

The syntax/layout of servers.json is as follows:
The `servers.json` file will define what servers the client will connect to and will populate the server list in the sidebar, it contains a list of default servers which will be added the first time the user runs the app (or when all servers are removed from the list).
The file syntax is as follows:
```
{
"MyRocketChatServer": "https://my-chat-server-url.com",
"Server2": "https://demo.rocket.chat"
"Demo Rocket Chat": "https://demo.rocket.chat",
"Open Rocket Chat": "https://open.rocket.chat"
}
```

On MacOS the full path of servers.json is:
```
/Users/<username>/Library/Application Support/Rocket.Chat+/servers.json
```
## Pre-Release Configuration

You can bundle a `servers.json` with the install package, the file should be located in the root of the project application (same level as the `package.json`). If the file is found, the initial "Connect to server" screen will be skipped and it will attempt to connect to the first server in the array that has been defined and drop the user right at the login screen. Note that the `servers.json` will only be checked if no other servers have already be added, even if you uninstall the app without removing older preferences, it will not be triggered again.

## Post-Install Configuration

If you can't (or don't want to) bundle the file inside the app, you can create a `servers.json` in the user preferences folder which will overwrite the packaged one. The file should be located in the `%APPDATA%/Rocket.Chat+/` folder or the installation folder in case of a installation for all users (Windows only).

and on Windows:
For Windows the full paths are:
```
C:\Users\<username>\AppData\Roaming\Rocket.Chat+\servers.json
C:\Program Files\Rocket.Chat+\Resources\servers.json
```
On MacOS the full path is:
```
/Users/<username>/Library/Application Support/Rocket.Chat+/servers.json
```


# Useful links

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
],
"extraResources": [
"dictionaries/**/*",
"build/icon.ico"
"build/icon.ico",
"servers.json"
],
"mac": {
"bundleVersion": "19",
Expand Down
3 changes: 3 additions & 0 deletions servers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Rocket.Chat": "https://demo.rocket.chat"
}
9 changes: 6 additions & 3 deletions src/scripts/servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ class Servers extends EventEmitter {

// Load server info from server config file
if (Object.keys(hosts).length === 0) {
const serverFileName = 'servers.json';
const userDataDir = jetpack.cwd(remote.app.getPath('userData'));
const pathToServerJson = jetpack.path(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we check the user APPDATA folder first, then the system installation folder (for /allusers) and then the packaged file (if we do a branded package).

jetpack.find(remote.app.getPath('userData'), { matching: 'servers.json'})[0] ||
jetpack.find(process.cwd(), { matching: 'servers.json'})[0] ||
jetpack.find(remote.app.getAppPath(), { matching: 'servers.json'})[0]);

try {
const result = userDataDir.read(serverFileName, 'json');
const result = jetpack.read(pathToServerJson, 'json');
if (result) {
hosts = {};
Object.keys(result).forEach((title) => {
Expand Down
Loading