Skip to content

Commit b7cc28e

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 WIP: Adding placeholder for using osascript to register/unregister login items Mark for deprecation Trying to fix broken unit test Fix ruby version
1 parent 9e4beda commit b7cc28e

34 files changed

+208
-39
lines changed

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.4.4

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class AbstractUninstall < AbstractArtifact
2020
:launchctl,
2121
:quit,
2222
:signal,
23+
# odeprecated: deprecate when all casks have been migrated to top-level login_items
2324
:login_item,
2425
:kext,
2526
:script,
@@ -295,6 +296,7 @@ def uninstall_signal(*signals, command: nil, **_)
295296
end
296297
end
297298

299+
# TODO: Need to refer to attribute from the cask instead of this uninstall stanza
298300
def uninstall_login_item(*login_items, command: nil, successor: nil, **_)
299301
return if successor
300302

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]
@@ -400,6 +405,7 @@ def to_h
400405
"languages" => languages,
401406
"ruby_source_path" => ruby_source_path,
402407
"ruby_source_checksum" => ruby_source_checksum,
408+
"login_items" => login_items,
403409
}
404410
end
405411

Library/Homebrew/cask/cask_loader.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ def load(config:)
367367
end
368368
desc json_cask[:desc]
369369
homepage json_cask[:homepage]
370+
login_items json_cask[:login_items] if json_cask[:login_items].present?
370371

371372
if (deprecation_date = json_cask[:deprecation_date].presence)
372373
reason = DeprecateDisable.to_reason_string_or_symbol json_cask[:deprecation_reason], type: :cask
@@ -378,7 +379,7 @@ def load(config:)
378379
disable! date: disable_date, because: reason
379380
end
380381

381-
auto_updates json_cask[:auto_updates] unless json_cask[:auto_updates].nil?
382+
auto_updates json_cask[:auto_updates] if json_cask[:auto_updates].present?
382383
conflicts_with(**json_cask[:conflicts_with]) if json_cask[:conflicts_with].present?
383384

384385
if json_cask[:depends_on].present?

Library/Homebrew/cask/dsl.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class DSL
104104
:no_autobump!,
105105
:autobump?,
106106
:no_autobump_message,
107+
:login_items,
107108
:on_system_blocks_exist?,
108109
:on_system_block_min_os,
109110
:depends_on_set_in_block?,
@@ -238,6 +239,21 @@ def set_unique_stanza(stanza, should_return)
238239
raise CaskInvalidError.new(cask, "'#{stanza}' stanza failed with: #{e}")
239240
end
240241

