Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Ti.Platform.versionPatch and global.OS_VERSION_PATCH #11967

Merged
merged 6 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class PlatformModule extends KrollModule
private List<Processor> processors;
private int versionMajor;
private int versionMinor;
private int versionPatch;
protected int batteryState;
protected double batteryLevel;
protected boolean batteryStateReady;
Expand All @@ -92,6 +93,9 @@ public PlatformModule()
this.versionMajor = Integer.parseInt(versionComponents[0]);
if (versionComponents.length >= 2) {
this.versionMinor = Integer.parseInt(versionComponents[1]);
if (versionComponents.length >= 3) {
this.versionPatch = Integer.parseInt(versionComponents[2]);
}
}
} catch (Exception ex) {
Log.e(TAG, "Failed to parse OS version string.", ex);
Expand Down Expand Up @@ -163,6 +167,12 @@ public int getVersionMinor()
return this.versionMinor;
}

@Kroll.getProperty
public int getVersionPatch()
{
return this.versionPatch;
}

@Kroll.method
@Kroll.getProperty
public double getAvailableMemory()
Expand Down
11 changes: 11 additions & 0 deletions apidoc/Global/Global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,17 @@ properties:
permission: read-only
since: "9.2.0"

- name: OS_VERSION_PATCH
summary: The operating system's patch version number.
description: |
This returns the same value as the <Titanium.Platform.versionPatch> property.

Will return zero if the OS does not have a patch version.
type: Number
default: 0
permission: read-only
since: "9.2.0"

- name: ENV_DEV
summary: Alias for <ENV_DEVELOPMENT>
type: Boolean
Expand Down
11 changes: 11 additions & 0 deletions apidoc/Titanium/Platform/Platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,17 @@ properties:
permission: read-only
since: "9.2.0"

- name: versionPatch
summary: The operating system's patch version number.
description: |
This returns the same value as the [OS_VERSION_PATCH](Global.OS_VERSION_PATCH) constant.

Will return zero if the OS does not have a patch version.
type: Number
default: 0
permission: read-only
since: "9.2.0"

examples:
- title: Battery Event Example
example: |
Expand Down
3 changes: 2 additions & 1 deletion common/Resources/ti.internal/extensions/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ Object.defineProperties(global, {
'OS_ANDROID': { value: OS_ANDROID, writable: false },
'OS_IOS': { value: OS_IOS, writable: false },
OS_VERSION_MAJOR: { value: Ti.Platform.versionMajor, writable: false },
OS_VERSION_MINOR: { value: Ti.Platform.versionMinor, writable: false }
OS_VERSION_MINOR: { value: Ti.Platform.versionMinor, writable: false },
OS_VERSION_PATCH: { value: Ti.Platform.versionPatch, writable: false }
});
1 change: 1 addition & 0 deletions iphone/Classes/PlatformModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ READONLY_PROPERTY(NSString *, username, Username);
READONLY_PROPERTY(NSString *, version, Version);
READONLY_PROPERTY(NSNumber *, versionMajor, VersionMajor);
READONLY_PROPERTY(NSNumber *, versionMinor, VersionMinor);
READONLY_PROPERTY(NSNumber *, versionPatch, VersionPatch);

// Methods
- (BOOL)canOpenURL:(NSString *)url;
Expand Down
21 changes: 14 additions & 7 deletions iphone/Classes/PlatformModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,30 @@

@implementation PlatformModule

@synthesize architecture, availableMemory, model, name, osname, ostype, processorCount, totalMemory, uptime, username, version, versionMajor, versionMinor;
@synthesize architecture, availableMemory, model, name, osname, ostype, processorCount, totalMemory, uptime, username, version, versionMajor, versionMinor, versionPatch;

#pragma mark Internal

- (id)init
{
if (self = [super init]) {
UIDevice *theDevice = [UIDevice currentDevice];
name = [[theDevice systemName] retain];
version = [[theDevice systemVersion] retain];
UIDevice *theDevice = UIDevice.currentDevice;
name = [theDevice.systemName retain];
version = [theDevice.systemVersion retain];

// Extract "<major>.<minor>" integers from OS version string.
NSArray *versionComponents = [version componentsSeparatedByString:@"."];
versionMajor = [NSNumber numberWithInt:[versionComponents[0] intValue]];
if ([versionComponents count] >= 2) {
versionMinor = [NSNumber numberWithInt:[versionComponents[1] intValue]];
if ([versionComponents count] >= 3) {
versionPatch = [NSNumber numberWithInt:[versionComponents[2] intValue]];
} else {
versionPatch = @0;
}
} else {
versionMinor = @0;
versionPatch = @0;
}

// grab logical CPUs
Expand All @@ -58,7 +64,7 @@ - (id)init
}
processorCount = [[NSNumber numberWithInt:cores] retain];

username = [[theDevice name] retain];
username = [theDevice.name retain];
#ifdef __LP64__
ostype = [@"64bit" retain];
#else
Expand All @@ -73,7 +79,7 @@ - (id)init
osname = [@"iphone" retain];
}

NSString *themodel = [theDevice model];
NSString *themodel = theDevice.model;

// attempt to determine extended phone info
struct utsname u;
Expand All @@ -88,7 +94,7 @@ - (id)init
architecture = [[TiUtils currentArchitecture] retain];

// needed for platform displayCaps orientation to be correct
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[theDevice beginGeneratingDeviceOrientationNotifications];
}
return self;
}
Expand All @@ -100,6 +106,7 @@ - (void)dealloc
RELEASE_TO_NIL(version);
RELEASE_TO_NIL(versionMajor);
RELEASE_TO_NIL(versionMinor);
RELEASE_TO_NIL(versionPatch);
RELEASE_TO_NIL(architecture);
RELEASE_TO_NIL(processorCount);
RELEASE_TO_NIL(username);
Expand Down
11 changes: 10 additions & 1 deletion tests/Resources/ti.platform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* global OS_VERSION_MAJOR, OS_VERSION_MINOR, OS_IOS */
/* global OS_VERSION_MAJOR, OS_VERSION_MINOR, OS_VERSION_PATCH, OS_IOS */
/* eslint-env mocha */
/* eslint no-unused-expressions: "off" */
'use strict';
Expand Down Expand Up @@ -308,6 +308,15 @@ describe('Titanium.Platform', function () {
should(Ti.Platform.versionMinor).be.eql(versionMinor);
});

it('.versionPatch', () => {
should(Ti.Platform).have.readOnlyProperty('versionPatch').which.is.a.Number();
should(Ti.Platform.versionPatch).be.eql(OS_VERSION_PATCH);

const versionComponents = Ti.Platform.version.split('.');
const versionPatch = (versionComponents.length >= 3) ? parseInt(versionComponents[2]) : 0;
should(Ti.Platform.versionPatch).be.eql(versionPatch);
});

it.ios('.identifierForVendor', () => {
should(Ti.Platform.identifierForVendor).be.a.String();
should(Ti.Platform.getIdentifierForVendor).be.a.Function();
Expand Down