Skip to content

Commit eaba8a8

Browse files
committed
First cut of moving 'login_item' from under the 'uninstall' block to the top-level
Fix issues found when running brew cli commands (upgrade, update, install) Incorporate 'login_items' into 'info' command output (not yet verified) Incorporate 'login_items' option for 'reinstall' command
1 parent 7b34fcc commit eaba8a8

31 files changed

+191
-41
lines changed

Library/Homebrew/ast_constants.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[{ name: :include, type: :method_call }],
88
[{ name: :desc, type: :method_call }],
99
[{ name: :homepage, type: :method_call }],
10+
[{ name: :login_items, type: :method_call }],
1011
[{ name: :url, type: :method_call }],
1112
[{ name: :mirror, type: :method_call }],
1213
[{ name: :version, type: :method_call }],

Library/Homebrew/cask/artifact/abstract_uninstall.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class AbstractUninstall < AbstractArtifact
2020
:launchctl,
2121
:quit,
2222
:signal,
23-
:login_item,
23+
:login_item, # DEPRECATED: Need to remove once the casks have been fixed
2424
:kext,
2525
:script,
2626
:pkgutil,
@@ -295,6 +295,7 @@ def uninstall_signal(*signals, command: nil, **_)
295295
end
296296
end
297297

298+
# TODO: Need to refer to attribute from the cask instead of this uninstall stanza
298299
def uninstall_login_item(*login_items, command: nil, successor: nil, **_)
299300
return if successor
300301

Library/Homebrew/cask/cask.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ def languages
321321
@languages ||= @dsl.languages
322322
end
323323

324+
def login_items
325+
@login_items ||= @dsl.login_items
326+
end
327+
324328
def tap_git_head
325329
@tap_git_head ||= tap&.git_head
326330
rescue TapUnavailableError
@@ -331,6 +335,7 @@ def populate_from_api!(json_cask)
331335
raise ArgumentError, "Expected cask to be loaded from the API" unless loaded_from_api?
332336

333337
@languages = json_cask.fetch(:languages, [])
338+
@login_items = json_cask.fetch(:login_items, [])
334339
@tap_git_head = json_cask.fetch(:tap_git_head, "HEAD")
335340

336341
@ruby_source_path = json_cask[:ruby_source_path]
@@ -395,6 +400,7 @@ def to_h
395400
"languages" => languages,
396401
"ruby_source_path" => ruby_source_path,
397402
"ruby_source_checksum" => ruby_source_checksum,
403+
"login_items" => login_items,
398404
}
399405
end
400406

Library/Homebrew/cask/cask_loader.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ def load(config:)
350350
end
351351
desc json_cask[:desc]
352352
homepage json_cask[:homepage]
353+
login_items json_cask[:login_items] unless json_cask[:login_items].nil?
353354

354355
if (deprecation_date = json_cask[:deprecation_date].presence)
355356
reason = DeprecateDisable.to_reason_string_or_symbol json_cask[:deprecation_reason], type: :cask

Library/Homebrew/cask/dsl.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class DSL
100100
:livecheck,
101101
:livecheck_defined?,
102102
:livecheckable?, # TODO: remove once `#livecheckable?` is removed
103+
:login_items,
103104
:on_system_blocks_exist?,
104105
:on_system_block_min_os,
105106
:depends_on_set_in_block?,
@@ -190,6 +191,21 @@ def set_unique_stanza(stanza, should_return)
190191
raise CaskInvalidError.new(cask, "'#{stanza}' stanza failed with: #{e}")
191192
end
192193

194+
# Sets the cask's login items
195+
#
196+
# ### Example
197+
#
198+
# ```ruby
199+
# login_items "Raycast"
200+
# ```
201+
#
202+
# @api public
203+
def login_items(login_items = nil)
204+
return [] if login_items.nil?
205+
206+
set_unique_stanza(:login_items, login_items.nil?) { Array(login_items) }
207+
end
208+
193209
# Sets the cask's homepage.
194210
#
195211
# ### Example

Library/Homebrew/cask/info.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def self.get_info(cask)
2727
language = language_info(cask)
2828
output << language if language
2929
output << "#{artifact_info(cask)}\n"
30+
login_items = login_items_info(cask)
31+
output << login_items if login_items
3032
caveats = Installer.caveats(cask)
3133
output << caveats if caveats
3234
output
@@ -132,5 +134,15 @@ def self.artifact_info(cask)
132134
end
133135
artifact_output.freeze
134136
end
137+
138+
sig { params(cask: Cask).returns(T.nilable(String)) }
139+
def self.login_items_info(cask)
140+
return if cask.login_items.empty?
141+
142+
<<~EOS
143+
#{ohai_title("Login Items")}
144+
#{cask.login_items.join(", ")}
145+
EOS
146+
end
135147
end
136148
end

