Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed May 28, 2021
1 parent 95cc29f commit 871b06c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 150 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,5 @@ rules:
'@typescript-eslint/no-implicit-any-catch': off
'@typescript-eslint/member-ordering': off
'@typescript-eslint/no-var-requires': off
'@typescript-eslint/no-unsafe-argument': off
'@typescript-eslint/restrict-plus-operands': off
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@types/js-yaml": "^4.0.1",
"@types/node": "15.6.1",
"@types/webpack-env": "^1.16.0",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"apply-loader": "2.0.0",
"awesome-typescript-loader": "^5.2.1",
Expand Down
98 changes: 0 additions & 98 deletions terminus-core/src/services/docking.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import type { Display } from 'electron'
import { ConfigService } from '../services/config.service'
import { ElectronService } from '../services/electron.service'
import { HostAppService, Bounds } from '../services/hostApp.service'

export abstract class Screen {
id: number
name?: string
Expand All @@ -12,96 +7,3 @@ export abstract class DockingService {
abstract dock (): void
abstract getScreens (): Screen[]
}

export class ElectronDockingService {
/** @hidden */
private constructor (
private electron: ElectronService,
private config: ConfigService,
private hostApp: HostAppService,
) {
hostApp.displaysChanged$.subscribe(() => this.repositionWindow())
hostApp.displayMetricsChanged$.subscribe(() => this.repositionWindow())
}

dock (): void {
const dockSide = this.config.store.appearance.dock

if (dockSide === 'off') {
this.hostApp.setAlwaysOnTop(false)
return
}

let display = this.electron.screen.getAllDisplays()
.filter(x => x.id === this.config.store.appearance.dockScreen)[0]
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!display) {
display = this.getCurrentScreen()
}

const newBounds: Bounds = { x: 0, y: 0, width: 0, height: 0 }

const fill = this.config.store.appearance.dockFill <= 1 ? this.config.store.appearance.dockFill : 1
const space = this.config.store.appearance.dockSpace <= 1 ? this.config.store.appearance.dockSpace : 1
const [minWidth, minHeight] = this.hostApp.getWindow().getMinimumSize()

if (dockSide === 'left' || dockSide === 'right') {
newBounds.width = Math.max(minWidth, Math.round(fill * display.bounds.width))
newBounds.height = Math.round(display.bounds.height * space)
}
if (dockSide === 'top' || dockSide === 'bottom') {
newBounds.width = Math.round(display.bounds.width * space)
newBounds.height = Math.max(minHeight, Math.round(fill * display.bounds.height))
}
if (dockSide === 'right') {
newBounds.x = display.bounds.x + display.bounds.width - newBounds.width
} else if (dockSide === 'left') {
newBounds.x = display.bounds.x
} else {
newBounds.x = display.bounds.x + Math.round(display.bounds.width / 2 * (1 - space))
}
if (dockSide === 'bottom') {
newBounds.y = display.bounds.y + display.bounds.height - newBounds.height
} else if (dockSide === 'top') {
newBounds.y = display.bounds.y
} else {
newBounds.y = display.bounds.y + Math.round(display.bounds.height / 2 * (1 - space))
}

const alwaysOnTop = this.config.store.appearance.dockAlwaysOnTop

this.hostApp.setAlwaysOnTop(alwaysOnTop)
setImmediate(() => {
this.hostApp.setBounds(newBounds)
})
}

getScreens (): Display[] {
const primaryDisplayID = this.electron.screen.getPrimaryDisplay().id
return this.electron.screen.getAllDisplays().sort((a, b) =>
a.bounds.x === b.bounds.x ? a.bounds.y - b.bounds.y : a.bounds.x - b.bounds.x
).map((display, index) => {
return {
...display,
id: display.id,
name: display.id === primaryDisplayID ? 'Primary Display' : `Display ${index + 1}`,
}
})
}

private getCurrentScreen (): Display {
return this.electron.screen.getDisplayNearestPoint(this.electron.screen.getCursorScreenPoint())
}

private repositionWindow () {
const [x, y] = this.hostApp.getWindow().getPosition()
for (const screen of this.electron.screen.getAllDisplays()) {
const bounds = screen.bounds
if (x >= bounds.x && x <= bounds.x + bounds.width && y >= bounds.y && y <= bounds.y + bounds.height) {
return
}
}
const screen = this.electron.screen.getPrimaryDisplay()
this.hostApp.getWindow().setPosition(screen.bounds.x, screen.bounds.y)
}
}
2 changes: 1 addition & 1 deletion terminus-local/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class Session extends BaseSession {
super()
this.config = injector.get(ConfigService)
this.hostApp = injector.get(HostAppService)
this.bootstrapData = injector.get(BOOTSTRAP_DATA) as BootstrapData
this.bootstrapData = injector.get(BOOTSTRAP_DATA)
}

