Skip to content

Commit

Permalink
Focus "Package Control Messages" depending on unattended flag
Browse files Browse the repository at this point in the history
This commit associates decision about whether to focus
"Package Control Messages" with the already existing "unattended" mode, which
is already used to suppress error dialogs etc. for background tasks such as
package cleanup or automatic upgrades.

Note: Existing "Package Control Messages" views keep unfocused.
  • Loading branch information
deathaxe committed Aug 3, 2023
1 parent 7360e1e commit 7ed5f1b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
6 changes: 3 additions & 3 deletions package_control/package_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def cleanup_pending_packages(self):
package_name
)

elif not self.manager.install_package(package_name):
elif not self.manager.install_package(package_name, unattended=True):
create_empty_file(reinstall_file)

# Convert unpacked managed package into unmanaged package,
Expand Down Expand Up @@ -319,7 +319,7 @@ def migrate_incompatible_packages(self, found_packages):
for package_name in sorted(migrate_packages, key=lambda s: s.lower()):
try:
progress.set_label('Migrating package {}...'.format(package_name))
result = self.manager.install_package(package_name)
result = self.manager.install_package(package_name, unattended=True)
if result is True:
num_success += 1

Expand Down Expand Up @@ -434,7 +434,7 @@ def install_missing_packages(self, found_packages):
)
if tasks:
with ActivityIndicator('Installing missing packages...') as progress:
self.run_install_tasks(tasks, package_kind='missing', progress=progress)
self.run_install_tasks(tasks, progress, unattended=True, package_kind='missing')

# Drop remaining missing packages, which seem no longer available upstream,
# to avoid trying again and again each time ST starts.
Expand Down
14 changes: 10 additions & 4 deletions package_control/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ def remove_library(self, lib):
)
return True