Library/Homebrew/cask/installer.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ class Installer
2222
skip_cask_deps: T::Boolean, binaries: T::Boolean, verbose: T::Boolean, zap: T::Boolean,
2323
require_sha: T::Boolean, upgrade: T::Boolean, reinstall: T::Boolean, installed_as_dependency: T::Boolean,
2424
installed_on_request: T::Boolean, quarantine: T::Boolean, verify_download_integrity: T::Boolean,
25-
quiet: T::Boolean
25+
quiet: T::Boolean, login_items: T::Boolean
2626
).void
2727
}
2828
def initialize(cask, command: SystemCommand, force: false, adopt: false,
2929
skip_cask_deps: false, binaries: true, verbose: false,
3030
zap: false, require_sha: false, upgrade: false, reinstall: false,
3131
installed_as_dependency: false, installed_on_request: true,
32-
quarantine: true, verify_download_integrity: true, quiet: false)
32+
quarantine: true, verify_download_integrity: true, quiet: false,
33+
login_items: false)
3334
@cask = cask
3435
@command = command
3536
@force = force
@@ -46,6 +47,7 @@ def initialize(cask, command: SystemCommand, force: false, adopt: false,
4647
@quarantine = quarantine
4748
@verify_download_integrity = verify_download_integrity
4849
@quiet = quiet
50+
@login_items = login_items
4951
end
5052

5153
sig { returns(T::Boolean) }
@@ -63,6 +65,9 @@ def installed_as_dependency? = @installed_as_dependency
6365
sig { returns(T::Boolean) }
6466
def installed_on_request? = @installed_on_request
6567

68+
sig { returns(T::Boolean) }
69+
def login_items? = @login_items
70+
6671
sig { returns(T::Boolean) }
6772
def quarantine? = @quarantine
6873

@@ -312,6 +317,14 @@ def install_artifacts(predecessor: nil)
312317
already_installed_artifacts.unshift(artifact)
313318
end
314319

320+
# TODO: should we register the login_items here?
321+
# if login_items?
322+
# login_items.each do |lgi|
323+
# # TODO: register the login_items here using osascript
324+
# puts "***** WILL REGISTER login_item: #{lgi}"
325+
# end
326+
# end
327+
315328
save_config_file
316329
save_download_sha if @cask.version.latest?
317330
rescue => e

Library/Homebrew/cask/reinstall.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Reinstall
66
sig {
77
params(
88
casks: ::Cask::Cask, verbose: T::Boolean, force: T::Boolean, skip_cask_deps: T::Boolean, binaries: T::Boolean,
9-
require_sha: T::Boolean, quarantine: T::Boolean, zap: T::Boolean
9+
require_sha: T::Boolean, quarantine: T::Boolean, zap: T::Boolean, login_items: T::Boolean
1010
).void
1111
}
1212
def self.reinstall_casks(
@@ -17,15 +17,17 @@ def self.reinstall_casks(
1717
binaries: false,
1818
require_sha: false,
1919
quarantine: false,
20-
zap: false
20+
zap: false,
21+
login_items: false
2122
)
2223
require "cask/installer"
2324

2425
quarantine = true if quarantine.nil?
2526

2627
casks.each do |cask|
2728
Installer
28-
.new(cask, binaries:, verbose:, force:, skip_cask_deps:, require_sha:, reinstall: true, quarantine:, zap:)
29+
.new(cask, binaries:, verbose:, force:, skip_cask_deps:, require_sha:, reinstall: true, quarantine:, zap:,
30+
login_items:)
2931
.install
3032
end
3133
end

Library/Homebrew/cask/upgrade.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Upgrade
2121
binaries: T.nilable(T::Boolean),
2222
quarantine: T.nilable(T::Boolean),
2323
require_sha: T.nilable(T::Boolean),
24+
login_items: T.nilable(T::Boolean),
2425
).returns(T::Boolean)
2526
}
2627
def self.upgrade_casks(
@@ -36,7 +37,8 @@ def self.upgrade_casks(
3637
quiet: false,
3738
binaries: nil,
3839
quarantine: nil,
39-
require_sha: nil
40+
require_sha: nil,
41+
login_items: nil
4042
)
4143
quarantine = true if quarantine.nil?
4244

@@ -123,7 +125,7 @@ def self.upgrade_casks(
123125
upgrade_cask(
124126
old_cask, new_cask,
125127
binaries:, force:, skip_cask_deps:, verbose:,
126-
quarantine:, require_sha:
128+
quarantine:, require_sha:, login_items:
127129
)
128130
rescue => e
129131
new_exception = e.exception("#{new_cask.full_name}: #{e}")
@@ -147,13 +149,14 @@ def self.upgrade_casks(
147149
force: T.nilable(T::Boolean),
148150
quarantine: T.nilable(T::Boolean),
149151
require_sha: T.nilable(T::Boolean),
152+
login_items: T.nilable(T::Boolean),
150153
skip_cask_deps: T.nilable(T::Boolean),
151154
verbose: T.nilable(T::Boolean),
152155
).void
153156
}
154157
def self.upgrade_cask(
155158
old_cask, new_cask,
156-
binaries:, force:, quarantine:, require_sha:, skip_cask_deps:, verbose:
159+
binaries:, force:, quarantine:, require_sha:, login_items:, skip_cask_deps:, verbose:
157160
)
158161
require "cask/installer"
159162

@@ -181,6 +184,7 @@ def self.upgrade_cask(
181184
require_sha:,
182185
upgrade: true,
183186
quarantine:,
187+
login_items:,
184188
}.compact
185189

186190
new_cask_installer =

Library/Homebrew/cmd/install.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ class InstallCmd < AbstractCommand
148148
description: "Disable/enable quarantining of downloads (default: enabled).",
149149
env: :cask_opts_quarantine,
150150
}],
151+
[:switch, "--[no-]login-items", {
152+
description: "Disable/enable registering of login item(s) (default: disabled).",
153+
env: :cask_opts_login_items,
154+
}],
151155
[:switch, "--adopt", {
152156
description: "Adopt existing artifacts in the destination that are identical to those being installed. " \
153157
"Cannot be combined with `--force`.",
@@ -249,6 +253,7 @@ def run
249253
binaries: args.binaries?,
250254
force: args.force?,
251255
quarantine: args.quarantine?,
256+
login_items: args.login_items?,
252257
quiet: args.quiet?,
253258
require_sha: args.require_sha?,
254259
skip_cask_deps: args.skip_cask_deps?,
@@ -265,6 +270,7 @@ def run
265270
dry_run: args.dry_run?,
266271
binaries: args.binaries?,
267272
quarantine: args.quarantine?,
273+
login_items: args.login_items?,
268274
require_sha: args.require_sha?,
269275
skip_cask_deps: args.skip_cask_deps?,
270276
verbose: args.verbose?,

Library/Homebrew/cmd/reinstall.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ class Reinstall < AbstractCommand
8888
description: "Disable/enable quarantining of downloads (default: enabled).",
8989
env: :cask_opts_quarantine,
9090
}],
91+
[:switch, "--[no-]login-items", {
92+
description: "Disable/enable registering of login item(s) (default: disabled).",
93+
env: :cask_opts_login_items,
94+
}],
9195
[:switch, "--adopt", {
9296
description: "Adopt existing artifacts in the destination that are identical to those being installed. " \
9397
"Cannot be combined with `--force`.",
@@ -181,6 +185,7 @@ def run
181185
require_sha: args.require_sha?,
182186
skip_cask_deps: args.skip_cask_deps?,
183187
quarantine: args.quarantine?,
188+
login_items: args.login_items?,
184189
zap: args.zap?,
185190
)
186191
end

Library/Homebrew/cmd/upgrade.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ class UpgradeCmd < AbstractCommand
111111
description: "Disable/enable quarantining of downloads (default: enabled).",
112112
env: :cask_opts_quarantine,
113113
}],
114+
[:switch, "--[no-]login-items", {
115+
description: "Disable/enable registering of login item(s) (default: disabled).",
116+
env: :cask_opts_login_items,
117+
}],
114118
].each do |args|
115119
options = args.pop
116120
send(*args, **options)
@@ -271,6 +275,7 @@ def upgrade_outdated_casks(casks)
271275
dry_run: args.dry_run?,
272276
binaries: args.binaries?,
273277
quarantine: args.quarantine?,
278+
login_items: args.login_items?,
274279
require_sha: args.require_sha?,
275280
skip_cask_deps: args.skip_cask_deps?,
276281
verbose: args.verbose?,

