Skip to content

Commit 76e97c0

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 0d9b9b4 commit 76e97c0

34 files changed

+207
-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,
@@ -297,6 +298,7 @@ def uninstall_signal(*signals, command: nil, **_)
297298
end
298299
end
299300

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

Library/Homebrew/cask/cask.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,10 @@ def languages
347347
@languages ||= @dsl.languages
348348
end
349349

350+
def login_items
351+
@login_items ||= @dsl.login_items
352+
end
353+
350354
def tap_git_head
351355
@tap_git_head ||= tap&.git_head
352356
rescue TapUnavailableError
@@ -357,6 +361,7 @@ def populate_from_api!(json_cask)
357361
raise ArgumentError, "Expected cask to be loaded from the API" unless loaded_from_api?
358362

359363
@languages = json_cask.fetch(:languages, [])
364+
@login_items = json_cask.fetch(:login_items, [])
360365
@tap_git_head = json_cask.fetch(:tap_git_head, "HEAD")
361366

362367
@ruby_source_path = json_cask[:ruby_source_path]
@@ -427,6 +432,7 @@ def to_h
427432
"languages" => languages,
428433
"ruby_source_path" => ruby_source_path,
429434
"ruby_source_checksum" => ruby_source_checksum,
435+
"login_items" => login_items,
430436
}
431437
end
432438

Library/Homebrew/cask/cask_loader.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ def load(config:)
377377
end
378378
desc json_cask[:desc]
379379
homepage json_cask[:homepage]
380+
login_items json_cask[:login_items] if json_cask[:login_items].present?
380381

381382
if (date = json_cask[:deprecation_date].presence)
382383
because = DeprecateDisable.to_reason_string_or_symbol json_cask[:deprecation_reason], type: :cask
@@ -389,7 +390,7 @@ def load(config:)
389390
disable! date:, because:
390391
end
391392

392-
auto_updates json_cask[:auto_updates] unless json_cask[:auto_updates].nil?
393+
auto_updates json_cask[:auto_updates] if json_cask[:auto_updates].present?
393394
conflicts_with(**json_cask[:conflicts_with]) if json_cask[:conflicts_with].present?
394395

395396
if json_cask[:rename].present?

Library/Homebrew/cask/dsl.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class DSL
109109
:no_autobump!,
110110
:autobump?,
111111
:no_autobump_message,
112+
:login_items,
112113
:on_system_blocks_exist?,
113114
:on_system_block_min_os,
114115
:depends_on_set_in_block?,
@@ -244,6 +245,21 @@ def set_unique_stanza(stanza, should_return)
244245
raise CaskInvalidError.new(cask, "'#{stanza}' stanza failed with: #{e}")
245246
end
246247

248+
# Sets the cask's login items
249+
#
250+
# ### Example
251+
#
252+
# ```ruby
253+
# login_items "Raycast"
254+
# ```
255+
#
256+
# @api public
257+
def login_items(login_items = nil)
258+
return [] if login_items.nil?
259+
260+
set_unique_stanza(:login_items, login_items.nil?) { Array(login_items) }
261+
end
262+
247263
# Sets the cask's homepage.
248264
#
249265
# ### Example

Library/Homebrew/cask/info.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def self.get_info(cask)
3030
language = language_info(cask)
3131
output << language if language
3232
output << "#{artifact_info(cask)}\n"
33+
login_items = login_items_info(cask)
34+
output << login_items if login_items
3335
caveats = Installer.caveats(cask)
3436
output << caveats if caveats
3537
output
@@ -137,5 +139,15 @@ def self.artifact_info(cask)
137139
end
138140
artifact_output.freeze
139141
end
142+
143+
sig { params(cask: Cask).returns(T.nilable(String)) }
144+
def self.login_items_info(cask)
145+
return if cask.login_items.empty?
146+
147+
<<~EOS
148+
#{ohai_title("Login Items")}
149+
#{cask.login_items.join(", ")}
150+
EOS
151+
end
140152
end
141153
end

