Skip to content

Commit

Permalink
Update: デバッグリポジトリの実装
Browse files Browse the repository at this point in the history
  • Loading branch information
S--Minecraft committed Oct 29, 2017
1 parent 1e963fd commit e84b4cc
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 186 deletions.
2 changes: 1 addition & 1 deletion src/core/plistList.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ filter = (parsedObj, useCache = false) ->
if _isNeeded(ver, plat, v3)
obj[k1] = {} if !obj[k1]?
obj[k1][k2] = {} if !obj[k1][k2]?
obj[k1][k2][k3] = v3.name
obj[k1][k2][k3] = v3
return obj

module.exports = {
Expand Down
3 changes: 3 additions & 0 deletions src/gui/css/core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ li {
.form-control-feedback {
flex: 100%;
}
#repo .debug-info {
display: none;
}

.hidden {
display: none;
Expand Down
53 changes: 53 additions & 0 deletions src/gui/debug_repo.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
!!! 5
%html
%head
%meta(charset="utf-8")
%meta(name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no")
%meta(http-equiv="x-ua-compatible" content="ie=edge")
%link(rel="stylesheet" type="text/css" href="../node_modules/bootstrap/dist/css/bootstrap.min.css")
%link(rel="stylesheet" type="text/css" href="css/core.css")
%body
%nav.navbar.navbar-dark.bg-dark.sticky-top.mb-4
.mr-auto
%a(href="./index.html")
%button.btn(type="button")
%img(src="./img/circle-left.svg" height="30px" width="30px")
%span.navbar-brand.pl-2.translate(data-key="DEBUG_REPOSITORY_NAME")
%button.btn#reload(type="button")
%img(src="./img/loop2.svg" height="30px" width="30px")
%button.btn#apply(type="button")
%img(src="./img/checkmark2.svg" height="30px" width="30px")
.container-fluid#debug-repo
.row#root
%description(:hasinfo="hasinfo" :name="infoname" :version="infoversion" :maintainer="infomaintainer" :changelog="changelog")
.col-12.text-center(v-if="loading")
%img.spin(src="./img/spinner2.svg" height="40px" width="40px")
.col-12(v-else-if="error")
%p
%span.translate(data-key="ERROR_HAPPEN")
%p {{errorMsg}}
%big-category(v-else=true v-for="(v, k) in plist" :name="k" :val="v")
.modal.fade#progress
.modal-dialog
.modal-content
.modal-header
%h4.modal-title
%modal-body(:phase="phase" :log="log" :finished="finished")
.modal-footer
%button.btn.btn-primary(type="button" :disabled="!finished" @click="reset")
%span.translate(data-key="BUTTON_CLOSE")
.modal.fade#detail
.modal-dialog
.modal-content
.modal-body#outwebview
%webview#detailweb(src="about:blank" autosize="on")
.modal-footer
%button.btn.btn-primary(type="button" data-dismiss="modal")
%span.translate(data-key="BUTTON_CLOSE")
%script(type="text/javascript")
window.jQuery = window.$ = require("../node_modules/jquery/dist/jquery.slim.min.js");
%script(src="../node_modules/popper.js/dist/umd/popper.min.js")
%script(src="../node_modules/bootstrap/dist/js/bootstrap.min.js")
%script(src="../node_modules/vue/dist/vue.min.js")
%script(src="./js/repo_components.js")
%script(src="./js/debug_repo.js")
2 changes: 1 addition & 1 deletion src/gui/index.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
%img(src="./img/cogs.svg" height="30px" width="30px")
%button.btn#play(type="button")
%img(src="./img/play3.svg" height="30px" width="30px")
.container-fluid
.container-fluid#index
.row#repo
.col-md-6(v-if="remoteRepos.length > 0")
.card
Expand Down
146 changes: 146 additions & 0 deletions src/gui/js/debug_repo.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{remote} = require "electron"
{shell} = remote
plistList = remote.require("./plistList")
plistInfo = remote.require("./plistInfo")
util = remote.require("./util")
config = remote.require("./config")
applyMod = remote.require("./applyMod")
request = remote.require("./request")
lang = remote.require("./lang")

path = config.get("debugRepo")
repo =
type: "local"
name: path
langName = config.get("lang")

langTable = lang.get()
transEle = document.getElementsByClassName("translate")
for te in transEle
te.textContent = langTable[te.dataset.key]

r = new Vue(
el: "#root"
data:
loading: false
error: false
errorMsg: ""
plist: {}
hasinfo: false
infoname: ""
infoversion: ""
infomaintainer: ""
changelog: ""
created: ->
do =>
await @getPlist()
await r.getPlistWithOutBlackout(true)
return
@getInfo()
@getChangelog()
return
methods:
getPlist: (force = false) ->
@loading = true
@error = false
try
obj = await plistList.getUntilDone(repo, langName, force)
@loading = false
@plist = obj
catch err
@loading = false
@error = true
@errorMsg = err
return
getPlistWithOutBlackout: (force = false) ->
@error = false
try
obj = await plistList.getUntilDone(repo, langName, force)
if JSON.stringify(@plist) isnt JSON.stringify(obj)
@plist = obj
catch err
@error = true
@errorMsg = err
return
getInfo: (force = false) ->
try
{name, version, maintainer} = await plistInfo.get(repo, force)
@hasinfo = true
@infoname = name
@infoversion = version
@infomaintainer = maintainer
catch
@hasinfo = false
return
getChangelog: ->
@changelog = await request.getChangelog(repo)
return
)

onBeforeClose = (e) ->
if !confirm(langTable.CONFIRM_APPLY_CLOSE_STRING)
e.returnValue = false
return

document.getElementById("apply").addEventListener("click", ->
return unless confirm(langTable.CONFIRM_APPLY_STRING)
# 閉じる防止
window.addEventListener("beforeunload", onBeforeClose)

addMods = []
deleteMods = []
for $mod in $("button:not(.applied) input:checked")
addMods.push({repo, name: $mod.dataset.path, showname: $mod.dataset.name})
for $mod in $("button.applied input:not(:checked)")
deleteMods.push({repo, name: $mod.dataset.path, showname: $mod.dataset.name})

$("#progress").modal({ keyboard: false, focus: true, backdrop: "static" })
errored = false
await applyMod.applyMods(addMods, deleteMods, (phase, type, mod, err) ->
if phase is "done"
$button = $("button[data-path=\"#{mod.name}\"]")
switch type
when "add"
$button.addClass("applied")
p.addLog(mod.showname, langTable.MODAL_LOG_APPLIED)
when "delete"
$button.removeClass("applied")
p.addLog(mod.showname, langTable.MODAL_LOG_REMOVED)
else if phase is "fail"
$checkbox = $("button[data-path=\"#{mod.name}\"]").find("input")
errored = true
switch type
when "add"
p.addLog(mod.showname, langTable.MODAL_LOG_FAILED_APPLY+"(#{err})")
$checkbox.prop("checked", false)
when "delete"
p.addLog(mod.showname, langTable.MODAL_LOG_FAILED_REMOVE+"(#{err})")
$checkbox.prop("checked", true)
else
switch phase
when "download"
p.addLog(mod.showname, langTable.MODAL_LOG_DOWNLOAD_START)
when "downloaded"
p.addLog(mod.showname, langTable.MODAL_LOG_DOWNLOAD_FINISH)
when "copydir"
p.addLog(mod.showname, langTable.MODAL_LOG_COPY_START)
when "zipextract"
p.addLog(mod.showname, langTable.MODAL_LOG_EXTRACT_START)
when "zipextracted"
p.addLog(mod.showname, langTable.MODAL_LOG_EXTRACT_FINISH)
when "tempdone"
p.addLog(mod.showname, langTable.MODAL_LOG_TEMP_DONE)
when "zipcompress"
p.addLog(mod.showname, langTable.MODAL_LOG_COMPRESS_START)
when "zipcompressed"
p.addLog(mod.showname, langTable.MODAL_LOG_COMPRESS_FINISH)
return
)
if !errored
p.changePhase("done")
else
p.changePhase("failed")
# 閉じる防止解除
window.removeEventListener("beforeunload", onBeforeClose)
return
)
Loading

0 comments on commit e84b4cc

Please sign in to comment.