Skip to content

Commit d934f36

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 5602f0e commit d934f36

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
@@ -326,6 +326,10 @@ def languages
326326
@languages ||= @dsl.languages
327327
end
328328

329+
def login_items
330+
@login_items ||= @dsl.login_items
331+
end
332+
329333
def tap_git_head
330334
@tap_git_head ||= tap&.git_head
331335
rescue TapUnavailableError
@@ -336,6 +340,7 @@ def populate_from_api!(json_cask)
336340
raise ArgumentError, "Expected cask to be loaded from the API" unless loaded_from_api?
337341

338342
@languages = json_cask.fetch(:languages, [])
343+
@login_items = json_cask.fetch(:login_items, [])
339344
@tap_git_head = json_cask.fetch(:tap_git_head, "HEAD")
340345

341346
@ruby_source_path = json_cask[:ruby_source_path]
@@ -405,6 +410,7 @@ def to_h
405410
"languages" => languages,
406411
"ruby_source_path" => ruby_source_path,
407412
"ruby_source_checksum" => ruby_source_checksum,
413+
"login_items" => login_items,
408414
}
409415
end
410416

Library/Homebrew/cask/cask_loader.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ def load(config:)
370370
end
371371
desc json_cask[:desc]
372372
homepage json_cask[:homepage]
373+
login_items json_cask[:login_items] if json_cask[:login_items].present?
373374

374375
if (deprecation_date = json_cask[:deprecation_date].presence)
375376
reason = DeprecateDisable.to_reason_string_or_symbol json_cask[:deprecation_reason], type: :cask
@@ -381,7 +382,7 @@ def load(config:)
381382
disable! date: disable_date, because: reason
382383
end
383384

384-
auto_updates json_cask[:auto_updates] unless json_cask[:auto_updates].nil?
385+
auto_updates json_cask[:auto_updates] if json_cask[:auto_updates].present?
385386
conflicts_with(**json_cask[:conflicts_with]) if json_cask[:conflicts_with].present?
386387

387388
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
@@ -106,6 +106,7 @@ class DSL
106106
:no_autobump!,
107107
:autobump?,
108108
:no_autobump_message,
109+
:login_items,
109110
:on_system_blocks_exist?,
110111
:on_system_block_min_os,
111112
:depends_on_set_in_block?,
@@ -241,6 +242,21 @@ def set_unique_stanza(stanza, should_return)
241242
raise CaskInvalidError.new(cask, "'#{stanza}' stanza failed with: #{e}")
242243
end
243244

245+
# Sets the cask's login items
246+
#
247+
# ### Example
248+
#
249+
# ```ruby
250+
# login_items "Raycast"
251+
# ```
252+
#
253+
# @api public
254+
def login_items(login_items = nil)
255+
return [] if login_items.nil?
256+
257+
set_unique_stanza(:login_items, login_items.nil?) { Array(login_items) }
258+
end
259+
244260
# Sets the cask's homepage.
245261
#
246262
# ### 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
@@ -134,5 +136,15 @@ def self.artifact_info(cask)
134136
end
135137
artifact_output.freeze
136138
end
139+
140+
sig { params(cask: Cask).returns(T.nilable(String)) }
141+
def self.login_items_info(cask)
142+
return if cask.login_items.empty?
143+
144+
<<~EOS
145+
#{ohai_title("Login Items")}
146+
#{cask.login_items.join(", ")}
147+
EOS
148+
end
137149
end
138150
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
@@ -47,6 +48,7 @@ def initialize(cask, command: SystemCommand, force: false, adopt: false,
4748
@quiet = quiet
4849
@download_queue = download_queue
4950
@ran_prelude = T.let(false, T::Boolean)
51+
@login_items = login_items
5052
end
5153

5254
sig { returns(T::Boolean) }
@@ -64,6 +66,9 @@ def installed_as_dependency? = @installed_as_dependency
6466
sig { returns(T::Boolean) }
6567
def installed_on_request? = @installed_on_request
6668

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

@@ -340,6 +345,17 @@ def install_artifacts(predecessor: nil)
340345
already_installed_artifacts.unshift(artifact)
341346
end
342347

348+
unless @cask.login_items.empty?
349+
if login_items?
350+
@cask.login_items.each do |lgi|
351+
# TODO: register the login_items here using osascript
352+
ohai "***** Will REGISTER login_item: #{lgi}"
353+
end
354+
else
355+
ohai "Skipping processing of login_items"
356+
end
357+
end
358+
343359
save_config_file
344360
save_download_sha if @cask.version.latest?
345361
rescue => e
@@ -584,6 +600,15 @@ def uninstall_artifacts(clear: false, successor: nil)
584600
odebug "Uninstalling artifacts"
585601
odebug "#{::Utils.pluralize("artifact", artifacts.length, include_count: true)} defined", artifacts
586602

603+
if login_items?
604+
@cask.login_items.each do |lgi|
605+
# TODO: unregister the login_items here using osascript
606+
ohai "***** Will UNREGISTER login_item: #{lgi}"
607+
end
608+
else
609+
ohai "Skipping processing of login_items"
610+
end
611+
587612
artifacts.each do |artifact|
588613
if artifact.respond_to?(:uninstall_phase)
589614
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

@@ -148,7 +150,7 @@ def self.upgrade_casks!(
148150
upgrade_cask(
149151
old_cask, new_cask,
150152
binaries:, force:, skip_cask_deps:, verbose:,
151-
quarantine:, require_sha:, download_queue:
153+
quarantine:, require_sha:, download_queue:, login_items:
152154
)
153155
rescue => e
154156
new_exception = e.exception("#{new_cask.full_name}: #{e}")
@@ -172,14 +174,15 @@ def self.upgrade_casks!(
172174
force: T.nilable(T::Boolean),
173175
quarantine: T.nilable(T::Boolean),
174176
require_sha: T.nilable(T::Boolean),
177+
login_items: T.nilable(T::Boolean),
175178
skip_cask_deps: T.nilable(T::Boolean),
176179
verbose: T.nilable(T::Boolean),
177180
download_queue: T.nilable(Homebrew::DownloadQueue),
178181
).void
179182
}
180183
def self.upgrade_cask(
181184
old_cask, new_cask,
182-
binaries:, force:, quarantine:, require_sha:, skip_cask_deps:, verbose:, download_queue:
185+
binaries:, force:, quarantine:, require_sha:, login_items:, skip_cask_deps:, verbose:, download_queue:
183186
)
184187
require "cask/installer"
185188

@@ -208,6 +211,7 @@ def self.upgrade_cask(
208211
upgrade: true,
209212
quarantine:,
210213
download_queue:,
214+
login_items:,
211215
}.compact
212216

213217
new_cask_installer =

0 commit comments

Comments
 (0)