Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
BITespresso committed Apr 26, 2019
2 parents b54fb21 + b9a06cb commit b436463
Show file tree
Hide file tree
Showing 3 changed files with 2,169 additions and 1 deletion.
247 changes: 247 additions & 0 deletions README.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
# DSM-Window-Utilities

Allows you to adjust or reset the size and position of windows on the DSM desktop for [Synology](https://www.synology.com) DiskStations.

## Table of Contents

1. [Introduction](#introduction)
2. [Usage](#usage)
1. [General](#general)
2. [Using `cascadeOverlap([bounds])`](#using-cascadeoverlapbounds)
3. [Using `resetRestoreSizeAndPosition([appNames])`](#using-resetrestoresizeandpositionappnames)
4. [Using `launch([appNames])`](#using-launchappnames)
5. [Using `setRestorePagePosition(appName, x, y)`](#using-setrestorepagepositionappname-x-y)
3. [Compatibility](#compatibility)
4. [References](#references)
1. [Opening the Browser Console](#opening-the-browser-console)
2. [List of supported Applications](#list-of-supported-applications)
5. [API Reference](#api-reference)
6. [License](#license)

## Introduction

By default, each new application window opened on the DSM desktop is offset horizontally and vertically 30px from the last window opened. This continues until part of the window would be outside the desktop area. In this case, the window is moved to the left and/or top of the desktop. Internally in the DSM, this algorithm is named **cascadeOverlap**.

Whenever you move or resize an application window, a `restoreSizePos` entry is created in the current user profile that saves the current window size and location for that application. Newly opened windows then always get this size and position and no longer get their position through the **cascadeOverlap** algorithm.

This default behavior has some drawbacks that are addressed by the DSM-Window-Utilities:

* It is almost impossible to achieve a consistent window arrangement across different DiskStations by manually moving the windows.
* If you frequently take screenshots of the DSM desktop and create a mask in Photoshop to crop individual windows, it's an extra effort to adjust the window position to the mask position each time.
* In some cases, an application window may accidentally receive a `restoreSizePos` located outside the visible area of the desktop. This can only be fixed by manipulating the HTML of the page and changing the position of the element.

DSM-Window-Utilities therefore provides a JavaScript API to adjust or reset the size and position of the application windows according to your requirements.

## Usage

### General

1. Sign in to DSM with the user for whom you want to change the application windows.
2. [Open](#opening-the-browser-console) the Browser's Developer Console.
3. Copy the **contents** of the `bit-sds-windowutil.js` file, paste it into the console and press Enter. This creates the static class `BIT.SDS.WindowUtil` and allows you to call the provided [methods](#BIT.SDS.WindowUtil).
4. Now you can simply call a method by entering e.g. `BIT.SDS.WindowUtil.launch();`. This example launches all installed [applications](#list-of-supported-applications) that display a window on the DSM desktop.

### Using `cascadeOverlap([bounds])`

Probably the most useful method is `cascadeOverlap()`. This method arranges all application windows with the same algorithm as the internal **cascadeOverlap**, but assigns a fixed position to the windows by setting the `restoreSizePos`. The position of the individual application windows is determined only by the limits specified by the optional `bounds` argument. As long as you call this method with the same `bounds`, each window has the same individual position, regardless of which applications you have installed, which DSM version you are using, or how large your browser window is.

Unless you want to customize the `bounds`, you don't need to specify the bounds values. You can simply rely on the [suggestion](#BIT.SDS.WindowUtil.suggestBounds) made when calling `cascadeOverlap()` without argument.

Make sure that you first undock the console window from the browser window and set the browser window to the desired size. Then type into the console:

```js
BIT.SDS.WindowUtil.cascadeOverlap();
```

You will notice that `cascadeOverlap()` logs the bounds it uses in the console. For example:

```
Using: BIT.SDS.WindowUtil.cascadeOverlap({x: 160, y: 139, width: 1640, height: 830});
```

To see the effect of the new window arrangement, you can use the following command, which first closes all windows and then opens them again:

```js
BIT.SDS.WindowUtil.close()
.then(BIT.SDS.WindowUtil.launch());
```

If you want to customize the bounds, start changing the values of `x`, `y`, `width` or `height` to your liking and call `cascadeOverlap()` again. For example:

```js
BIT.SDS.WindowUtil.cascadeOverlap({x: 0, y: 39, width: 1920, height: 1161});
```

**Note:** Once you have found **your** `bounds`, note them down so that you can reproduce the call at any time.

### Using `resetRestoreSizeAndPosition([appNames])`

If you like the default behavior of DSM, which moves each newly opened window, but you have already moved or resized some windows, you can simply restore the default with the following command, which removes the `restoreSizePos` from each application window, so that you get a fresh start:

```js
BIT.SDS.WindowUtil.resetRestoreSizeAndPosition();
```

For a more specific reset, you can also specify a single `appName` or an array of `appName`s as in these examples:

```js
BIT.SDS.WindowUtil.resetRestoreSizeAndPosition("SYNO.SDS.App.FileStation3.Instance");
```

```js
BIT.SDS.WindowUtil.resetRestoreSizeAndPosition(["SYNO.SDS.App.FileStation3.Instance", "SYNO.SDS.PkgManApp.Instance"]);
```

See [here](#list-of-supported-applications) for a list of supported applications and their respective `appName`.

### Using `launch([appNames])`

The `launch()` method can be used to launch applications that are not running and open the application window. This allows you to easily get an overview of how your application windows are currently arranged:

```js
BIT.SDS.WindowUtil.launch();
```

The `launch()` method returns a promise that is fulfilled with an array of all launched application instances. This allows you to call methods of the application instance class (`SYNO.SDS.AppInstance`). A simple example is setting the position of the application instance window:

```js
BIT.SDS.WindowUtil.launch("SYNO.SDS.App.FileStation3.Instance")
.then(function(results) {
results[0].window.setPagePosition(0, 39);
});
```

Internally, the promise returned by `launch()` is used by the `getDefaultSize()` method, which retrieves the window size from the application instance window.

**Note:** You do not have to start an application just to get your application instance. If the application is already running, you can use the method `SYNO.SDS.AppMgr.getByAppName(appName)` to get an array of all instances of a particular application.

### Using `setRestorePagePosition(appName, x, y)`

If you want to permanently set the position of an application window, you can use `setRestorePagePosition()` which writes the provided x,y page position to the `restoreSizePos`. In this example, the position of the File Station application is set to the top left corner of the DSM desktop:

```js
BIT.SDS.WindowUtil.setRestorePagePosition("SYNO.SDS.App.FileStation3.Instance", 0, 39);
```

## Compatibility

DSM-Window-Utilities has been tested on the following DSM versions:

* **DSM 5.2**
* **DSM 6.0.x**
* **DSM 6.1.x**
* **DSM 6.2.x**

## References

### Opening the Browser Console

| Browser | Mac | Windows / Linux |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------- |
| Chrome | <kbd>Cmd</kbd>+<kbd>Option</kbd>+<kbd>J</kbd> | <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>J</kbd> |
| Firefox | <kbd>Cmd</kbd>+<kbd>Option</kbd>+<kbd>K</kbd> | <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>K</kbd> |
| Safari | <kbd>Cmd</kbd>+<kbd>Option</kbd>+<kbd>C</kbd><br><sub>**Note**: You need to enable<br>*Show Developer menu in menu bar*<br>in *Preferences/Advanced* before.</sub> | N/A |
| Opera | <kbd>Cmd</kbd>+<kbd>Option</kbd>+<kbd>J</kbd> | <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>J</kbd> |
| Edge | N/A | <kbd>F12</kbd> and click on *Console* tab |
| Internet Explorer | N/A | <kbd>F12</kbd> and click on *Console* tab |

### List of supported Applications

| Application | appName |
| ---------------------------------------------- | ----------------------------------------- |
| Control Panel | `SYNO.SDS.AdminCenter.Application` |
| File Station | `SYNO.SDS.App.FileStation3.Instance` |
| EZ-Internet | `SYNO.SDS.EzInternet.Instance` |
| DSM Help | `SYNO.SDS.HelpBrowser.Application` |
| Package Center | `SYNO.SDS.PkgManApp.Instance` |
| Resource Monitor | `SYNO.SDS.ResourceMonitor.Instance` |
| Storage Manager | `SYNO.SDS.StorageManager.Instance` |
| High Availability Manager | `SYNO.SDS.HA.Instance` |
| Log Center | `SYNO.SDS.LogCenter.Instance` |
| Security Advisor | `SYNO.SDS.SecurityScan.Instance` |
| Support Center | `SYNO.SDS.SupportForm.Application` |
| Options / Personal | `SYNO.SDS.App.PersonalSettings.Instance` |
| Backup & Replication | `SYNO.SDS.Backup.Application` |
| Text Editor | `SYNO.SDS.ACEEditor.Application` |
| Synology Account | `SYNO.SDS.MyDSCenter.Application` |
| Storage Analyzer | `SYNO.SDS.StorageReport.Application` |
| Antivirus Essential & Antivirus by McAfee | `SYNO.SDS.AV.Instance` |
| Audio Station | `SYNO.SDS.AudioStation.Application` |
| CardDAV Server | `SYNO.SDS.CardDAVServer.Instance` |
| Cloud Station / Cloud Station Server | `SYNO.SDS.CSTN.Instance` |
| Cloud Station Client / Cloud Station ShareSync | `SYNO.SDS.CloudStationClient.Instance` |
| Cloud Sync | `SYNO.SDS.DSCloudSync.Instance` |
| CMS | `SYNO.SDS.CMS.Application` |
| Directory Server | `SYNO.SDS.LDAP.AppInstance` |
| DNS Server | `SYNO.SDS.DNS.Instance` |
| Docker | `SYNO.SDS.Docker.Application` |
| Download Station | `SYNO.SDS.DownloadStation.Application` |
| Git Server | `SYNO.SDS.GIT.Instance` |
| Glacier Backup | `SYNO.SDS.Glacier.Instance` |
| HiDrive Backup | `SYNO.SDS.HiDrive.Instance` |
| iTunes Server | `SYNO.SDS.iTunes.Application` |
| Java Manager | `SYNO.SDS.JAVAMANAGER.Instance` |
| Mail Server | `SYNO.SDS.MailServer.Instance` |
| MariaDB / MariaDB 5 | `SYNO.SDS.MARIADB.Instance` |
| Media Server | `SYNO.SDS.MediaServer.AppInstance` |
| Note Station | `SYNO.SDS.NoteStation.Application` |
| Proxy Server | `SYNO.SDS.ProxyServer.Instance` |
| RADIUS Server | `SYNO.SDS.RAD.Instance` |
| SSO Server | `SYNO.SDS.SSOServer.Instance` |
| SVN | `SYNO.SDS.SVN.Instance` |
| Video Station | `SYNO.SDS.VideoStation.AppInstance` |
| VPN Server | `SYNO.SDS.VPN.Instance` |
| Active Backup for Server | `SYNO.SDS.ActiveBackup.Instance` |
| Hyper Backup | `SYNO.SDS.Backup.Application` |
| Hyper Backup Vault | `SYNO.SDS.BackupService.Instance` |
| Java7 | `SYNO.SDS.JAVA7.Instance` |
| Java8 | `SYNO.SDS.JAVA8.Instance` |
| MailPlus Server | `SYNO.SDS.MailPlusServer.Instance` |
| MariaDB 10 | `SYNO.SDS.MARIADB10.Instance` |
| Notification Settings | `SYNO.SDS.DSMNotify.Setting.Application` |
| PetaSpace | `SYNO.SDS.ClusteredShare.Application` |
| Snapshot Replication | `SYNO.SDS.DisasterRecovery.Application` |
| Storage Analyzer | `SYNO.SDS.StorageAnalyzer.Application` |
| Text Editor | `SYNO.TextEditor.Application` |
| Web Station | `SYNO.SDS.WebStation.Application` |
| WebDAV Server | `SYNO.SDS.WebDAVServer.Instance` |
| Universal Search | `SYNO.Finder.Application` |
| Active Backup for G Suite | `SYNO.SDS.ActiveBackupGSuite.Instance` |
| Active Backup for Office 365 | `SYNO.SDS.ActiveBackupOffice365.Instance` |
| Presto File Server | `SYNO.SDS.PrestoServer.Application` |
| USB Copy | `SYNO.SDS.USBCopy.Application` |
| Active Backup for Business | `SYNO.ActiveBackup.AppInstance` |
| iSCSI Manager | `SYNO.SDS.iSCSI.Application` |
| OAuth Service | `SYNO.SDS.OAuthService.Instance` |
| Active Directory Server | `SYNO.SDS.ADServer.Application` |
| Virtual Machine Manager | `SYNO.SDS.Virtualization.Application` |

## API Reference

{{#namespace name="BIT"}}
{{>header~}}
{{>body}}
{{/namespace}}
{{>separator~}}

{{#namespace name="SDS"}}
{{>header~}}
{{>body}}
{{/namespace}}
{{>separator~}}

{{#class name="WindowUtil"}}
{{>docs~}}
{{/class}}
{{>separator~}}

{{#class name="Promise"}}
{{>docs~}}
{{/class}}
{{>separator~}}

## License

Copyright (C) 2019 Michael Berger (BITespresso)

DSM-Window-Utilities is licensed under the **GNU General Public License v3 (GPL-3)** (http://www.gnu.org/copyleft/gpl.html).
Loading

0 comments on commit b436463

Please sign in to comment.