Library/Homebrew/env_config.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ module EnvConfig
105105
},
106106
HOMEBREW_CASK_OPTS: {
107107
description: "Append these options to all `cask` commands. All `--*dir` options, " \
108-
"`--language`, `--require-sha`, `--no-quarantine` and `--no-binaries` are supported. " \
108+
"`--language`, `--require-sha`, `--no-quarantine`, `--no-login-items` " \
109+
"and `--no-binaries` are supported. " \
109110
"For example, you might add something like the following to your " \
110111
"`~/.profile`, `~/.bash_profile`, or `~/.zshenv`:" \
111112
"\n\n `export HOMEBREW_CASK_OPTS=\"--appdir=${HOME}/Applications --fontdir=/Library/Fonts\"`",
@@ -612,6 +613,16 @@ def cask_opts_quarantine?
612613
true
613614
end
614615

616+
sig { returns(T::Boolean) }
617+
def cask_opts_login_items?
618+
cask_opts.reverse_each do |opt|
619+
return true if opt == "--login-items"
620+
return false if opt == "--no-login-items"
621+
end
622+
623+
false
624+
end
625+
615626
sig { returns(T::Boolean) }
616627
def cask_opts_require_sha?
617628
cask_opts.include?("--require-sha")

Library/Homebrew/rubocops/cask/constants/stanza.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module Constants
3838
:app,
3939
:pkg,
4040
:installer,
41+
:login_items,
4142
:binary,
4243
:manpage,
4344
:colorpicker,
@@ -82,7 +83,6 @@ module Constants
8283
:launchctl,
8384
:quit,
8485
:signal,
85-
:login_item,
8686
:kext,
8787
:script,
8888
:pkgutil,

Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/fetch_cmd.rbi

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/install_cmd.rbi

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/reinstall.rbi

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/upgrade_cmd.rbi

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)