start (options: SessionOptions): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ export class WindowSettingsTabComponent extends BaseComponent {

this.themes = config.enabledServices(this.themes)

if (this.docking) {
const dockingService = docking
if (dockingService) {
this.subscribeUntilDestroyed(hostApp.displaysChanged$, () => {
this.zone.run(() => this.screens = this.docking!.getScreens())
this.zone.run(() => this.screens = dockingService.getScreens())
})
this.screens = this.docking.getScreens()
this.screens = dockingService.getScreens()
}

this.isFluentVibrancySupported = isWindowsBuild(WIN_BUILD_FLUENT_BG_SUPPORTED)
Expand Down
60 changes: 13 additions & 47 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -430,29 +430,29 @@
dependencies:
"@types/yargs-parser" "*"

"@typescript-eslint/eslint-plugin@^4.14.1":
version "4.18.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.18.0.tgz#50fbce93211b5b690895d20ebec6fe8db48af1f6"
integrity sha512-Lzkc/2+7EoH7+NjIWLS2lVuKKqbEmJhtXe3rmfA8cyiKnZm3IfLf51irnBcmow8Q/AptVV0XBZmBJKuUJTe6cQ==
"@typescript-eslint/eslint-plugin@^4.25.0":
version "4.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.25.0.tgz#d82657b6ab4caa4c3f888ff923175fadc2f31f2a"
integrity sha512-Qfs3dWkTMKkKwt78xp2O/KZQB8MPS1UQ5D3YW2s6LQWBE1074BE+Rym+b1pXZIX3M3fSvPUDaCvZLKV2ylVYYQ==
dependencies:
"@typescript-eslint/experimental-utils" "4.18.0"
"@typescript-eslint/scope-manager" "4.18.0"
"@typescript-eslint/experimental-utils" "4.25.0"
"@typescript-eslint/scope-manager" "4.25.0"
debug "^4.1.1"
functional-red-black-tree "^1.0.1"
lodash "^4.17.15"
regexpp "^3.0.0"
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/experimental-utils@4.18.0":
version "4.18.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.18.0.tgz#ed6c955b940334132b17100d2917449b99a91314"
integrity sha512-92h723Kblt9JcT2RRY3QS2xefFKar4ZQFVs3GityOKWQYgtajxt/tuXIzL7sVCUlM1hgreiV5gkGYyBpdOwO6A==
"@typescript-eslint/experimental-utils@4.25.0":
version "4.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.25.0.tgz#b2febcfa715d2c1806fd5f0335193a6cd270df54"
integrity sha512-f0doRE76vq7NEEU0tw+ajv6CrmPelw5wLoaghEHkA2dNLFb3T/zJQqGPQ0OYt5XlZaS13MtnN+GTPCuUVg338w==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/scope-manager" "4.18.0"
"@typescript-eslint/types" "4.18.0"
"@typescript-eslint/typescript-estree" "4.18.0"
"@typescript-eslint/scope-manager" "4.25.0"
"@typescript-eslint/types" "4.25.0"
"@typescript-eslint/typescript-estree" "4.25.0"
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"

Expand All @@ -466,14 +466,6 @@
"@typescript-eslint/typescript-estree" "4.25.0"
debug "^4.1.1"

"@typescript-eslint/scope-manager@4.18.0":
version "4.18.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.18.0.tgz#d75b55234c35d2ff6ac945758d6d9e53be84a427"
integrity sha512-olX4yN6rvHR2eyFOcb6E4vmhDPsfdMyfQ3qR+oQNkAv8emKKlfxTWUXU5Mqxs2Fwe3Pf1BoPvrwZtwngxDzYzQ==
dependencies:
"@typescript-eslint/types" "4.18.0"
"@typescript-eslint/visitor-keys" "4.18.0"

"@typescript-eslint/scope-manager@4.25.0":
version "4.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.25.0.tgz#9d86a5bcc46ef40acd03d85ad4e908e5aab8d4ca"
Expand All @@ -482,29 +474,11 @@
"@typescript-eslint/types" "4.25.0"
"@typescript-eslint/visitor-keys" "4.25.0"

"@typescript-eslint/types@4.18.0":
version "4.18.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.18.0.tgz#bebe323f81f2a7e2e320fac9415e60856267584a"
integrity sha512-/BRociARpj5E+9yQ7cwCF/SNOWwXJ3qhjurMuK2hIFUbr9vTuDeu476Zpu+ptxY2kSxUHDGLLKy+qGq2sOg37A==

"@typescript-eslint/types@4.25.0":
version "4.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.25.0.tgz#0e444a5c5e3c22d7ffa5e16e0e60510b3de5af87"
integrity sha512-+CNINNvl00OkW6wEsi32wU5MhHti2J25TJsJJqgQmJu3B3dYDBcmOxcE5w9cgoM13TrdE/5ND2HoEnBohasxRQ==

"@typescript-eslint/typescript-estree@4.18.0":
version "4.18.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.18.0.tgz#756d3e61da8c16ab99185532c44872f4cd5538cb"
integrity sha512-wt4xvF6vvJI7epz+rEqxmoNQ4ZADArGQO9gDU+cM0U5fdVv7N+IAuVoVAoZSOZxzGHBfvE3XQMLdy+scsqFfeg==
dependencies:
"@typescript-eslint/types" "4.18.0"
"@typescript-eslint/visitor-keys" "4.18.0"
debug "^4.1.1"
globby "^11.0.1"
is-glob "^4.0.1"
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/typescript-estree@4.25.0":
version "4.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.25.0.tgz#942e4e25888736bff5b360d9b0b61e013d0cfa25"
Expand All @@ -518,14 +492,6 @@
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/visitor-keys@4.18.0":
version "4.18.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.18.0.tgz#4e6fe2a175ee33418318a029610845a81e2ff7b6"
integrity sha512-Q9t90JCvfYaN0OfFUgaLqByOfz8yPeTAdotn/XYNm5q9eHax90gzdb+RJ6E9T5s97Kv/UHWKERTmqA0jTKAEHw==
dependencies:
"@typescript-eslint/types" "4.18.0"
eslint-visitor-keys "^2.0.0"

"@typescript-eslint/visitor-keys@4.25.0":
version "4.25.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.25.0.tgz#863e7ed23da4287c5b469b13223255d0fde6aaa7"
Expand Down

0 comments on commit 871b06c

Please sign in to comment.