From 19d869b41599f3c4b15e1165d45fbd37de07a434 Mon Sep 17 00:00:00 2001 From: jparez Date: Wed, 4 Sep 2024 09:25:32 +0200 Subject: [PATCH] cleanup old redis events --- README.md | 2 +- index.d.ts | 9 --- src/plugins/Battery.js | 8 --- src/plugins/Clipboard.js | 5 -- src/plugins/FileUpload.js | 7 --- src/plugins/IOThrottling.js | 3 - src/plugins/Identifiers.js | 8 --- src/plugins/Network.js | 3 - tests/unit/battery.test.js | 29 --------- tests/unit/clipboard.test.js | 5 -- tests/unit/fileupload.test.js | 103 -------------------------------- tests/unit/identifiers.test.js | 28 --------- tests/unit/iothrottling.test.js | 23 ------- tests/unit/network.test.js | 14 ----- 14 files changed, 1 insertion(+), 246 deletions(-) diff --git a/README.md b/README.md index f5383285..0dc458ee 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ The Player API provides functionality for managing plugin options and websocket - Parameters: - - event (string): The name of the event to listen for. Example events include 'fingerprint', 'gps', and 'BATTERY_LEVEL'... + - event (string): The name of the event to listen for. Example events include 'fingerprint', 'gps'... - callback (function): The function to call when the event is emitted. The message from the VM will be passed as an argument to the callback function. - Example Usage diff --git a/index.d.ts b/index.d.ts index dace9f96..315d89aa 100644 --- a/index.d.ts +++ b/index.d.ts @@ -36,24 +36,15 @@ type DeviceRendererKeyMapping = { }; type VmEvent = - | 'ANDROID_ID' | 'baseband' - | 'BATTERY_LEVEL' - | 'BATTERY_STATUS' | 'battery' | 'beforeunload' - | 'BLK' - | 'CLIPBOARD' | 'diskio' | 'fingerprint' | 'framework' | 'gps' - | 'IMEI' | 'network_profile' - | 'NETWORK' | 'settings' - | 'SYSTEM_PATCHER_LAST_RESULT' - | 'SYSTEM_PATCHER_STATUS' | 'systempatcher' | 'vinput' | string; // This list is not exhaustive and should be completed diff --git a/src/plugins/Battery.js b/src/plugins/Battery.js index 10057f9a..35462618 100644 --- a/src/plugins/Battery.js +++ b/src/plugins/Battery.js @@ -23,18 +23,10 @@ module.exports = class Battery extends OverlayPlugin { // Register plugin this.instance.battery = this; - // Listen for initial battery charging status - this.instance.registerEventCallback('BATTERY_STATUS', (value) => { - this.updateUIBatteryChargingState(value !== 'false'); - }); - // Display widget this.renderToolbarButton(); this.renderWidget(); - // Listen for initial battery level - this.instance.registerEventCallback('BATTERY_LEVEL', this.onBatteryLevelChange.bind(this)); - // Listen for battery messages: "state mode " this.instance.registerEventCallback('battery', (message) => { const values = message.split(' ').splice(-2); diff --git a/src/plugins/Clipboard.js b/src/plugins/Clipboard.js index 00d72981..5207fa3b 100644 --- a/src/plugins/Clipboard.js +++ b/src/plugins/Clipboard.js @@ -46,11 +46,6 @@ module.exports = class Clipboard extends OverlayPlugin { log.warn('Malformed clipboard content'); } }); - - // Listen for initial clipboard status - this.instance.registerEventCallback('CLIPBOARD', (text) => { - this.clipboard = text; - }); } /** diff --git a/src/plugins/FileUpload.js b/src/plugins/FileUpload.js index 60676df1..7610f50f 100644 --- a/src/plugins/FileUpload.js +++ b/src/plugins/FileUpload.js @@ -94,13 +94,6 @@ module.exports = class FileUpload extends OverlayPlugin { this.renderToolbarButton(); this.renderWidget(); - // Listen for events - this.instance.registerEventCallback('SYSTEM_PATCHER_STATUS', this.onSystemPatcherStatusEvent.bind(this)); - this.instance.registerEventCallback( - 'SYSTEM_PATCHER_LAST_RESULT', - this.onSystemPatcherLastResultEvent.bind(this), - ); - /* * Listen for systempatcher messages: "status " * or "last_result _error " diff --git a/src/plugins/IOThrottling.js b/src/plugins/IOThrottling.js index 01a7f39a..a5e44363 100644 --- a/src/plugins/IOThrottling.js +++ b/src/plugins/IOThrottling.js @@ -33,9 +33,6 @@ module.exports = class IOThrottling extends OverlayPlugin { this.renderToolbarButton(); this.renderWidget(); - // Listen for initial diskio - this.instance.registerEventCallback('BLK', this.setActive.bind(this)); - // Listen for diskio messages: "readbyterate " (or "cachecleared") this.instance.registerEventCallback('diskio', (message) => { const values = message.split(' '); diff --git a/src/plugins/Identifiers.js b/src/plugins/Identifiers.js index 19faa635..8f253535 100644 --- a/src/plugins/Identifiers.js +++ b/src/plugins/Identifiers.js @@ -34,14 +34,6 @@ module.exports = class Identifiers extends OverlayPlugin { this.renderToolbarButton(); this.renderWidget(); - // Listen for IDs from renderer - this.instance.registerEventCallback('ANDROID_ID', (payload) => { - this.androidInput.value = payload; - }); - this.instance.registerEventCallback('IMEI', (payload) => { - this.deviceInput.value = payload; - }); - // Listen for settings messages: "parameter :" this.instance.registerEventCallback('settings', (message) => { const values = message.split(' '); diff --git a/src/plugins/Network.js b/src/plugins/Network.js index b8b248ba..e3b59a8a 100644 --- a/src/plugins/Network.js +++ b/src/plugins/Network.js @@ -51,9 +51,6 @@ module.exports = class Network extends OverlayPlugin { // Listen for settings messages: "if wifi:on|off mobile:on|off" this.instance.registerEventCallback('settings', this.handleSettings.bind(this)); - // Listen for initial network - this.instance.registerEventCallback('NETWORK', this.setActiveProfile.bind(this)); - /* * Listen for network messages: * state wifi up_rate:: diff --git a/tests/unit/battery.test.js b/tests/unit/battery.test.js index 64333127..fcb2cec1 100644 --- a/tests/unit/battery.test.js +++ b/tests/unit/battery.test.js @@ -65,35 +65,6 @@ describe('Battery Plugin', () => { levelMock.mockRestore(); }); - test('BATTERY_STATUS', () => { - instance.emit('BATTERY_STATUS', 'jean-michel'); // Invalid value (=== charging) - expect(battery.chargingInput.checked).toBeTruthy(); - - instance.emit('BATTERY_STATUS', 'false'); // Discharging - expect(battery.chargingInput.checked).toBeFalsy(); - - instance.emit('BATTERY_STATUS', 'true'); // Charging - expect(battery.chargingInput.checked).toBeTruthy(); - }); - - test('BATTERY_LEVEL', () => { - instance.emit('BATTERY_LEVEL', 'jean-michel'); // Invalid value - expect(Number(battery.chargeSlider.value)).toBe(50); - expect(Number(battery.chargeInput.value)).toBe(50); - - instance.emit('BATTERY_LEVEL', '69'); // Nice - expect(Number(battery.chargeSlider.value)).toBe(69); - expect(Number(battery.chargeInput.value)).toBe(69); - - instance.emit('BATTERY_LEVEL', '666'); // Overflow - expect(Number(battery.chargeSlider.value)).toBe(100); - expect(Number(battery.chargeInput.value)).toBe(100); - - instance.emit('BATTERY_LEVEL', '-420'); // Underflow - expect(Number(battery.chargeSlider.value)).toBe(0); - expect(Number(battery.chargeInput.value)).toBe(0); - }); - test('battery', () => { instance.emit('battery', 'jean-michel'); // Bad format expect(levelMock).not.toHaveBeenCalled(); diff --git a/tests/unit/clipboard.test.js b/tests/unit/clipboard.test.js index cbe8009b..f2787ad6 100644 --- a/tests/unit/clipboard.test.js +++ b/tests/unit/clipboard.test.js @@ -59,11 +59,6 @@ describe('Clipboard Plugin', () => { }); describe('incoming events', () => { - test('CLIPBOARD', () => { - instance.emit('CLIPBOARD', 'test value'); - expect(clipboard.clipboard).toBe('test value'); - }); - test('framework', () => { instance.emit('framework', 'clipboard too many arguments'); expect(clipboard.clipboard).toBe(''); diff --git a/tests/unit/fileupload.test.js b/tests/unit/fileupload.test.js index fc5af7a3..8b73e7c3 100644 --- a/tests/unit/fileupload.test.js +++ b/tests/unit/fileupload.test.js @@ -115,112 +115,9 @@ describe('FileUpload Plugin', () => { uploader.toggleWidget(); expect(uploader.currentStep).toEqual('homeScreen'); }); - - test('Dont force show on success', () => { - uploader.flashing = false; - uploader.displayStep('uploadScreen'); - expect(document.getElementsByClassName('gm-hidden').length).toEqual(1); - instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'success'); - expect(document.getElementsByClassName('gm-hidden').length).toEqual(1); - }); - - test('dont force show on error', () => { - uploader.flashing = false; - uploader.displayStep('uploadScreen'); - expect(document.getElementsByClassName('gm-hidden').length).toEqual(1); - instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'install_error'); - expect(document.getElementsByClassName('gm-hidden').length).toEqual(1); - }); - - test('force show on opengapps success', () => { - uploader.flashing = true; - uploader.displayStep('uploadScreen'); - expect(document.getElementsByClassName('gm-hidden').length).toEqual(1); - instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'success'); - expect(document.getElementsByClassName('gm-hidden').length).toEqual(0); - }); - - test('force show on opengapps error', () => { - uploader.flashing = true; - uploader.displayStep('uploadScreen'); - expect(document.getElementsByClassName('gm-hidden').length).toEqual(1); - instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'install_error'); - expect(document.getElementsByClassName('gm-hidden').length).toEqual(0); - }); }); describe('incoming events', () => { - describe('SYSTEM_PATCHER_STATUS', () => { - test('downloading', () => { - uploader.displayStep('uploadScreen'); - const textProgress = document.getElementsByClassName('gm-upload-in-progress-txt-percent')[0]; - - instance.emit('SYSTEM_PATCHER_STATUS', 'downloading something'); // Not enough parameters - expect(textProgress.innerHTML).toBe(''); - - instance.emit('SYSTEM_PATCHER_STATUS', 'downloading 69 100'); - expect(textProgress.innerHTML).toBe('69%'); // Nice - }); - - test('installing', () => { - uploader.displayStep('uploadScreen'); - const textProgress = document.getElementsByClassName('gm-upload-in-progress-txt-progress')[0]; - - instance.emit('SYSTEM_PATCHER_STATUS', 'installing'); - expect(textProgress.innerHTML).toBe('TEST UPLOADER PLUGIN INSTALLING...'); - }); - - test('ready', () => { - const updateOpenGAppsStatus = jest.spyOn(uploader, 'updateOpenGAppsStatus'); - const sendEventSpy = jest.spyOn(instance, 'sendEvent'); - - instance.emit('SYSTEM_PATCHER_STATUS', 'ready'); // Not enough parameters - expect(updateOpenGAppsStatus).toHaveBeenCalledTimes(0); - - instance.emit('SYSTEM_PATCHER_STATUS', 'ready something'); - expect(updateOpenGAppsStatus).toHaveBeenCalledTimes(0); - - // Asumes uploader.flashing = false, default - instance.emit('SYSTEM_PATCHER_STATUS', 'ready opengapps'); - expect(updateOpenGAppsStatus).toHaveBeenCalledTimes(1); - expect(sendEventSpy).toHaveBeenCalledTimes(0); - - uploader.flashing = true; - instance.emit('SYSTEM_PATCHER_STATUS', 'ready opengapps'); - expect(updateOpenGAppsStatus).toHaveBeenCalledTimes(2); - expect(sendEventSpy).toHaveBeenCalledTimes(1); - expect(instance.outgoingMessages[0]).toEqual({ - channel: 'systempatcher', - messages: ['notify last_result'], - }); - }); - }); - - test('SYSTEM_PATCHER_LAST_RESULT', () => { - const displayStep = jest.spyOn(uploader, 'displayStep'); - - instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'success'); - expect(displayStep).toHaveBeenNthCalledWith(1, 'successScreen'); - - instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'unavailable'); - expect(displayStep).toHaveBeenNthCalledWith(2, 'errorScreen'); - - instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'network_error'); - expect(displayStep).toHaveBeenNthCalledWith(3, 'errorScreen'); - - instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'corrupted_archive'); - expect(displayStep).toHaveBeenNthCalledWith(4, 'errorScreen'); - - instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'install_error'); - expect(displayStep).toHaveBeenNthCalledWith(5, 'errorScreen'); - - instance.emit('SYSTEM_PATCHER_LAST_RESULT', 'something'); - expect(displayStep).toHaveBeenCalledTimes(5); - - instance.emit('SYSTEM_PATCHER_LAST_RESULT', ''); - expect(displayStep).toHaveBeenCalledTimes(5); - }); - test('systempatcher', () => { const onSystemPatcherStatusEvent = jest.spyOn(uploader, 'onSystemPatcherStatusEvent'); const onSystemPatcherLastResultEvent = jest.spyOn(uploader, 'onSystemPatcherLastResultEvent'); diff --git a/tests/unit/identifiers.test.js b/tests/unit/identifiers.test.js index ceaa107c..4c57b6b7 100644 --- a/tests/unit/identifiers.test.js +++ b/tests/unit/identifiers.test.js @@ -60,34 +60,6 @@ describe('Identifiers Plugin', () => { }); describe('incoming events', () => { - test('ANDROID_ID', () => { - ['jean-michel', '123', '0123456789abcdef0', ''].forEach((invalidValue) => { - instance.emit('ANDROID_ID', invalidValue); - identifiers.validateAndroidId(); - expect(identifiers.invalidAndroidId).toBeTruthy(); - }); - - ['0123456789abcdef'].forEach((validValue) => { - instance.emit('ANDROID_ID', validValue); - identifiers.validateAndroidId(); - expect(identifiers.invalidAndroidId).toBeFalsy(); - }); - }); - - test('IMEI', () => { - ['jean-michel', '123', '', '0123456789abcdef'].forEach((invalidValue) => { - instance.emit('IMEI', invalidValue); - identifiers.validateDeviceId(); - expect(identifiers.invalidDeviceId).toBeTruthy(); - }); - - ['0123456789abcd', '0123456789abcde'].forEach((validValue) => { - instance.emit('IMEI', validValue); - identifiers.validateDeviceId(); - expect(identifiers.invalidDeviceId).toBeFalsy(); - }); - }); - describe('settings', () => { test('unrelevant topics', () => { ['unrelevant', 'parameters unrelevant:value', ''].forEach((invalidValue) => { diff --git a/tests/unit/iothrottling.test.js b/tests/unit/iothrottling.test.js index 6862f772..76aa43e2 100644 --- a/tests/unit/iothrottling.test.js +++ b/tests/unit/iothrottling.test.js @@ -57,29 +57,6 @@ describe('IOThrottling Plugin', () => { }); describe('incoming events', () => { - test('BLK', () => { - ['jean-michel', '-123', ''].forEach((invalidValue) => { - instance.emit('BLK', invalidValue); - expect(diskio.select.value).toBe('None'); - }); - - [69, 420].forEach((customValue) => { - instance.emit('BLK', customValue * 1024); - expect(diskio.select.value).toBe('Custom'); - expect(Number(diskio.readByteRate.value)).toBe(customValue); - }); - - IOThrottlingProfiles.forEach((profile) => { - if (!profile.readByteRate) { - return; - } - - instance.emit('BLK', profile.readByteRate * 1024); - expect(diskio.select.value).toBe(profile.name); - expect(Number(diskio.readByteRate.value)).toBe(profile.readByteRate); - }); - }); - test('diskio', () => { ['jean-michel', 'readbyterate -123', '', 'readbyterate invalid'].forEach((invalidValue) => { instance.emit('diskio', invalidValue); diff --git a/tests/unit/network.test.js b/tests/unit/network.test.js index 3d556087..010b83a0 100644 --- a/tests/unit/network.test.js +++ b/tests/unit/network.test.js @@ -54,20 +54,6 @@ describe('Network Plugin', () => { // render default widget network.disableMobileThrottling(); }); - test('NETWORK', () => { - const loadDetails = jest.spyOn(network, 'loadDetails'); - - ['jean-michel', '-123', '', '9'].forEach((invalidValue) => { - instance.emit('NETWORK', invalidValue); - expect(loadDetails).not.toHaveBeenCalled(); - }); - - NetworkProfiles.forEach((profile) => { - instance.emit('NETWORK', profile.id); - expect(loadDetails).toHaveBeenCalledWith(NetworkProfiles[NetworkProfiles.length - 1 - profile.id]); - loadDetails.mockReset(); - }); - }); test('network_profile', () => { const loadDetails = jest.spyOn(network, 'loadDetails');