This is an automated email from the ASF dual-hosted git repository. jcesarmobile pushed a commit to branch remove-windows in repository https://gitbox.apache.org/repos/asf/cordova-plugin-battery-status.git
commit 7c99d7af028c0f9dc78003cb05b0519256c3cf68 Author: jcesarmobile <[email protected]> AuthorDate: Tue Mar 7 00:44:20 2023 +0100 fix!: remove deprecated windows platform --- README.md | 3 - package.json | 3 +- plugin.xml | 9 -- src/windows/BatteryProxy.js | 130 --------------------- src/windows/BatteryStatus.winmd | Bin 9216 -> 0 bytes src/windows/BatteryStatus/BatteryStatus.sln | 40 ------- src/windows/BatteryStatus/BatteryStatus/.gitignore | 3 - .../BatteryStatus/BatteryStatus/BatteryStatus.cs | 104 ----------------- .../BatteryStatus/BatteryStatus.csproj | 72 ------------ .../BatteryStatus/Properties/AssemblyInfo.cs | 44 ------- tests/tests.js | 81 ++----------- 11 files changed, 13 insertions(+), 476 deletions(-) diff --git a/README.md b/README.md index 2f96060..bca1a8d 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,6 @@ Fires when the battery charge percentage changes by at least 1 percent, or when - iOS - Android -- Windows - Browser (Chrome, Firefox, Opera) ### Quirks: Android @@ -83,7 +82,6 @@ Fires when the battery charge percentage reaches the low charge threshold. This - iOS - Android -- Windows - Browser (Chrome, Firefox, Opera) ## batterycritical event @@ -102,7 +100,6 @@ Fires when the battery charge percentage reaches the critical charge threshold. - iOS - Android -- Windows - Browser (Chrome, Firefox, Opera) diff --git a/package.json b/package.json index 9161763..43f4154 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,7 @@ "platforms": [ "android", "ios", - "browser", - "windows" + "browser" ] }, "repository": "github:apache/cordova-plugin-battery-status", diff --git a/plugin.xml b/plugin.xml index 650d128..e2c6c59 100644 --- a/plugin.xml +++ b/plugin.xml @@ -54,15 +54,6 @@ <source-file src="src/ios/CDVBattery.m" /> </platform> - <!-- windows --> - <platform name="windows"> - <js-module src="src/windows/BatteryProxy.js" name="Battery"> - <runs /> - </js-module> - - <framework src="src/windows/BatteryStatus.winmd" custom="true" target="phone"/> - </platform> - <!-- browser --> <platform name="browser"> <js-module src="src/browser/BatteryProxy.js" name="Battery"> diff --git a/src/windows/BatteryProxy.js b/src/windows/BatteryProxy.js deleted file mode 100644 index 2376a10..0000000 --- a/src/windows/BatteryProxy.js +++ /dev/null @@ -1,130 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/* global Windows, WinJS, BatteryStatus */ - -var PowerManager = Windows && Windows.System && Windows.System.Power && Windows.System.Power.PowerManager; - -if (PowerManager) { - var pluginCallback; - var reportStatus = function () { - if (!pluginCallback) { - return; - } - - pluginCallback( - { - level: PowerManager.remainingChargePercent, - isPlugged: PowerManager.powerSupplyStatus !== Windows.System.Power.PowerSupplyStatus.notPresent - }, - { keepCallback: true } - ); - }; - - var BatteryWin10 = { - start: function (win, fail) { - pluginCallback = win; - PowerManager.addEventListener('remainingchargepercentchanged', reportStatus); - PowerManager.addEventListener('powersupplystatuschanged', reportStatus); - - reportStatus(); - }, - - stop: function () { - if (pluginCallback) { - PowerManager.removeEventListener('remainingchargepercentchanged', reportStatus); - PowerManager.removeEventListener('powersupplystatuschanged', reportStatus); - } - - pluginCallback = null; - } - }; - - require('cordova/exec/proxy').add('Battery', BatteryWin10); -} else { - var stopped; - - var handleResponse = function (successCb, errorCb, jsonResponse) { - var info = JSON.parse(jsonResponse); - - if ({}.hasOwnProperty.call(info, 'exceptionMessage')) { - errorCb(info.exceptionMessage); - return; - } - - successCb(info, { keepCallback: true }); - }; - - var Battery = { - start: function (win, fail, args, env) { - function getBatteryStatus (success, error) { - handleResponse(success, error, BatteryStatus.BatteryStatus.start()); - } - - function getBatteryStatusLevelChangeEvent (success, error) { - return BatteryStatus.BatteryStatus.getBatteryStatusChangeEvent().done( - function (result) { - if (stopped) { - return; - } - - handleResponse(success, error, result); - - setTimeout(function () { - getBatteryStatusLevelChangeEvent(success, error); - }, 0); - }, - function (err) { - fail(err); - } - ); - } - - // Battery API supported on Phone devices only so in case of - // desktop/tablet the only one choice is to fail with appropriate message. - if (!WinJS.Utilities.isPhone) { - fail('The operation is not supported on Windows Desktop devices.'); - return; - } - - stopped = false; - try { - getBatteryStatus(win, fail); - getBatteryStatusLevelChangeEvent(win, fail); - } catch (e) { - fail(e); - } - }, - - stop: function () { - // Battery API supported on Phone devices only so in case of - // desktop/tablet device we don't need for any actions. - if (!WinJS.Utilities.isPhone) { - return; - } - - stopped = true; - BatteryStatus.BatteryStatus.stop(); - } - }; - - require('cordova/exec/proxy').add('Battery', Battery); -} diff --git a/src/windows/BatteryStatus.winmd b/src/windows/BatteryStatus.winmd deleted file mode 100644 index 5000045..0000000 Binary files a/src/windows/BatteryStatus.winmd and /dev/null differ diff --git a/src/windows/BatteryStatus/BatteryStatus.sln b/src/windows/BatteryStatus/BatteryStatus.sln deleted file mode 100644 index d530122..0000000 --- a/src/windows/BatteryStatus/BatteryStatus.sln +++ /dev/null @@ -1,40 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 -MinimumVisualStudioVersion = 10.0.40219.1 -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BatteryStatus", "BatteryStatus\BatteryStatus.csproj", "{9749E0FB-CDCF-4D80-8953-AAB577B44234}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9749E0FB-CDCF-4D80-8953-AAB577B44234}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9749E0FB-CDCF-4D80-8953-AAB577B44234}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9749E0FB-CDCF-4D80-8953-AAB577B44234}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9749E0FB-CDCF-4D80-8953-AAB577B44234}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/src/windows/BatteryStatus/BatteryStatus/.gitignore b/src/windows/BatteryStatus/BatteryStatus/.gitignore deleted file mode 100644 index b84aa9d..0000000 --- a/src/windows/BatteryStatus/BatteryStatus/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/bin/ -/obj/ -*.suo \ No newline at end of file diff --git a/src/windows/BatteryStatus/BatteryStatus/BatteryStatus.cs b/src/windows/BatteryStatus/BatteryStatus/BatteryStatus.cs deleted file mode 100644 index ffb2e01..0000000 --- a/src/windows/BatteryStatus/BatteryStatus/BatteryStatus.cs +++ /dev/null @@ -1,104 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -using System; -using System.IO; -using System.Runtime.Serialization; -using System.Runtime.Serialization.Json; -using System.Threading; -using System.Threading.Tasks; -using Windows.Foundation; -using Windows.Phone.Devices.Power; - -namespace BatteryStatus -{ - public sealed class BatteryStatus - { - private static Battery battery = Battery.GetDefault(); - private static TaskCompletionSource<string> levelCompletionSource = new TaskCompletionSource<string>(); - - public static string start() - { - battery.RemainingChargePercentChanged += BatteryOnRemainingChargePercentChanged; - - return getBatteryStatus(); - } - - public static void stop() - { - battery.RemainingChargePercentChanged -= BatteryOnRemainingChargePercentChanged; - } - - public static string getBatteryStatus() - { - try - { - return Serialize(typeof(BatteryInfo), new BatteryInfo - { - Level = battery.RemainingChargePercent - }); - } - catch (Exception ex) - { - return Serialize(typeof(ExceptionInfo), new ExceptionInfo { Message = ex.Message }); - } - } - - public static IAsyncOperation<string> getBatteryStatusChangeEvent() - { - return GetBatteryStatusChangeEvent().AsAsyncOperation(); - } - - private static async Task<string> GetBatteryStatusChangeEvent() - { - levelCompletionSource = new TaskCompletionSource<string>(); - - return await levelCompletionSource.Task; - } - - private static void BatteryOnRemainingChargePercentChanged(object sender, object o) - { - levelCompletionSource.SetResult(getBatteryStatus()); - } - - private static string Serialize(Type type, object obj) - { - using (var stream = new MemoryStream()) - { - var jsonSer = new DataContractJsonSerializer(type); - jsonSer.WriteObject(stream, obj); - stream.Position = 0; - return new StreamReader(stream).ReadToEnd(); - } - } - - [DataContract] - private class BatteryInfo - { - [DataMember(Name = "level")] - public int Level; - - // Not supported by native API - [DataMember(Name = "isPlugged")] - public string IsPlugged; - }; - - [DataContract] - private class ExceptionInfo - { - [DataMember(Name = "exceptionMessage")] - public string Message = string.Empty; - }; - } -} diff --git a/src/windows/BatteryStatus/BatteryStatus/BatteryStatus.csproj b/src/windows/BatteryStatus/BatteryStatus/BatteryStatus.csproj deleted file mode 100644 index 4e7a087..0000000 --- a/src/windows/BatteryStatus/BatteryStatus/BatteryStatus.csproj +++ /dev/null @@ -1,72 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. ---> -<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> - <PropertyGroup> - <MinimumVisualStudioVersion>12.0</MinimumVisualStudioVersion> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProjectGuid>{9749E0FB-CDCF-4D80-8953-AAB577B44234}</ProjectGuid> - <OutputType>winmdobj</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>BatteryStatus</RootNamespace> - <AssemblyName>BatteryStatus</AssemblyName> - <DefaultLanguage>en-US</DefaultLanguage> - <FileAlignment>512</FileAlignment> - <ProjectTypeGuids>{76F1466A-8B6D-4E39-A767-685A06062A39};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> - <TargetPlatformIdentifier>WindowsPhoneApp</TargetPlatformIdentifier> - <TargetPlatformVersion>8.1</TargetPlatformVersion> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <ItemGroup> - <!-- A reference to the entire .NET Framework is automatically included --> - </ItemGroup> - <ItemGroup> - <Compile Include="BatteryStatus.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - </ItemGroup> - <Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" /> - <PropertyGroup> - <PostBuildEvent>xcopy /Y /Q "$(TargetPath)" "$(SolutionDir).."</PostBuildEvent> - </PropertyGroup> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - --> -</Project> diff --git a/src/windows/BatteryStatus/BatteryStatus/Properties/AssemblyInfo.cs b/src/windows/BatteryStatus/BatteryStatus/Properties/AssemblyInfo.cs deleted file mode 100644 index 2b13e4d..0000000 --- a/src/windows/BatteryStatus/BatteryStatus/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,44 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -using System.Resources; -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("BatteryStatus")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("BatteryStatus")] -[assembly: AssemblyCopyright("Copyright © 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: NeutralResourcesLanguage("en")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/tests/tests.js b/tests/tests.js index addafcf..81b7695 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -21,23 +21,11 @@ /* global Windows, WinJS, cordova */ exports.defineAutoTests = function () { - var hasPowerManagerAPI = - cordova.platformId === 'windows' && Windows && Windows.System && Windows.System.Power && Windows.System.Power.PowerManager; - - var batteryStatusUnsupported = - (cordova.platformId === 'windows8' || - // We don't test battery status on Windows when there is no corresponding APIs available - cordova.platformId === 'windows') && - !(hasPowerManagerAPI || WinJS.Utilities.isPhone); var onEvent; describe('Battery (navigator.battery)', function () { it('battery.spec.1 should exist', function () { - if (batteryStatusUnsupported) { - pending('Battery status is not supported on windows store'); - } - expect(navigator.battery).toBeDefined(); }); }); @@ -45,20 +33,14 @@ exports.defineAutoTests = function () { describe('Battery Events', function () { describe('batterystatus', function () { afterEach(function () { - if (!batteryStatusUnsupported) { - try { - window.removeEventListener('batterystatus', onEvent, false); - } catch (e) { - console.error('Error removing batterystatus event listener: ' + e); - } + try { + window.removeEventListener('batterystatus', onEvent, false); + } catch (e) { + console.error('Error removing batterystatus event listener: ' + e); } }); it('battery.spec.2 should fire batterystatus events', function (done) { - if (batteryStatusUnsupported) { - pending('Battery status is not supported on windows store'); - } - onEvent = jasmine.createSpy('BatteryStatus'); // batterystatus -> 30 @@ -78,20 +60,14 @@ exports.defineAutoTests = function () { describe('batterylow', function () { afterEach(function () { - if (!batteryStatusUnsupported) { - try { - window.removeEventListener('batterylow', onEvent, false); - } catch (e) { - console.error('Error removing batterylow event listener: ' + e); - } + try { + window.removeEventListener('batterylow', onEvent, false); + } catch (e) { + console.error('Error removing batterylow event listener: ' + e); } }); it('battery.spec.3 should fire batterylow event (30 -> 20)', function (done) { - if (batteryStatusUnsupported) { - pending('Battery status is not supported on windows store'); - } - onEvent = jasmine.createSpy('BatteryLow'); // batterylow 30 -> 20 @@ -114,10 +90,6 @@ exports.defineAutoTests = function () { }); it('battery.spec.3.1 should fire batterylow event (30 -> 19)', function (done) { - if (batteryStatusUnsupported) { - pending('Battery status is not supported on windows store'); - } - onEvent = jasmine.createSpy('BatteryLow'); // batterylow 30 -> 19 @@ -140,10 +112,6 @@ exports.defineAutoTests = function () { }); it('battery.spec.3.2 should not fire batterylow event (5 -> 20)', function (done) { - if (batteryStatusUnsupported) { - pending('Battery status is not supported on windows store'); - } - onEvent = jasmine.createSpy('BatteryLow'); // batterylow should not fire when level increases (5->20) ( CB-4519 ) @@ -166,10 +134,6 @@ exports.defineAutoTests = function () { }); it('battery.spec.3.3 batterylow event(21 -> 20) should not fire if charging', function (done) { - if (batteryStatusUnsupported) { - pending('Battery status is not supported on windows store'); - } - onEvent = jasmine.createSpy('BatteryLow'); // batterylow should NOT fire if we are charging ( CB-4520 ) @@ -194,20 +158,14 @@ exports.defineAutoTests = function () { describe('batterycritical', function () { afterEach(function () { - if (!batteryStatusUnsupported) { - try { - window.removeEventListener('batterycritical', onEvent, false); - } catch (e) { - console.error('Error removing batterycritical event listener: ' + e); - } + try { + window.removeEventListener('batterycritical', onEvent, false); + } catch (e) { + console.error('Error removing batterycritical event listener: ' + e); } }); it('battery.spec.4 should fire batterycritical event (19 -> 5)', function (done) { - if (batteryStatusUnsupported) { - pending('Battery status is not supported on windows store'); - } - onEvent = jasmine.createSpy('BatteryCritical'); // batterycritical 19->5 @@ -230,10 +188,6 @@ exports.defineAutoTests = function () { }); it('battery.spec.4.1 should fire batterycritical event (19 -> 4)', function (done) { - if (batteryStatusUnsupported) { - pending('Battery status is not supported on windows store'); - } - onEvent = jasmine.createSpy('BatteryCritical'); // batterycritical 19->4 @@ -256,10 +210,6 @@ exports.defineAutoTests = function () { }); it('battery.spec.4.2 should fire batterycritical event (100 -> 4) when decreases', function (done) { - if (batteryStatusUnsupported) { - pending('Battery status is not supported on windows store'); - } - onEvent = jasmine.createSpy('BatteryCritical'); // setup: batterycritical should fire when level decreases (100->4) ( CB-4519 ) @@ -282,10 +232,6 @@ exports.defineAutoTests = function () { }); it('battery.spec.4.3 should not fire batterycritical event (4 -> 5) when increasing', function (done) { - if (batteryStatusUnsupported) { - pending('Battery status is not supported on windows store'); - } - onEvent = jasmine.createSpy('BatteryCritical'); window.addEventListener('batterycritical', onEvent, false); @@ -308,9 +254,6 @@ exports.defineAutoTests = function () { }); it('battery.spec.4.4 should not fire batterycritical event (6 -> 5) if charging', function (done) { - if (batteryStatusUnsupported) { - pending('Battery status is not supported on windows store'); - } onEvent = jasmine.createSpy('BatteryCritical'); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
