Skip to content

Commit

Permalink
Release 0.11.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ngld committed Jul 9, 2018
2 parents b711dd6 + f1a1d24 commit 57e3051
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 215 deletions.
2 changes: 0 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@
check_module('requests_toolbelt')
check_module('ply')
check_module('token_bucket')
# if sys.platform == 'win32':
# check_module('comtypes')

# We want to use the more modern QtWebEngine by default so we check for that first.
webkit = False
Expand Down
6 changes: 2 additions & 4 deletions html/templates/kn-devel-page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,7 @@ export default {
call(fs2mod.addPkgExe, this.selected_mod.folder, (files) => {
for(let path of files) {
this.selected_pkg.executables.push({
'file': path,
'debug': false
'file': path
});
}
});
Expand All @@ -419,8 +418,7 @@ export default {
for(let path of files) {
if(exes.indexOf(path) === -1) {
this.selected_pkg.executables.push({
'file': path,
'debug': false
'file': path
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion knossos/center.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# The version should follow the http://semver.org guidelines.
# Only remove the -dev tag if you're making a release!
VERSION = '0.11.0'
VERSION = '0.11.1'
UPDATE_LINK = 'https://fsnebula.org/knossos'
INNOEXTRACT_LINK = 'https://dev.tproxy.de/knossos/innoextract.txt'
DEBUG = os.getenv('KN_DEBUG', '0').strip() == '1'
Expand Down
171 changes: 30 additions & 141 deletions knossos/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
from __future__ import absolute_import, print_function

import sys
import os
import logging
import shlex

from . import uhf
uhf(__name__)

from . import center, qt, launcher
from . import center, qt


tr = qt.QtCore.QCoreApplication.translate
Expand All @@ -46,60 +44,11 @@ def annoy_user(self, activate=True):
if center.main_win and activate:
center.app.alert(center.main_win, 3000)

def install_scheme_handler(self):
pass


class LinuxIntegration(Integration):

def install_scheme_handler(self):
my_cmd = launcher.get_cmd()

tpl_desktop = r"""[Desktop Entry]
Name=Knossos
Exec={PATH} %U
Icon={ICON_PATH}
Type=Application
Terminal=false
MimeType=x-scheme-handler/fso;
"""

tpl_mime_type = 'x-scheme-handler/fso=knossos.desktop;'

applications_path = os.path.expanduser('~/.local/share/applications/')
desktop_file = applications_path + 'knossos.desktop'
mime_types_file = applications_path + 'mimeapps.list'
my_path = ' '.join([shlex.quote(p) for p in my_cmd])

if os.path.isfile(desktop_file) or os.path.isfile('/usr/share/applications/knossos.desktop'):
return True

tpl_desktop = tpl_desktop.replace('{PATH}', my_path)
tpl_desktop = tpl_desktop.replace('{ICON_PATH}', os.path.abspath(launcher.get_file_path('hlp.png')))

if not os.path.isdir(applications_path):
os.makedirs(applications_path)

with open(desktop_file, 'w') as output_file:
output_file.write(tpl_desktop)

found = False
if os.path.isfile(mime_types_file):
with open(mime_types_file, 'r') as lines:
for line in lines:
if tpl_mime_type in line:
found = True
break
def set_busy(self):
self.show_progress(0)

if not found:
with open(mime_types_file, 'a') as output_file:
output_file.write(tpl_mime_type)

return True


class UnityIntegration(LinuxIntegration):
launcher = None
class UnityIntegration(Integration):

def __init__(self, Unity):
try:
Expand Down Expand Up @@ -141,75 +90,39 @@ def annoy_user(self, activate=True):


class WindowsIntegration(Integration):
TBPF_NOPROGRESS = 0x0
TBPF_INDETERMINATE = 0x1
TBPF_NORMAL = 0x2
TBPF_ERROR = 0x4
TBPF_PAUSED = 0x8

taskbar = None
_hwnd = None
_win = None
_busy = False

def __init__(self, taskbar):
self.taskbar = taskbar

try:
taskbar.HrInit()
except Exception:
logging.exception('taskbar.HrInit() failed!')

def wid(self):
win = center.main_win.win
if win != self._win:
self._hwnd = win.winId()
self._win = win
def __init__(self):
from PyQt5 import QtWinExtras

return self._hwnd
self._button = QtWinExtras.QWinTaskbarButton()
self._button.setWindow(center.main_win.win.windowHandle())
self._progress = self._button.progress()

def show_progress(self, value):
try:
self.taskbar.SetProgressState(self.wid(), self.TBPF_NORMAL)
except Exception:
logging.exception('COM error')

self.set_progress(value)
self._progress.show()

def set_progress(self, value):
try:
self.taskbar.SetProgressValue(self.wid(), int(value * 100), 100)
except Exception:
logging.exception('COM error')
if self._busy:
self._busy = False
self._progress.setRange(0, 100)

def hide_progress(self):
try:
self.taskbar.SetProgressState(self.wid(), self.TBPF_NOPROGRESS)
except Exception:
logging.exception('COM error')

def install_scheme_handler(self):
my_cmd = launcher.get_cmd()

settings = qt.QtCore.QSettings('HKEY_CLASSES_ROOT\\fso', qt.QtCore.QSettings.NativeFormat)
settings.setFallbacksEnabled(False)

settings.setValue('Default', 'URL:Knossos protocol')
settings.setValue('URL Protocol', '')
settings.setValue('DefaultIcon/Default', '"' + launcher.get_file_path('hlp.ico') + ',1"')
self._progress.setValue(int(value * 100))

my_cmd.append('%1')
my_path = ' '.join(['"' + p + '"' for p in my_cmd])

settings.setValue('shell/open/command/Default', my_path)

# Check
# FIXME: Is there any better way to detect whether this worked or not?
def hide_progress(self):
self._progress.hide()

settings.sync()
settings = qt.QtCore.QSettings('HKEY_CLASSES_ROOT\\fso', qt.QtCore.QSettings.NativeFormat)
settings.setFallbacksEnabled(False)
def set_busy(self):
if self._busy:
self._progress.show()
return

return settings.value('shell/open/command/Default') == my_path
self._busy = True
self._progress.setRange(0, 0)
self._progress.setValue(0)
self._progress.show()


current = None
Expand All @@ -220,16 +133,12 @@ def init():

if sys.platform == 'win32':
try:
import comtypes.client as cc

tlb = cc.GetModule('taskbar.tlb')
taskbar = cc.CreateObject('{56FDF344-FD6D-11d0-958A-006097C9A090}', interface=tlb.ITaskbarList3)
except Exception:
logging.exception('Failed to load ITaskbarList3! Disabling Windows integration.')
else:
logging.info('Activating Windows integration...')
current = WindowsIntegration(taskbar)
current = WindowsIntegration()
return
except Exception:
logging.exception('Failed to activate the Windows integration.')

elif sys.platform.startswith('linux'):
try:
import gi
Expand All @@ -248,25 +157,5 @@ def init():
current = UnityIntegration(Unity)
return

logging.info('Activating generic Linux integration...')
current = LinuxIntegration()
return

logging.warning('No desktop integration active.')
logging.info('No desktop integration active.')
current = Integration()


def install_scheme_handler(interactive=True):
logging.info('Installing scheme handler...')

try:
if current.install_scheme_handler():
if interactive:
qt.QtWidgets.QMessageBox.information(None, 'Knossos', tr('integration', 'Done!'))

return
except Exception:
logging.exception('Failed to install the scheme handler!')

qt.QtWidgets.QMessageBox.critical(None, 'Knossos',
tr('integration', 'I probably failed to install the scheme handler.\nRun me as administrator and try again.'))
21 changes: 8 additions & 13 deletions knossos/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
from . import py2_compat # noqa

from .qt import QtCore, QtGui, QtWidgets, variant as qt_variant
from .tasks import run_task, CheckUpdateTask
from . import util, ipc, auto_fetch


Expand Down Expand Up @@ -158,9 +157,12 @@ def load_settings():
def run_knossos():
global app

from . import repo, progress, integration
from .windows import HellWindow

center.app = app
center.main_win = HellWindow()
app.processEvents()

if sys.platform.startswith('win') and os.path.isfile('7z.exe'):
util.SEVEN_PATH = os.path.abspath('7z.exe')
elif sys.platform == 'darwin' and os.path.isfile('7z'):
Expand All @@ -177,7 +179,8 @@ def run_knossos():
if center.settings['download_bandwidth'] > 0.0:
util.SPEED_LIMIT_BUCKET.set_rate(center.settings['download_bandwidth'])

center.app = app
from . import repo, progress, integration

center.installed = repo.InstalledRepo()
center.pmaster = progress.Master()
center.pmaster.start_workers(10)
Expand All @@ -196,9 +199,7 @@ def run_knossos():
logging.exception('Failed to load local mod list!')
center.mods.clear()

center.main_win = HellWindow()
center.main_win.start_init()
center.main_win.open()

app.exec_()

Expand Down Expand Up @@ -300,7 +301,7 @@ def main():

logging.debug('Loading settings...')
load_settings()

trans = QtCore.QTranslator()
if center.settings['language']:
lang = center.settings['language']
Expand All @@ -316,13 +317,7 @@ def main():
ipc_conn = ipc.IPCComm(center.settings_path)

if len(sys.argv) > 1:
if sys.argv[1] == '--install-scheme':
from . import integration

integration.init()
integration.install_scheme_handler('--silent' not in sys.argv)
return
elif sys.argv[1] == '--finish-update':
if sys.argv[1] == '--finish-update':
updater = sys.argv[2]

if not os.path.isfile(updater):
Expand Down
2 changes: 1 addition & 1 deletion knossos/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ def get_mod_flag(self):
if mod.dev_mode:
# Sort packages by their folder name since FSO also sorts VPs by their name.
# See https://github.com/ngld/knossos/issues/107 for more details.
for pkg in sorted(mod.packages, key=lambda pkg: pkg.folder):
for pkg in sorted(mod.packages, key=lambda pkg: pkg.folder, reverse=True):
if pkg.check_env():
paths.append((os.path.join(mod.folder, pkg.folder), '%s - %s' % (mod.title, pkg.name)))
dev_involved = True
Expand Down
23 changes: 17 additions & 6 deletions knossos/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def changeEvent(self, event):
if integration.current is not None:
integration.current.annoy_user(False)

if center.main_win and center.main_win.win.isActiveWindow():
if center.main_win and center.main_win.win.isActiveWindow() and center.auto_fetcher:
center.auto_fetcher.trigger()

return super(QMainWindow, self).changeEvent(event)
Expand Down Expand Up @@ -348,16 +348,18 @@ def watch_task(self, task):
self.win.progressLabel.setText(task.title)
self.win.progressBar.setValue(0)

integration.current.show_progress(0)
integration.current.set_busy()

def _track_progress(self, task, pi):
self.browser_ctrl.bridge.taskProgress.emit(id(task), pi[0] * 100, json.dumps(pi[1]))

for m in task.mods:
self._updating_mods[m.mid] = pi[0] * 100

if len(self._tasks) == 1 and pi[0] > 0:
integration.current.set_progress(pi[0])

if len(task.mods) == 0 and self._prg_visible:
integration.current.set_progress(pi[0])
self.win.progressBar.setValue(pi[0] * 100)

def _forget_task(self, task):
Expand All @@ -372,9 +374,18 @@ def _forget_task(self, task):
del self._updating_mods[m.mid]

if len(task.mods) == 0 and self._prg_visible:
self._prg_visible = False
self.win.progressInfo.hide()
integration.current.hide_progress()
global_tasks = [t for t in self._tasks.values() if len(t.mods) == 0]
if len(global_tasks) > 0:
self.win.progressLabel.setText(global_tasks[0].title)
self.win.progressBar.setValue(0)
integration.current.set_busy()

else:
self._prg_visible = False
self.win.progressInfo.hide()

if len(self._tasks) == 0:
integration.current.hide_progress()

def abort_task(self, task):
if task in self._tasks:
Expand Down
Loading

0 comments on commit 57e3051

Please sign in to comment.