Skip to content

Commit

Permalink
- Battery as a feature (enabled by default for backwards compatibility)
Browse files Browse the repository at this point in the history
- Refresh tray before opening it (updated battery state #347)
- Get rid of custom DPI settings

Actually, we could move the most code / stuff from device into the feature classes which would allow to get rid of quite some if's in the device code. It would just be (again) quite some refactoring and testing (statemanager) needed.
  • Loading branch information
dhobi committed Apr 27, 2021
1 parent 47f2345 commit 931285d
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/devices/abyssus_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"productId": "0x005B",
"mainType": "mouse",
"image": "https://assets.razerzone.com/eeimages/support/products/721/721_abyssusv2.png",
"featuresMissing": ["none", "waveSimple", "spectrum", "reactive", "breathe"],
"featuresMissing": ["none", "waveSimple", "spectrum", "reactive", "breathe", "battery"],
"featuresConfig": [
{
"static": {
Expand Down
2 changes: 1 addition & 1 deletion src/devices/mamba_elite.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"mainType": "mouse",
"image": "https://assets.razerzone.com/eeimages/support/products/1390/1390_mamba_elite.png",
"features": null,
"featuresMissing": ["oldMouseEffects"],
"featuresMissing": ["oldMouseEffects", "battery"],
"featuresConfig": [
{
"dpi": {
Expand Down
15 changes: 12 additions & 3 deletions src/main/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,9 @@ export class Application {

// mouse dpi rpc listener
ipcMain.on('request-set-dpi', (_, arg) => {
const { device } = arg;
const { device, dpi } = arg;
const currentDevice = this.razerApplication.deviceManager.getByInternalId(device.internalId);
currentDevice.setSettings(device.settings);
currentDevice.setDPI(currentDevice.settings.customSensitivity);
currentDevice.setDPI(dpi);
this.refreshTray();
});

Expand Down Expand Up @@ -292,6 +291,16 @@ export class Application {
// Template.png will be automatically inverted by electron: https://www.electronjs.org/docs/api/native-image#template-image
this.tray = new Tray(path.join(__static, '/assets/iconTemplate.png'));
this.tray.setToolTip('Razer macOS menu');
this.tray.on('click', () => {
if(this.razerApplication.deviceManager.activeRazerDevices != null) {
this.razerApplication.deviceManager.activeRazerDevices.forEach(device => {
if (device !== null) {
device.refresh();
}
});
}
this.refreshTray();
});

this.refreshTray(true);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/device/razerdevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class RazerDevice {
};
}

refresh() {
}

destroy() {
this.addon = null;
}
Expand Down
41 changes: 29 additions & 12 deletions src/main/device/razerdevicemouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ export class RazerDeviceMouse extends RazerDevice {
}

async init() {
this.batteryLevel = this.addon.getBatteryLevel(this.internalId);
this.chargingStatus = this.addon.getChargingStatus(this.internalId);
if(this.hasFeature(FeatureIdentifier.BATTERY)) {
this.batteryLevel = this.addon.getBatteryLevel(this.internalId);
this.chargingStatus = this.addon.getChargingStatus(this.internalId);
}

this.dpi = this.addon.mouseGetDpi(this.internalId);
this.pollRate = this.addon.mouseGetPollRate(this.internalId);
if(this.hasFeature(FeatureIdentifier.MOUSE_DPI)) {
this.dpi = this.addon.mouseGetDpi(this.internalId);
}

if(this.hasFeature(FeatureIdentifier.POLL_RATE)) {
this.pollRate = this.addon.mouseGetPollRate(this.internalId);
}

const featureMouseBrightness = this.getFeature(FeatureIdentifier.MOUSE_BRIGHTNESS);

Expand All @@ -36,17 +43,23 @@ export class RazerDeviceMouse extends RazerDevice {
return super.init();
}

getDefaultSettings() {
return {
customSensitivity: this.getDPI(),
customColor1: this.defaultColorSettings,
refresh() {
super.refresh();
if(this.hasFeature(FeatureIdentifier.BATTERY)) {
this.batteryLevel = this.addon.getBatteryLevel(this.internalId);
this.chargingStatus = this.addon.getChargingStatus(this.internalId);
}
}

getState() {
const deviceState = super.getState();
deviceState['dpi'] = this.dpi;
deviceState['pollRate'] = this.pollRate;
if(this.hasFeature(FeatureIdentifier.MOUSE_DPI)) {
deviceState['dpi'] = this.dpi;
}

if(this.hasFeature(FeatureIdentifier.POLL_RATE)) {
deviceState['pollRate'] = this.pollRate;
}

const featureMouseBrightness = this.getFeature(FeatureIdentifier.MOUSE_BRIGHTNESS);
if(typeof featureMouseBrightness !== 'undefined') {
Expand All @@ -71,8 +84,12 @@ export class RazerDeviceMouse extends RazerDevice {

resetToState(state) {
super.resetToState(state);
this.setDPI(state.dpi);
this.setPollRate(state.pollRate);
if(this.hasFeature(FeatureIdentifier.MOUSE_DPI)) {
this.setDPI(state.dpi);
}
if(this.hasFeature(FeatureIdentifier.POLL_RATE)) {
this.setPollRate(state.pollRate);
}

const featureMouseBrightness = this.getFeature(FeatureIdentifier.MOUSE_BRIGHTNESS);
if(typeof featureMouseBrightness !== 'undefined') {
Expand Down
8 changes: 8 additions & 0 deletions src/main/feature/featurebattery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Feature } from './feature';
import { FeatureIdentifier } from './featureidentifier';

export class FeatureBattery extends Feature {
constructor(config) {
super(FeatureIdentifier.BATTERY, config);
}
}
4 changes: 4 additions & 0 deletions src/main/feature/featurehelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { FeatureMousePollRate } from './featuremousepollrate';
import { FeatureMouseDPI } from './featuremousedpi';
import { RazerDeviceType } from '../device/razerdevicetype';
import { FeatureIdentifier } from './featureidentifier';
import { FeatureBattery } from './featurebattery';

export class FeatureHelper {

Expand All @@ -37,6 +38,7 @@ export class FeatureHelper {
case FeatureIdentifier.MOUSE_BRIGHTNESS: return new FeatureMouseBrightness(configuration);
case FeatureIdentifier.POLL_RATE: return new FeatureMousePollRate(configuration);
case FeatureIdentifier.MOUSE_DPI: return new FeatureMouseDPI(configuration);
case FeatureIdentifier.BATTERY: return new FeatureBattery(configuration);
default:
throw featureIdentifier+' is not a valid feature identifier!'
}
Expand Down Expand Up @@ -69,13 +71,15 @@ export class FeatureHelper {
new FeatureMouseBrightness(),
new FeatureMousePollRate(),
new FeatureMouseDPI(),
new FeatureBattery(),
];
case RazerDeviceType.MOUSEDOCK:
return [
new FeatureNone(),
new FeatureStatic(),
new FeatureSpectrum(),
new FeatureBreathe(),
new FeatureBattery(),
];
case RazerDeviceType.MOUSEMAT:
return [
Expand Down
3 changes: 2 additions & 1 deletion src/main/feature/featureidentifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ FeatureIdentifier.WHEEL = 'wheel';
FeatureIdentifier.OLD_MOUSE_EFFECTS = 'oldMouseEffects';
FeatureIdentifier.MOUSE_BRIGHTNESS = 'mouseBrightness';
FeatureIdentifier.POLL_RATE = 'pollRate';
FeatureIdentifier.MOUSE_DPI = 'dpi';
FeatureIdentifier.MOUSE_DPI = 'dpi';
FeatureIdentifier.BATTERY = 'battery';
4 changes: 3 additions & 1 deletion src/main/menu/menubuilderdevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function getHeaderFor(application, razerDevice) {
case RazerDeviceType.KEYBOARD:
break;
case RazerDeviceType.MOUSE:
if (razerDevice.batteryLevel !== -1) {
if (razerDevice.hasFeature(FeatureIdentifier.BATTERY) && razerDevice.batteryLevel !== -1) {
if (razerDevice.chargingStatus) {
label = label + ' - ⚡' + razerDevice.batteryLevel.toString() + '%';
} else {
Expand Down Expand Up @@ -85,6 +85,8 @@ function getFeatureMenuFor(application, device, feature) {
return null;
case FeatureIdentifier.MOUSE_DPI:
return null;
case FeatureIdentifier.BATTERY:
return null;
default:
throw 'Unmapped feature for identifier ' + feature.featureIdentifier + ' detected.';
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/razerdevicemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ export class RazerDeviceManager {
}

destroy() {
this.activeRazerDevices.forEach(device => {
if (device !== null) {
device.destroy();
}
});
if(this.activeRazerDevices != null) {
this.activeRazerDevices.forEach(device => {
if (device !== null) {
device.destroy();
}
});
}
this.closeDevices();
this.addon = null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/sections/sectionsettingsensitivity.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export class SectionSettingSensitivity extends SectionSettingBlock {
}

handleClick(currentDpi) {
this.deviceSelected.settings.customSensitivity = currentDpi;
let payload = {
device: this.deviceSelected
device: this.deviceSelected,
dpi: currentDpi
};
ipcRenderer.send('request-set-dpi', payload);
};
Expand Down

0 comments on commit 931285d

Please sign in to comment.