auto-terminal-profile 2.1.0 → 3.0.2

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.
@@ -1,8 +1,11 @@
1
- import darkMode from 'dark-mode';
1
+ import process from 'node:process';
2
2
  import {setTerminalProfile, setTerminalDefaultProfile} from 'terminal-profile';
3
3
  import {config} from '../config.js';
4
+ import {isTerminalOpen} from '../functions/index.js';
4
5
 
5
6
  export async function updateProfile() {
7
+ if (!(await isTerminalOpen())) return;
8
+
6
9
  if (!config.darkProfile) {
7
10
  throw new Error('Dark profile not set');
8
11
  }
@@ -11,7 +14,7 @@ export async function updateProfile() {
11
14
  throw new Error('Light profile not set');
12
15
  }
13
16
 
14
- const mode = (await darkMode.isEnabled()) ? 'dark' : 'light';
17
+ const mode = process.env.DARKMODE === '1' ? 'dark' : 'light';
15
18
  const profile = config[`${mode}Profile`];
16
19
 
17
20
  await Promise.all([
package/changelog.md CHANGED
@@ -5,13 +5,35 @@ 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
- ## [v2.1.0](https://github.com/ptrkcsk/terminal-profile/compare/v2.0.0...v2.1.0) – 2023-07-04
8
+ ## [v3.0.2](https://github.com/patrik-csak/terminal-profile/compare/v3.0.1...v3.0.2) – 2024-02-21
9
+
10
+ ### Fixed
11
+
12
+ - Fix Terminal opening when closed
13
+
14
+ ## [v3.0.1](https://github.com/patrik-csak/terminal-profile/compare/v3.0.0...v3.0.1) – 2024-02-20
15
+
16
+ ### Fixed
17
+
18
+ - Fix broken post-install compilation step
19
+
20
+ ## [v3.0.0](https://github.com/patrik-csak/terminal-profile/compare/v2.1.0...v3.0.0) – 2024-02-19
21
+
22
+ ### Removed
23
+
24
+ - Support for Node.js versions before 18
25
+
26
+ ### Fixed
27
+
28
+ - Fix issue causing `auto-terminal-profile` to silently fail on macOS Sonoma
29
+
30
+ ## [v2.1.0](https://github.com/patrik-csak/terminal-profile/compare/v2.0.0...v2.1.0) – 2023-07-04
9
31
 
10
32
  ### Changed
11
33
 
12
34
  - Update dependencies
13
35
 
14
- ## [2.0.0](https://github.com/ptrkcsk/terminal-profile/compare/v1.1.1...v2.0.0) – 2023-05-10
36
+ ## [2.0.0](https://github.com/patrik-csak/terminal-profile/compare/v1.1.1...v2.0.0) – 2023-05-10
15
37
 
16
38
  ### Added
17
39
 
package/config.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import Conf from 'conf';
2
- import {readPackageUp} from 'read-pkg-up';
2
+ import {readPackageUp} from 'read-package-up';
3
3
 
4
4
  const {packageJson} = await readPackageUp({cwd: new URL('.', import.meta.url)});
5
5
 
6
- const conf = new Conf({projectName: packageJson.name});
6
+ const config_ = new Conf({projectName: packageJson.name});
7
7
 
8
8
  class Config {
9
9
  keys = {
@@ -15,28 +15,28 @@ class Config {
15
15
  * @return {string}
16
16
  */
17
17
  get darkProfile() {
18
- return conf.get(this.keys.darkProfile);
18
+ return config_.get(this.keys.darkProfile);
19
19
  }
20
20
 
21
21
  /**
22
22
  * @param {string} profile
23
23
  */
24
24
  set darkProfile(profile) {
25
- conf.set(this.keys.darkProfile, profile);
25
+ config_.set(this.keys.darkProfile, profile);
26
26
  }
27
27
 
28
28
  /**
29
29
  * @return {string}
30
30
  */
31
31
  get lightProfile() {
32
- return conf.get(this.keys.lightProfile);
32
+ return config_.get(this.keys.lightProfile);
33
33
  }
34
34
 
35
35
  /**
36
36
  * @param {string} profile
37
37
  */
38
38
  set lightProfile(profile) {
39
- conf.set(this.keys.lightProfile, profile);
39
+ config_.set(this.keys.lightProfile, profile);
40
40
  }
41
41
  }
42
42
 
@@ -1,4 +1,4 @@
1
- import {readPackageUp} from 'read-pkg-up';
1
+ import {readPackageUp} from 'read-package-up';
2
2
 
3
3
  export const {packageJson} = await readPackageUp({
4
4
  cwd: new URL('.', import.meta.url),
@@ -0,0 +1,17 @@
1
+ prefix ?= /usr/local
2
+ bindir = $(prefix)/bin
3
+
4
+ build:
5
+ swift build -c release --disable-sandbox
6
+
7
+ install: build
8
+ install -d "$(bindir)"
9
+ install ".build/release/dark-mode-notify" "$(bindir)"
10
+
11
+ uninstall:
12
+ rm -rf "$(bindir)/dark-mode-notify"
13
+
14
+ clean:
15
+ rm -rf .build
16
+
17
+ .PHONY: build install uninstall clean
@@ -0,0 +1,15 @@
1
+ // swift-tools-version:4.0
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "dark-mode-notify",
6
+ dependencies: [
7
+ ],
8
+ targets: [
9
+ .target(
10
+ name: "dark-mode-notify",
11
+ path: "."
12
+ )
13
+ ]
14
+ )
15
+
@@ -4,9 +4,13 @@ This small Swift program will run a command whenever the dark mode status change
4
4
 
5
5
  ## Usage
6
6
 
7
- You can run it directly by doing `./dark-mode-notify.swift <program>`.
7
+ Use make to compile the program, then run directly:
8
8
 
9
- Alternatively you can compile it by doing `swiftc dark-mode-notify.swift -o /usr/local/bin/dark-mode-notify`.
9
+ ```shell
10
+ .build/release/dark-mode-notify <your-program>
11
+ ```
12
+
13
+ Alternatively you can install it by doing `make install`.
10
14
 
11
15
  The program will be run immediately when the command starts, and every time the OS goes from dark mode to light mode or back. The environment variable `DARKMODE` will be set to either `1` or `0`.
12
16
 
@@ -1,9 +1,6 @@
1
- #!/usr/bin/env swift
2
-
3
- // Run as ./notify.swift <program to run when dark mode changes>
4
1
  // The program will have the DARKMODE env flag set to 1 or 0
5
- // You can also compile with:
6
- // swiftc notify.swift -o notify
2
+ // Compile with:
3
+ // swift build
7
4
  // And run the binary directly
8
5
  // Most credit goes to https://github.com/mnewt/dotemacs/blob/master/bin/dark-mode-notifier.swift
9
6
 
@@ -35,4 +32,11 @@ DistributedNotificationCenter.default.addObserver(
35
32
  shell(args)
36
33
  }
37
34
 
35
+ NSWorkspace.shared.notificationCenter.addObserver(
36
+ forName: NSWorkspace.didWakeNotification,
37
+ object: nil,
38
+ queue: nil) { (notification) in
39
+ shell(args)
40
+ }
41
+
38
42
  NSApplication.shared.run()
@@ -15,7 +15,10 @@ export async function getLaunchAgentPlistFileContents() {
15
15
  new URL('../cli.js', import.meta.url),
16
16
  ),
17
17
  darkModeNotifyPath: fileURLToPath(
18
- new URL('../dark-mode-notify/dark-mode-notify.swift', import.meta.url),
18
+ new URL(
19
+ '../dark-mode-notify/.build/release/dark-mode-notify',
20
+ import.meta.url,
21
+ ),
19
22
  ),
20
23
  logPath: envPaths(packageJson.name).log,
21
24
  path: process.env.PATH,
@@ -2,3 +2,4 @@ export {enableAutomaticSwitching} from './enable-automatic-switching.js';
2
2
  export {disableAutomaticSwitching} from './disable-automatic-switching.js';
3
3
  export {getLaunchAgentPlistFileContents} from './get-launch-agent-plist-file-contents.js';
4
4
  export {isAutomaticSwitchingEnabled} from './is-automatic-switching-enabled.js';
5
+ export {isTerminalOpen} from './is-terminal-open.js';
@@ -0,0 +1,18 @@
1
+ import {runAppleScript} from 'run-applescript';
2
+
3
+ /**
4
+ * @returns {Promise<boolean>}
5
+ */
6
+ export async function isTerminalOpen() {
7
+ const result = await runAppleScript(`tell application "System Events"
8
+ set isOpen to (name of processes) contains "Terminal"
9
+ end tell
10
+
11
+ if isOpen then
12
+ return "true"
13
+ else
14
+ return "false"
15
+ end if`);
16
+
17
+ return result === 'true';
18
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "auto-terminal-profile",
3
- "version": "2.1.0",
4
- "description": "Automatically switch the macOS Terminal profile based on the system-wide dark / light appearance mode",
3
+ "version": "3.0.2",
4
+ "description": "Automatically switch macOS Terminal profile when system dark / light mode changes",
5
5
  "keywords": [
6
6
  "macos",
7
7
  "terminal",
@@ -9,34 +9,35 @@
9
9
  "dark mode",
10
10
  "profile"
11
11
  ],
12
+ "repository": "github:patrik-csak/auto-terminal-profile",
12
13
  "license": "MIT",
13
- "author": "Patrik Csak <p@trikcsak.com>",
14
- "funding": "https://www.buymeacoffee.com/patrikcsak",
14
+ "author": "Patrik Csak <p@trikcsak.com> (https://patrikcsak.com)",
15
+ "type": "module",
15
16
  "bin": "./cli.js",
16
- "repository": "github:patrik-csak/auto-terminal-profile",
17
17
  "scripts": {
18
- "format": "xo --fix",
19
- "test": "xo"
18
+ "format": "xo --fix && sort-package-json",
19
+ "postinstall": "cd dark-mode-notify && make build",
20
+ "test": "xo && sort-package-json --check"
20
21
  },
21
22
  "dependencies": {
22
- "commander": "^11.0.0",
23
- "conf": "^11.0.1",
24
- "dark-mode": "^4.0.0",
23
+ "commander": "^12.0.0",
24
+ "conf": "^12.0.0",
25
25
  "env-paths": "^3.0.0",
26
- "execa": "^7.1.1",
26
+ "execa": "^8.0.1",
27
27
  "pupa": "^3.1.0",
28
- "read-pkg-up": "^10.0.0",
28
+ "read-package-up": "^11.0.0",
29
+ "run-applescript": "^7.0.0",
29
30
  "terminal-profile": "^2.0.0",
30
31
  "untildify": "^5.0.0"
31
32
  },
32
33
  "devDependencies": {
33
- "xo": "^0.54.2"
34
+ "sort-package-json": "^2.7.0",
35
+ "xo": "^0.57.0"
34
36
  },
35
37
  "engines": {
36
- "node": ">=16 <=20"
38
+ "node": ">=18 <=20"
37
39
  },
38
40
  "os": [
39
41
  "darwin"
40
- ],
41
- "type": "module"
42
+ ]
42
43
  }
package/readme.md CHANGED
@@ -6,7 +6,7 @@ Automatically switch the macOS Terminal profile based on the system-wide dark /
6
6
 
7
7
  ## Prerequisites
8
8
 
9
- - [Node.js](https://nodejs.org/en/) 16–20
9
+ - [Node.js](https://nodejs.org/en/) 18–20
10
10
 
11
11
  ## Installation
12
12
 
@@ -32,4 +32,4 @@ auto-terminal-profile --help
32
32
 
33
33
  ## Acknowledgements
34
34
 
35
- Thanks to [Fatih Arslan](https://github.com/fatih) for his article [*Automatic dark mode for terminal applications*](https://arslan.io/2021/02/15/automatic-dark-mode-for-terminal-applications/) and [Bouke van der Bijl](https://github.com/bouk) for his project [dark-mode-notify](https://github.com/bouk/dark-mode-notify), which this project uses
35
+ Thanks [Bouke van der Bijl](https://bou.ke) for his project [dark-mode-notify](https://github.com/bouk/dark-mode-notify), which this project depends on
@@ -5,17 +5,22 @@
5
5
  <dict>
6
6
  <key>Label</key>
7
7
  <string>ke.bou.dark-mode-notify</string>
8
+
8
9
  <key>KeepAlive</key>
9
10
  <true/>
11
+
10
12
  <key>StandardErrorPath</key>
11
13
  <string>{logPath}/dark-mode-notify-stderr.log</string>
14
+
12
15
  <key>StandardOutPath</key>
13
16
  <string>{logPath}/dark-mode-notify-stdout.log</string>
17
+
14
18
  <key>EnvironmentVariables</key>
15
19
  <dict>
16
20
  <key>PATH</key>
17
21
  <string>{path}</string>
18
22
  </dict>
23
+
19
24
  <key>ProgramArguments</key>
20
25
  <array>
21
26
  <string>{darkModeNotifyPath}</string>