Skip to content

Commit 436f85f

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 4d14be8 commit 436f85f

34 files changed

+209
-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
@@ -105,6 +105,7 @@ class DSL
105105
:no_autobump!,
106106
:autobump?,
107107
:no_autobump_message,
108+
:login_items,
108109
:on_system_blocks_exist?,
109110
:on_system_block_min_os,
110111
:depends_on_set_in_block?,
@@ -239,6 +240,21 @@ def set_unique_stanza(stanza, should_return)
239240
raise CaskInvalidError.new(cask, "'#{stanza}' stanza failed with: #{e}")
240241
end
241242

243+
# Sets the cask's login items
244+
#
245+
# ### Example
246+
#
247+
# ```ruby
248+
# login_items "Raycast"
249+
# ```
250+
#
251+
# @api public
252+
def login_items(login_items = nil)
253+
return [] if login_items.nil?
254+
255+
set_unique_stanza(:login_items, login_items.nil?) { Array(login_items) }
256+
end
257+
242258
# Sets the cask's homepage.
243259
#
244260
# ### 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
24+
quiet: T::Boolean, 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)
31+
quarantine: true, verify_download_integrity: true, quiet: false,
32+
login_items: false)
3233
@cask = cask
3334
@command = command
3435
@force = force
@@ -45,6 +46,7 @@ def initialize(cask, command: SystemCommand, force: false, adopt: false,
4546
@quarantine = quarantine
4647
@verify_download_integrity = verify_download_integrity
4748
@quiet = quiet
49+
@login_items = login_items
4850
end
4951

5052
sig { returns(T::Boolean) }
@@ -62,6 +64,9 @@ def installed_as_dependency? = @installed_as_dependency
6264
sig { returns(T::Boolean) }
6365
def installed_on_request? = @installed_on_request
6466

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

@@ -325,6 +330,17 @@ def install_artifacts(predecessor: nil)
325330
already_installed_artifacts.unshift(artifact)
326331
end
327332

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

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

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: true
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 =

0 commit comments

Comments
 (0)