Skip to content

Commit

Permalink
Support older macOS versions before 10.13
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Dec 20, 2024
1 parent 72a4a09 commit 83139c0
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 61 deletions.
101 changes: 44 additions & 57 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
"@types/mocha": "^9.1.0",
"@types/node": "^17.0.21",
"@types/request": "^2.48.8",
"@types/semver": "^7.5.8",
"@types/vscode": "^1.59.0",
"@types/webpack": "^5.28.0",
"@types/which": "^2.0.1",
Expand All @@ -144,6 +145,7 @@
"original-fs": "^1.1.0",
"prettier": "2.6.0",
"request": "2.88.2",
"semver": "^7.6.3",
"ts-loader": "^9.2.8",
"tslib": "^2.3.1",
"typescript": "^4.6.2",
Expand Down
54 changes: 50 additions & 4 deletions src/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as request from 'request';
import * as semver from 'semver';
import * as which from 'which';

import { Options, Setting } from './options';

import { Desktop } from './desktop';
import { Logger } from './logger';

enum osName {
darwin = 'darwin',
windows = 'windows',
linux = 'linux',
}

export class Dependencies {
private options: Options;
private logger: Logger;
Expand All @@ -19,6 +27,14 @@ export class Dependencies {
private cliInstalled: boolean = false;
private githubDownloadUrl = 'https://github.com/wakatime/wakatime-cli/releases/latest/download';
private githubReleasesUrl = 'https://api.github.com/repos/wakatime/wakatime-cli/releases/latest';
private legacyOperatingSystems: {
[key in osName]?: {
kernelLessThan: string;
tag: string;
}[];
} = {
[osName.darwin]: [{ kernelLessThan: '17.0.0', tag: 'v1.39.1-alpha.1' }],
};

constructor(options: Options, logger: Logger, resourcesLocation: string) {
this.options = options;
Expand All @@ -32,8 +48,7 @@ export class Dependencies {
this.cliLocation = this.getCliLocationGlobal();
if (this.cliLocation) return this.cliLocation;

let osname = os.platform() as string;
if (osname == 'win32') osname = 'windows';
const osname = this.osName();
const arch = this.architecture();
const ext = Desktop.isWindows() ? '.exe' : '';
const binary = `wakatime-cli-${osname}-${arch}${ext}`;
Expand Down Expand Up @@ -89,11 +104,17 @@ export class Dependencies {
let currentVersion = _stdout.toString().trim() + stderr.toString().trim();
this.logger.debug(`Current wakatime-cli version is ${currentVersion}`);

if (currentVersion.trim() === '<local-build>') {
if (currentVersion === '<local-build>') {
callback(true);
return;
}

const tag = this.legacyReleaseTag();
if (tag && currentVersion !== tag) {
callback(false);
return;
}

this.options.getSetting(
'internal',
'cli_version_last_accessed',
Expand Down Expand Up @@ -316,18 +337,43 @@ export class Dependencies {
}
}

private legacyReleaseTag() {
const osname = this.osName() as osName;
const legacyOS = this.legacyOperatingSystems[osname];
if (!legacyOS) return;
const version = legacyOS.find((spec) => {
try {
return semver.lt(os.release(), spec.kernelLessThan);
} catch (e) {
return false;
}
});
return version?.tag;
}

private architecture(): string {
const arch = os.arch();
if (arch.indexOf('32') > -1) return '386';
if (arch.indexOf('x64') > -1) return 'amd64';
return arch;
}

private cliDownloadUrl(): string {
private osName(): string {
let osname = os.platform() as string;
if (osname == 'win32') osname = 'windows';
return osname;
}

private cliDownloadUrl(): string {
const osname = this.osName();
const arch = this.architecture();

// Use legacy wakatime-cli release to support older operating systems
const tag = this.legacyReleaseTag();
if (tag) {
return `https://github.com/wakatime/wakatime-cli/releases/download/${tag}/wakatime-cli-${osname}-${arch}.zip`;
}

const validCombinations = [
'darwin-amd64',
'darwin-arm64',
Expand Down

0 comments on commit 83139c0

Please sign in to comment.