def install_package(self, package_name):
def install_package(self, package_name, unattended=False):
"""
Downloads and installs (or upgrades) a package
Expand All @@ -1468,6 +1468,9 @@ def install_package(self, package_name):
:param package_name:
The package to download and install
:param unattended:
If ``True`` suppress message dialogs and don't focus "Package Control Messages".
:return: bool if the package was successfully installed or None
if the package needs to be cleaned up on the next restart
and should not be re-enabled
Expand Down Expand Up @@ -1743,7 +1746,7 @@ def install_package(self, package_name):

new_version = release['version']

self.print_messages(package_name, package_dir, is_upgrade, old_version, new_version)
self.print_messages(package_name, package_dir, is_upgrade, old_version, new_version, unattended)

with open(package_metadata_file, 'w', encoding='utf-8') as fobj:
now = time.time()
Expand Down Expand Up @@ -2138,7 +2141,7 @@ def prune_backup_dir(self):
except ValueError:
continue

def print_messages(self, package_name, package_dir, is_upgrade, old_version, new_version):
def print_messages(self, package_name, package_dir, is_upgrade, old_version, new_version, unattended):
"""
Prints out package install and upgrade messages
Expand All @@ -2160,6 +2163,9 @@ def print_messages(self, package_name, package_dir, is_upgrade, old_version, new
:param new_version:
The new (string) version of the package
:param unattended:
If ``True`` don't focus "Package Control Messages".
"""

try:
Expand Down Expand Up @@ -2249,7 +2255,7 @@ def read_message(message_path):
view = window.new_file()
window.set_view_index(view, 0, 0)

if active_view:
if unattended and active_view:
window.focus_view(active_view)

view.set_name('Package Control Messages')
Expand Down
29 changes: 19 additions & 10 deletions package_control/package_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def install_packages(self, packages, unattended=False, progress=None):
A list or set of unicode strings with package names to install.
:param unattended:
If ``True`` suppress message dialogs.
If ``True`` suppress message dialogs and don't focus "Package Control Messages".
:param progress:
An ``ActivityIndicator`` object to use for status information.
Expand Down Expand Up @@ -167,7 +167,7 @@ def install_packages(self, packages, unattended=False, progress=None):
show_message(message)
return

return self.run_install_tasks(tasks, progress)
return self.run_install_tasks(tasks, progress, unattended)

def upgrade_packages(self, packages=None, ignore_packages=None, unattended=False, progress=None):
"""
Expand All @@ -181,7 +181,7 @@ def upgrade_packages(self, packages=None, ignore_packages=None, unattended=False
A list or set of unicode strings with package names to exclude from updating.
:param unattended:
If ``True`` suppress message dialogs.
If ``True`` suppress message dialogs and don't focus "Package Control Messages".
:param progress:
An ``ActivityIndicator`` object to use for status information.
Expand Down Expand Up @@ -238,7 +238,7 @@ def upgrade_packages(self, packages=None, ignore_packages=None, unattended=False
show_message(message)
return True

return self.run_upgrade_tasks(tasks, progress)
return self.run_upgrade_tasks(tasks, progress, unattended)

def remove_packages(self, packages, progress=None, package_kind=''):
"""
Expand Down Expand Up @@ -312,12 +312,15 @@ def remove_packages(self, packages, progress=None, package_kind=''):
time.sleep(0.7)
self.reenable_packages({self.REMOVE: packages - deferred})

def satisfy_packages(self, progress=None):
def satisfy_packages(self, progress=None, unattended=False):
"""
Install missing and remove orphaned packages.
:param progress:
An ``ActivityIndicator`` object to use for status information.
:param unattended:
If ``True`` suppress message dialogs and don't focus "Package Control Messages".
"""

installed_packages = self.manager.installed_packages()
Expand All @@ -331,7 +334,7 @@ def satisfy_packages(self, progress=None):
)

if tasks:
self.run_install_tasks(tasks, progress, package_kind='missing')
self.run_install_tasks(tasks, progress, unattended, package_kind='missing')

# find all managed orphaned packages
orphaned_packages = set(filter(self.manager.is_managed, found_packages - installed_packages))
Expand All @@ -343,7 +346,7 @@ def satisfy_packages(self, progress=None):
if progress:
progress.finish(message)

def run_install_tasks(self, tasks, progress=None, package_kind=''):
def run_install_tasks(self, tasks, progress=None, unattended=False, package_kind=''):
"""
Execute specified package install tasks
Expand All @@ -353,6 +356,9 @@ def run_install_tasks(self, tasks, progress=None, package_kind=''):
:param progress:
An ``ActivityIndicator`` object to use for status information.
:param unattended:
If ``True`` suppress message dialogs and don't focus "Package Control Messages".
:param package_kind:
A unicode string with an additional package attribute.
(e.g.: `missing`, ...)
Expand Down Expand Up @@ -382,7 +388,7 @@ def run_install_tasks(self, tasks, progress=None, package_kind=''):
for task in tasks:
if progress:
progress.set_label('Installing {}package {}'.format(package_kind, task.package_name))
result = self.manager.install_package(task.package_name)
result = self.manager.install_package(task.package_name, unattended)
if result is True:
num_success += 1
# do not re-enable package if operation is deferred to next start
Expand All @@ -406,7 +412,7 @@ def run_install_tasks(self, tasks, progress=None, package_kind=''):
time.sleep(0.7)
self.reenable_packages({self.INSTALL: package_names})

def run_upgrade_tasks(self, tasks, progress=None):
def run_upgrade_tasks(self, tasks, progress=None, unattended=False):
"""
Execute specified package update tasks
Expand All @@ -416,6 +422,9 @@ def run_upgrade_tasks(self, tasks, progress=None):
:param progress:
An ``ActivityIndicator`` object to use for status information.
:param unattended:
If ``True`` suppress message dialogs and don't focus "Package Control Messages".
:return:
``True``, if upgrade was completed.
``False``, if Package Control has been updated.
Expand Down Expand Up @@ -466,7 +475,7 @@ def run_upgrade_tasks(self, tasks, progress=None):
package = task.package_name
if progress:
progress.set_label('Upgrading package {}'.format(task.package_name))
result = self.manager.install_package(package)
result = self.manager.install_package(package, unattended)
if result is True:
num_success += 1
# do not re-enable package if operation is deferred to next start
Expand Down

0 comments on commit 7ed5f1b

Please sign in to comment.