242+
# Sets the cask's login items
243+
#
244+
# ### Example
245+
#
246+
# ```ruby
247+
# login_items "Raycast"
248+
# ```
249+
#
250+
# @api public
251+
def login_items(login_items = nil)
252+
return [] if login_items.nil?
253+
254+
set_unique_stanza(:login_items, login_items.nil?) { Array(login_items) }
255+
end
256+
241257
# Sets the cask's homepage.
242258
#
243259
# ### 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: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ class Installer
2121
skip_cask_deps: T::Boolean, binaries: T::Boolean, verbose: T::Boolean, zap: T::Boolean,
2222
require_sha: T::Boolean, upgrade: T::Boolean, reinstall: T::Boolean, installed_as_dependency: T::Boolean,
2323
installed_on_request: T::Boolean, quarantine: T::Boolean, verify_download_integrity: T::Boolean,
24-
quiet: T::Boolean, download_queue: T.nilable(Homebrew::DownloadQueue)
24+
quiet: T::Boolean, download_queue: T.nilable(Homebrew::DownloadQueue), login_items: T::Boolean
2525
).void
2626
}
2727
def initialize(cask, command: SystemCommand, force: false, adopt: false,
2828
skip_cask_deps: false, binaries: true, verbose: false,
2929
zap: false, require_sha: false, upgrade: false, reinstall: false,
3030
installed_as_dependency: false, installed_on_request: true,
31-
quarantine: true, verify_download_integrity: true, quiet: false, download_queue: nil)
31+
quarantine: true, verify_download_integrity: true, quiet: false, download_queue: nil,
32+
login_items: false)
3233
@cask = cask
3334
@command = command
3435
@force = force
@@ -46,6 +47,7 @@ def initialize(cask, command: SystemCommand, force: false, adopt: false,
4647
@verify_download_integrity = verify_download_integrity
4748
@quiet = quiet
4849
@download_queue = download_queue
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

@@ -326,6 +331,17 @@ def install_artifacts(predecessor: nil)
326331
already_installed_artifacts.unshift(artifact)
327332
end
328333

334+
unless @cask.login_items.empty?
335+
if login_items?
336+
@cask.login_items.each do |lgi|
337+
# TODO: register the login_items here using osascript
338+
ohai "***** Will REGISTER login_item: #{lgi}"
339+
end
340+
else
341+
ohai "Skipping processing of login_items"
342+
end
343+
end
344+
329345
save_config_file
330346
save_download_sha if @cask.version.latest?
331347
rescue => e
@@ -570,6 +586,15 @@ def uninstall_artifacts(clear: false, successor: nil)
570586
odebug "Uninstalling artifacts"
571587
odebug "#{::Utils.pluralize("artifact", artifacts.length, include_count: true)} defined", artifacts
572588

589+
if login_items?
590+
@cask.login_items.each do |lgi|
591+
# TODO: unregister the login_items here using osascript
592+
ohai "***** Will UNREGISTER login_item: #{lgi}"
593+
end
594+
else
595+
ohai "Skipping processing of login_items"
596+
end
597+
573598
artifacts.each do |artifact|
574599
if artifact.respond_to?(:uninstall_phase)
575600
artifact = T.cast(

Library/Homebrew/cask/reinstall.rb

Lines changed: 4 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,7 +17,8 @@ def self.reinstall_casks(
1717
binaries: false,
1818
require_sha: false,
1919
quarantine: false,
20-
zap: false
20+
zap: false,
21+
login_items: true
2122
)
2223
require "cask/installer"
2324

@@ -26,7 +27,7 @@ def self.reinstall_casks(
2627
download_queue = Homebrew::DownloadQueue.new(pour: true) if Homebrew::EnvConfig.download_concurrency > 1
2728
cask_installers = casks.map do |cask|
2829
Installer.new(cask, binaries:, verbose:, force:, skip_cask_deps:, require_sha:, reinstall: true,
29-
quarantine:, zap:, download_queue:)
30+
quarantine:, zap:, download_queue:, login_items:)
3031
end
3132

3233
if download_queue

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

@@ -145,7 +147,7 @@ def self.upgrade_casks!(
145147
upgrade_cask(
146148
old_cask, new_cask,
147149
binaries:, force:, skip_cask_deps:, verbose:,
148-
quarantine:, require_sha:, download_queue:
150+
quarantine:, require_sha:, download_queue:, login_items:
149151
)
150152
rescue => e
151153
new_exception = e.exception("#{new_cask.full_name}: #{e}")
@@ -169,14 +171,15 @@ def self.upgrade_casks!(
169171
force: T.nilable(T::Boolean),
170172
quarantine: T.nilable(T::Boolean),
171173
require_sha: T.nilable(T::Boolean),
174+
login_items: T.nilable(T::Boolean),
172175
skip_cask_deps: T.nilable(T::Boolean),
173176
verbose: T.nilable(T::Boolean),
174177
download_queue: T.nilable(Homebrew::DownloadQueue),
175178
).void
176179
}
177180
def self.upgrade_cask(
178181
old_cask, new_cask,
179-
binaries:, force:, quarantine:, require_sha:, skip_cask_deps:, verbose:, download_queue:
182+
binaries:, force:, quarantine:, require_sha:, login_items:, skip_cask_deps:, verbose:, download_queue:
180183
)
181184
require "cask/installer"
182185

@@ -205,6 +208,7 @@ def self.upgrade_cask(
205208
upgrade: true,
206209
quarantine:,
207210
download_queue:,
211+
login_items:,
208212
}.compact
209213

210214
new_cask_installer =

0 commit comments

Comments
 (0)