Skip to content

Commit af24c14

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 c430720 commit af24c14

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
@@ -328,6 +328,10 @@ def languages
328328
@languages ||= @dsl.languages
329329
end
330330

331+
def login_items
332+
@login_items ||= @dsl.login_items
333+
end
334+
331335
def tap_git_head
332336
@tap_git_head ||= tap&.git_head
333337
rescue TapUnavailableError
@@ -338,6 +342,7 @@ def populate_from_api!(json_cask)
338342
raise ArgumentError, "Expected cask to be loaded from the API" unless loaded_from_api?
339343

340344
@languages = json_cask.fetch(:languages, [])
345+
@login_items = json_cask.fetch(:login_items, [])
341346
@tap_git_head = json_cask.fetch(:tap_git_head, "HEAD")
342347

343348
@ruby_source_path = json_cask[:ruby_source_path]
@@ -408,6 +413,7 @@ def to_h
408413
"languages" => languages,
409414
"ruby_source_path" => ruby_source_path,
410415
"ruby_source_checksum" => ruby_source_checksum,
416+
"login_items" => login_items,
411417
}
412418
end
413419

Library/Homebrew/cask/cask_loader.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ def load(config:)
372372
end
373373
desc json_cask[:desc]
374374
homepage json_cask[:homepage]
375+
login_items json_cask[:login_items] if json_cask[:login_items].present?
375376

376377
if (deprecation_date = json_cask[:deprecation_date].presence)
377378
reason = DeprecateDisable.to_reason_string_or_symbol json_cask[:deprecation_reason], type: :cask
@@ -383,7 +384,7 @@ def load(config:)
383384
disable! date: disable_date, because: reason
384385
end
385386

386-
auto_updates json_cask[:auto_updates] unless json_cask[:auto_updates].nil?
387+
auto_updates json_cask[:auto_updates] if json_cask[:auto_updates].present?
387388
conflicts_with(**json_cask[:conflicts_with]) if json_cask[:conflicts_with].present?
388389

389390
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

@@ -344,6 +349,17 @@ def install_artifacts(predecessor: nil)
344349
already_installed_artifacts.unshift(artifact)
345350
end
346351

352+
unless @cask.login_items.empty?
353+
if login_items?
354+
@cask.login_items.each do |lgi|
355+
# TODO: register the login_items here using osascript
356+
ohai "***** Will REGISTER login_item: #{lgi}"
357+
end
358+
else
359+
ohai "Skipping processing of login_items"
360+
end
361+
end
362+
347363
save_config_file
348364
save_download_sha if @cask.version.latest?
349365
rescue => e
@@ -588,6 +604,15 @@ def uninstall_artifacts(clear: false, successor: nil)
588604
odebug "Uninstalling artifacts"
589605
odebug "#{::Utils.pluralize("artifact", artifacts.length, include_count: true)} defined", artifacts
590606

607+
if login_items?
608+
@cask.login_items.each do |lgi|
609+
# TODO: unregister the login_items here using osascript
610+
ohai "***** Will UNREGISTER login_item: #{lgi}"
611+
end
612+
else
613+
ohai "Skipping processing of login_items"
614+
end
615+
591616
artifacts.each do |artifact|
592617
if artifact.respond_to?(:uninstall_phase)
593618
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
@@ -24,6 +24,7 @@ class Upgrade
2424
binaries: T.nilable(T::Boolean),
2525
quarantine: T.nilable(T::Boolean),
2626
require_sha: T.nilable(T::Boolean),
27+
login_items: T.nilable(T::Boolean),
2728
).returns(T::Boolean)
2829
}
2930
def self.upgrade_casks!(
@@ -39,7 +40,8 @@ def self.upgrade_casks!(
3940
quiet: false,
4041
binaries: nil,
4142
quarantine: nil,
42-
require_sha: nil
43+
require_sha: nil,
44+
login_items: nil
4345
)
4446
quarantine = true if quarantine.nil?
4547

@@ -151,7 +153,7 @@ def self.upgrade_casks!(
151153
upgrade_cask(
152154
old_cask, new_cask,
153155
binaries:, force:, skip_cask_deps:, verbose:,
154-
quarantine:, require_sha:, download_queue:
156+
quarantine:, require_sha:, download_queue:, login_items:
155157
)
156158
rescue => e
157159
new_exception = e.exception("#{new_cask.full_name}: #{e}")
@@ -175,14 +177,15 @@ def self.upgrade_casks!(
175177
force: T.nilable(T::Boolean),
176178
quarantine: T.nilable(T::Boolean),
177179
require_sha: T.nilable(T::Boolean),
180+
login_items: T.nilable(T::Boolean),
178181
skip_cask_deps: T.nilable(T::Boolean),
179182
verbose: T.nilable(T::Boolean),
180183
download_queue: T.nilable(Homebrew::DownloadQueue),
181184
).void
182185
}
183186
def self.upgrade_cask(
184187
old_cask, new_cask,
185-
binaries:, force:, quarantine:, require_sha:, skip_cask_deps:, verbose:, download_queue:
188+
binaries:, force:, quarantine:, require_sha:, login_items:, skip_cask_deps:, verbose:, download_queue:
186189
)
187190
require "cask/installer"
188191

@@ -211,6 +214,7 @@ def self.upgrade_cask(
211214
upgrade: true,
212215
quarantine:,
213216
download_queue:,
217+
login_items:,
214218
}.compact
215219

216220
new_cask_installer =

0 commit comments

Comments
 (0)