Library/Homebrew/cask/installer.rb

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ class Installer
2525
skip_cask_deps: T::Boolean, binaries: T::Boolean, verbose: T::Boolean, zap: T::Boolean,
2626
require_sha: T::Boolean, upgrade: T::Boolean, reinstall: T::Boolean, installed_as_dependency: T::Boolean,
2727
installed_on_request: T::Boolean, quarantine: T::Boolean, verify_download_integrity: T::Boolean,
28-
quiet: T::Boolean, download_queue: T.nilable(Homebrew::DownloadQueue)
28+
quiet: T::Boolean, download_queue: T.nilable(Homebrew::DownloadQueue), login_items: T::Boolean
2929
).void
3030
}
3131
def initialize(cask, command: SystemCommand, force: false, adopt: false,
3232
skip_cask_deps: false, binaries: true, verbose: false,
3333
zap: false, require_sha: false, upgrade: false, reinstall: false,
3434
installed_as_dependency: false, installed_on_request: true,
35-
quarantine: true, verify_download_integrity: true, quiet: false, download_queue: nil)
35+
quarantine: true, verify_download_integrity: true, quiet: false, download_queue: nil,
36+
login_items: false)
3637
@cask = cask
3738
@command = command
3839
@force = force
@@ -51,6 +52,7 @@ def initialize(cask, command: SystemCommand, force: false, adopt: false,
5152
@quiet = quiet
5253
@download_queue = download_queue
5354
@ran_prelude = T.let(false, T::Boolean)
55+
@login_items = login_items
5456
end
5557

5658
sig { returns(T::Boolean) }
@@ -68,6 +70,9 @@ def installed_as_dependency? = @installed_as_dependency
6870
sig { returns(T::Boolean) }
6971
def installed_on_request? = @installed_on_request
7072

73+
sig { returns(T::Boolean) }
74+
def login_items? = @login_items
75+
7176
sig { returns(T::Boolean) }
7277
def quarantine? = @quarantine
7378

@@ -348,6 +353,17 @@ def install_artifacts(predecessor: nil)
348353
already_installed_artifacts.unshift(artifact)
349354
end
350355

356+
unless @cask.login_items.empty?
357+
if login_items?
358+
@cask.login_items.each do |lgi|
359+
# TODO: register the login_items here using osascript
360+
ohai "***** Will REGISTER login_item: #{lgi}"
361+
end
362+
else
363+
ohai "Skipping processing of login_items"
364+
end
365+
end
366+
351367
save_config_file
352368
save_download_sha if @cask.version.latest?
353369
rescue => e
@@ -592,6 +608,15 @@ def uninstall_artifacts(clear: false, successor: nil)
592608
odebug "Uninstalling artifacts"
593609
odebug "#{::Utils.pluralize("artifact", artifacts.length, include_count: true)} defined", artifacts
594610

611+
if login_items?
612+
@cask.login_items.each do |lgi|
613+
# TODO: unregister the login_items here using osascript
614+
ohai "***** Will UNREGISTER login_item: #{lgi}"
615+
end
616+
else
617+
ohai "Skipping processing of login_items"
618+
end
619+
595620
artifacts.each do |artifact|
596621
if artifact.respond_to?(:uninstall_phase)
597622
artifact = T.cast(

Library/Homebrew/cask/reinstall.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Reinstall
1010
sig {
1111
params(
1212
casks: ::Cask::Cask, verbose: T::Boolean, force: T::Boolean, skip_cask_deps: T::Boolean, binaries: T::Boolean,
13-
require_sha: T::Boolean, quarantine: T::Boolean, zap: T::Boolean
13+
require_sha: T::Boolean, quarantine: T::Boolean, zap: T::Boolean, login_items: T::Boolean
1414
).void
1515
}
1616
def self.reinstall_casks(
@@ -21,7 +21,8 @@ def self.reinstall_casks(
2121
binaries: false,
2222
require_sha: false,
2323
quarantine: false,
24-
zap: false
24+
zap: false,
25+
login_items: true
2526
)
2627
require "cask/installer"
2728

@@ -30,7 +31,7 @@ def self.reinstall_casks(
3031
download_queue = Homebrew::DownloadQueue.new_if_concurrency_enabled(pour: true)
3132
cask_installers = casks.map do |cask|
3233
Installer.new(cask, binaries:, verbose:, force:, skip_cask_deps:, require_sha:, reinstall: true,
33-
quarantine:, zap:, download_queue:)
34+
quarantine:, zap:, download_queue:, login_items:)
3435
end
3536

3637
if download_queue

Library/Homebrew/cask/upgrade.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def self.outdated_casks(casks, args:, force:, quiet:,
7171
binaries: T.nilable(T::Boolean),
7272
quarantine: T.nilable(T::Boolean),
7373
require_sha: T.nilable(T::Boolean),
74+
login_items: T.nilable(T::Boolean),
7475
).returns(T::Boolean)
7576
}
7677
def self.upgrade_casks!(
@@ -86,7 +87,8 @@ def self.upgrade_casks!(
8687
quiet: false,
8788
binaries: nil,
8889
quarantine: nil,
89-
require_sha: nil
90+
require_sha: nil,
91+
login_items: nil
9092
)
9193
quarantine = true if quarantine.nil?
9294

@@ -171,7 +173,7 @@ def self.upgrade_casks!(
171173
upgrade_cask(
172174
old_cask, new_cask,
173175
binaries:, force:, skip_cask_deps:, verbose:,
174-
quarantine:, require_sha:, download_queue:
176+
quarantine:, require_sha:, download_queue:, login_items:
175177
)
176178
rescue => e
177179
new_exception = e.exception("#{new_cask.full_name}: #{e}")
@@ -195,14 +197,15 @@ def self.upgrade_casks!(
195197
force: T.nilable(T::Boolean),
196198
quarantine: T.nilable(T::Boolean),
197199
require_sha: T.nilable(T::Boolean),
200+
login_items: T.nilable(T::Boolean),
198201
skip_cask_deps: T.nilable(T::Boolean),
199202
verbose: T.nilable(T::Boolean),
200203
download_queue: T.nilable(Homebrew::DownloadQueue),
201204
).void
202205
}
203206
def self.upgrade_cask(
204207
old_cask, new_cask,
205-
binaries:, force:, quarantine:, require_sha:, skip_cask_deps:, verbose:, download_queue:
208+
binaries:, force:, quarantine:, require_sha:, login_items:, skip_cask_deps:, verbose:, download_queue:
206209
)
207210
require "cask/installer"
208211

@@ -231,6 +234,7 @@ def self.upgrade_cask(
231234
upgrade: true,
232235
quarantine:,
233236
download_queue:,
237+
login_items:,
234238
}.compact
235239

236240
new_cask_installer =

0 commit comments

Comments
 (0)