auto-terminal-profile 4.0.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions/enable.js +47 -13
- package/actions/set-mode-profile.js +15 -1
- package/actions/update-profile.js +4 -7
- package/changelog.md +14 -7
- package/config.js +2 -2
- package/functions/disable-automatic-switching.js +1 -1
- package/functions/enable-automatic-switching.js +1 -1
- package/functions/get-current-mode.js +8 -0
- package/functions/index.js +2 -0
- package/functions/is-automatic-switching-enabled.js +1 -1
- package/functions/set-terminal-profile.js +11 -0
- package/package.json +4 -4
package/actions/enable.js
CHANGED
|
@@ -1,24 +1,58 @@
|
|
|
1
1
|
import {config} from '../config.js';
|
|
2
2
|
import {packageJson} from '../constants/index.js';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
enableAutomaticSwitching,
|
|
5
|
+
getCurrentMode,
|
|
6
|
+
isTerminalOpen,
|
|
7
|
+
setTerminalProfile,
|
|
8
|
+
} from '../functions/index.js';
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} mode
|
|
12
|
+
*/
|
|
13
|
+
function undefinedProfileMessage(mode) {
|
|
14
|
+
return `${mode} profile must be specified with --${mode}-profile or previously set with \`${packageJson.name} set-${mode}-mode\``;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {object} parameters
|
|
19
|
+
* @param {string|undefined} parameters.darkProfile
|
|
20
|
+
* @param {string|undefined} parameters.lightProfile
|
|
21
|
+
*/
|
|
22
|
+
export async function enable(parameters) {
|
|
23
|
+
if (
|
|
24
|
+
[parameters.darkProfile, config.darkProfile].every(
|
|
25
|
+
(value) => value === undefined,
|
|
26
|
+
)
|
|
27
|
+
) {
|
|
28
|
+
throw new Error(undefinedProfileMessage('dark'));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (
|
|
32
|
+
[parameters.lightProfile, config.lightProfile].every(
|
|
33
|
+
(value) => value === undefined,
|
|
34
|
+
)
|
|
35
|
+
) {
|
|
36
|
+
throw new Error(undefinedProfileMessage('light'));
|
|
10
37
|
}
|
|
11
38
|
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
`Light profile must be specified with --light-profile or previously set with \`${packageJson.name} set-light-mode\``,
|
|
15
|
-
);
|
|
39
|
+
if (parameters.darkProfile !== undefined) {
|
|
40
|
+
config.darkProfile = parameters.darkProfile;
|
|
16
41
|
}
|
|
17
42
|
|
|
18
|
-
if (
|
|
19
|
-
|
|
43
|
+
if (parameters.lightProfile !== undefined) {
|
|
44
|
+
config.lightProfile = parameters.lightProfile;
|
|
45
|
+
}
|
|
20
46
|
|
|
21
47
|
await enableAutomaticSwitching();
|
|
22
48
|
|
|
23
|
-
|
|
49
|
+
if (await isTerminalOpen()) {
|
|
50
|
+
const mode = await getCurrentMode();
|
|
51
|
+
|
|
52
|
+
if (parameters[`${mode}Profile`] !== undefined) {
|
|
53
|
+
await setTerminalProfile(config[`${mode}Profile`]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
console.log('automatic switching enabled');
|
|
24
58
|
}
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import {config} from '../config.js';
|
|
2
|
+
import {
|
|
3
|
+
getCurrentMode,
|
|
4
|
+
isAutomaticSwitchingEnabled,
|
|
5
|
+
isTerminalOpen,
|
|
6
|
+
setTerminalProfile,
|
|
7
|
+
} from '../functions/index.js';
|
|
2
8
|
|
|
3
|
-
export function setModeProfile({mode, profile}) {
|
|
9
|
+
export async function setModeProfile({mode, profile}) {
|
|
4
10
|
config[`${mode}Profile`] = profile;
|
|
5
11
|
|
|
12
|
+
if ((await isAutomaticSwitchingEnabled()) && (await isTerminalOpen())) {
|
|
13
|
+
const currentMode = await getCurrentMode();
|
|
14
|
+
|
|
15
|
+
if (currentMode === mode) {
|
|
16
|
+
await setTerminalProfile(profile);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
6
20
|
console.log(`${mode} mode profile set to '${profile}'`);
|
|
7
21
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import darkMode from 'dark-mode';
|
|
2
|
-
import {setTerminalProfile, setTerminalDefaultProfile} from 'terminal-profile';
|
|
3
1
|
import {config} from '../config.js';
|
|
4
2
|
import {
|
|
3
|
+
getCurrentMode,
|
|
5
4
|
isAutomaticSwitchingEnabled,
|
|
6
5
|
isTerminalOpen,
|
|
6
|
+
setTerminalProfile,
|
|
7
7
|
} from '../functions/index.js';
|
|
8
8
|
|
|
9
9
|
export async function updateProfile() {
|
|
@@ -19,11 +19,8 @@ export async function updateProfile() {
|
|
|
19
19
|
throw new Error('Light profile not set');
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const mode =
|
|
22
|
+
const mode = await getCurrentMode();
|
|
23
23
|
const profile = config[`${mode}Profile`];
|
|
24
24
|
|
|
25
|
-
await
|
|
26
|
-
setTerminalProfile(profile),
|
|
27
|
-
setTerminalDefaultProfile(profile),
|
|
28
|
-
]);
|
|
25
|
+
await setTerminalProfile(profile);
|
|
29
26
|
}
|
package/changelog.md
CHANGED
|
@@ -5,29 +5,36 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [
|
|
8
|
+
## [5.0.0](https://github.com/patrik-csak/auto-terminal-profile/compare/v4.0.0...v5.0.0) – 2024-11-27
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **BREAKING**: `enable` and `set-(dark|light)-profile` now set the Terminal profile
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
15
|
+
## [4.0.0](https://github.com/patrik-csak/auto-terminal-profile/compare/v3.0.2...v4.0.0) – 2024-03-25
|
|
9
16
|
|
|
10
17
|
### Added
|
|
11
18
|
|
|
12
|
-
- Documentation explaining how to automatically update Terminal profile when opening Terminal
|
|
19
|
+
- Documentation explaining how to automatically update Terminal profile when opening Terminal
|
|
13
20
|
|
|
14
21
|
### Changed
|
|
15
22
|
|
|
16
23
|
- **BREAKING**: `update-profile` gets appearance mode from OS instead of from `DARKMODE` environment variable
|
|
17
24
|
|
|
18
|
-
## [3.0.2](https://github.com/patrik-csak/terminal-profile/compare/v3.0.1...v3.0.2) – 2024-02-21
|
|
25
|
+
## [3.0.2](https://github.com/patrik-csak/auto-terminal-profile/compare/v3.0.1...v3.0.2) – 2024-02-21
|
|
19
26
|
|
|
20
27
|
### Fixed
|
|
21
28
|
|
|
22
29
|
- Fix Terminal opening when closed
|
|
23
30
|
|
|
24
|
-
## [3.0.1](https://github.com/patrik-csak/terminal-profile/compare/v3.0.0...v3.0.1) – 2024-02-20
|
|
31
|
+
## [3.0.1](https://github.com/patrik-csak/auto-terminal-profile/compare/v3.0.0...v3.0.1) – 2024-02-20
|
|
25
32
|
|
|
26
33
|
### Fixed
|
|
27
34
|
|
|
28
35
|
- Fix broken post-install compilation step
|
|
29
36
|
|
|
30
|
-
## [3.0.0](https://github.com/patrik-csak/terminal-profile/compare/v2.1.0...v3.0.0) – 2024-02-19
|
|
37
|
+
## [3.0.0](https://github.com/patrik-csak/auto-terminal-profile/compare/v2.1.0...v3.0.0) – 2024-02-19
|
|
31
38
|
|
|
32
39
|
### Changed
|
|
33
40
|
|
|
@@ -41,13 +48,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
41
48
|
|
|
42
49
|
- Fix issue causing `auto-terminal-profile` to silently fail on macOS Sonoma
|
|
43
50
|
|
|
44
|
-
## [2.1.0](https://github.com/patrik-csak/terminal-profile/compare/v2.0.0...v2.1.0) – 2023-07-04
|
|
51
|
+
## [2.1.0](https://github.com/patrik-csak/auto-terminal-profile/compare/v2.0.0...v2.1.0) – 2023-07-04
|
|
45
52
|
|
|
46
53
|
### Changed
|
|
47
54
|
|
|
48
55
|
- Update dependencies
|
|
49
56
|
|
|
50
|
-
## [2.0.0](https://github.com/patrik-csak/terminal-profile/compare/v1.1.1...v2.0.0) – 2023-05-10
|
|
57
|
+
## [2.0.0](https://github.com/patrik-csak/auto-terminal-profile/compare/v1.1.1...v2.0.0) – 2023-05-10
|
|
51
58
|
|
|
52
59
|
### Added
|
|
53
60
|
|
package/config.js
CHANGED
|
@@ -12,7 +12,7 @@ class Config {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* @return {string}
|
|
15
|
+
* @return {string|undefined}
|
|
16
16
|
*/
|
|
17
17
|
get darkProfile() {
|
|
18
18
|
return config_.get(this.keys.darkProfile);
|
|
@@ -26,7 +26,7 @@ class Config {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
* @return {string}
|
|
29
|
+
* @return {string|undefined}
|
|
30
30
|
*/
|
|
31
31
|
get lightProfile() {
|
|
32
32
|
return config_.get(this.keys.lightProfile);
|
|
@@ -3,7 +3,7 @@ import {execa} from 'execa';
|
|
|
3
3
|
import {launchAgentPlistFilePath} from '../constants/index.js';
|
|
4
4
|
|
|
5
5
|
export async function disableAutomaticSwitching() {
|
|
6
|
-
await execa
|
|
6
|
+
await execa`launchctl unload -w ${launchAgentPlistFilePath}`;
|
|
7
7
|
|
|
8
8
|
await unlink(launchAgentPlistFilePath);
|
|
9
9
|
}
|
package/functions/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export {enableAutomaticSwitching} from './enable-automatic-switching.js';
|
|
2
2
|
export {disableAutomaticSwitching} from './disable-automatic-switching.js';
|
|
3
|
+
export {getCurrentMode} from './get-current-mode.js';
|
|
3
4
|
export {getLaunchAgentPlistFileContents} from './get-launch-agent-plist-file-contents.js';
|
|
4
5
|
export {isAutomaticSwitchingEnabled} from './is-automatic-switching-enabled.js';
|
|
5
6
|
export {isTerminalOpen} from './is-terminal-open.js';
|
|
7
|
+
export {setTerminalProfile} from './set-terminal-profile.js';
|
|
@@ -6,7 +6,7 @@ import {launchAgentPlistFilePath} from '../constants/index.js';
|
|
|
6
6
|
* @return {Promise<boolean>}
|
|
7
7
|
*/
|
|
8
8
|
async function isDarkModeNotifyRunning() {
|
|
9
|
-
const {stdout} = await execa
|
|
9
|
+
const {stdout} = await execa`launchctl list`;
|
|
10
10
|
|
|
11
11
|
return stdout.includes('ke.bou.dark-mode-notify');
|
|
12
12
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
setTerminalDefaultProfile as setDefaultProfile,
|
|
3
|
+
setTerminalProfile as setProfile,
|
|
4
|
+
} from 'terminal-profile';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} profile
|
|
8
|
+
*/
|
|
9
|
+
export async function setTerminalProfile(profile) {
|
|
10
|
+
await Promise.all([setDefaultProfile(profile), setProfile(profile)]);
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-terminal-profile",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Automatically switch macOS Terminal profile when system dark / light mode changes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"macos",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"commander": "^12.0.0",
|
|
25
|
-
"conf": "^
|
|
25
|
+
"conf": "^13.0.1",
|
|
26
26
|
"dark-mode": "^4.0.0",
|
|
27
27
|
"env-paths": "^3.0.0",
|
|
28
|
-
"execa": "^
|
|
28
|
+
"execa": "^9.5.1",
|
|
29
29
|
"pupa": "^3.1.0",
|
|
30
30
|
"read-package-up": "^11.0.0",
|
|
31
31
|
"run-applescript": "^7.0.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"sort-package-json": "^2.7.0",
|
|
37
|
-
"xo": "^0.
|
|
37
|
+
"xo": "^0.59.3"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=18 <=20"
|