Skip to content

Commit 8c78f8c

Browse files
authored
Merge pull request #2736 from UltimateHackingKeyboard/fix-disable-eyedropper-on-wayland
fix: disable eyeDropper of color picker on Wayland
2 parents ec4e2fa + c8955a8 commit 8c78f8c

File tree

11 files changed

+50
-4
lines changed

11 files changed

+50
-4
lines changed

packages/uhk-agent/src/services/app.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as os from 'os';
55
import { AppStartInfo, CommandLineArgs, IpcEvents, LogService } from 'uhk-common';
66
import { MainServiceBase } from './main-service-base';
77
import { DeviceService } from './device.service';
8-
import { getUdevFileContentAsync } from '../util';
8+
import { getUdevFileContentAsync, isRunningOnWayland } from '../util';
99

1010
export class AppService extends MainServiceBase {
1111
constructor(protected logService: LogService,
@@ -43,6 +43,7 @@ export class AppService extends MainServiceBase {
4343
'disable-agent-update-protection': this.options['disable-agent-update-protection'] || false,
4444
log: this.options.log
4545
},
46+
isRunningOnWayland: isRunningOnWayland(),
4647
platform: process.platform as string,
4748
osVersion: os.release(),
4849
udevFileContent: await getUdevFileContentAsync(this.rootDir)

packages/uhk-agent/src/util/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export * from './get-updater-logger';
1212
export * from './get-user-config-from-history-async';
1313
export * from './get-user-config-history-dir-async';
1414
export * from './get-window-background-color';
15+
export * from './is-running-on-wayland';
1516
export * from './load-user-config-from-binary-file';
1617
export * from './load-user-config-history-async';
1718
export * from './make-folder-writeable-to-user-on-linux';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import process from "node:process";
2+
3+
export function isRunningOnWayland(): boolean {
4+
return !!(process.env.WAYLAND_DISPLAY ||
5+
process.env.XDG_SESSION_TYPE === 'wayland' ||
6+
process.env.GDK_BACKEND === 'wayland');
7+
}

packages/uhk-common/src/models/app-start-info.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export interface AppStartInfo {
55
platform: string;
66
osVersion: string;
77
udevFileContent: string;
8+
isRunningOnWayland: boolean;
89
}

packages/uhk-web/src/app/components/device/led-settings/functional-backlight-color.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(colorPickerSelect)="onColorChanged($event)"
55
cpOutputFormat="hex"
66
[cpSaveClickOutside]="false"
7-
[cpEyeDropper]="true"
7+
[cpEyeDropper]
88
[cpOKButton]="true"
99
cpOKButtonClass="btn btn-primary"
1010
[cpCancelButton]="true"

packages/uhk-web/src/app/components/layers/colors/color-palette-button.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[(colorPicker)]="editColor"
33
cpOutputFormat="hex"
44
[cpSaveClickOutside]="false"
5-
[cpEyeDropper]="true"
5+
[cpEyeDropper]
66
[cpOKButton]="true"
77
cpOKButtonClass="btn btn-primary"
88
[cpCancelButton]="true"

packages/uhk-web/src/app/components/layers/layers.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
(colorPickerSelect)="onAddColor($event)"
5353
cpOutputFormat="hex"
5454
[cpSaveClickOutside]="false"
55-
[cpEyeDropper]="true"
55+
[cpEyeDropper]
5656
[cpOKButton]="true"
5757
cpOKButtonClass="btn btn-primary"
5858
[cpCancelButton]="true"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Directive, OnDestroy, OnInit } from '@angular/core';
2+
import { Store } from '@ngrx/store';
3+
import { ColorPickerDirective } from 'ngx-color-picker';
4+
import { Subscription } from 'rxjs';
5+
6+
import { AppState, isColorPickerEyeDropperEnabled } from '../store/index';
7+
8+
@Directive({
9+
selector: '[cpEyeDropper]',
10+
standalone: true,
11+
})
12+
export class NgxColorPickerEyeDropper implements OnDestroy, OnInit {
13+
private subscription: Subscription;
14+
15+
constructor(private store: Store<AppState>,
16+
private colorPicker: ColorPickerDirective) {
17+
}
18+
19+
ngOnInit() {
20+
this.subscription = this.store.select(isColorPickerEyeDropperEnabled)
21+
.subscribe(value => {
22+
this.colorPicker.cpEyeDropper = value;
23+
})
24+
}
25+
26+
ngOnDestroy() {
27+
this.subscription?.unsubscribe();
28+
}
29+
}

packages/uhk-web/src/app/shared.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ import { appRoutingProviders, routing } from './app.routes';
9999
import { UhkAgentIconComponent } from './components/uhk-icon/uhk-agent-icon.component';
100100

101101
import { CancelableDirective, ExternalUrlDirective } from './directives';
102+
import { NgxColorPickerEyeDropper } from './directives/ngx-color-picker-eye-dropper';
102103
import {
103104
AsHexColorPipe,
104105
EscapeHtmlPipe,
@@ -292,6 +293,7 @@ import appInitFactory from './services/app-init-factory';
292293
imports: [
293294
AngularSplitModule,
294295
CommonModule,
296+
NgxColorPickerEyeDropper,
295297
ColorPickerDirective,
296298
BrowserAnimationsModule,
297299
FontAwesomeModule,

packages/uhk-web/src/app/store/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ export const getUhkThemeColors = createSelector(getAppTheme, (theme): UhkThemeCo
202202
return defaultUhkThemeColors(theme);
203203
});
204204
export const getPlatform = createSelector(appState, fromApp.getPlatform);
205+
export const isColorPickerEyeDropperEnabled = createSelector(appState, fromApp.isColorPickerEyeDropperEnabled);
205206

206207
export const appUpdateState = (state: AppState) => state.appUpdate;
207208
export const getShowAppUpdateAvailable = createSelector(appUpdateState, fromAppUpdate.getShowAppUpdateAvailable);

0 commit comments

Comments
 (0)