提交 0cbc8172 编写于 作者: P peterq

fix pc: crash in mac

上级 2bd95865
......@@ -6,6 +6,7 @@ import (
"os"
"runtime"
"runtime/debug"
"syscall"
)
var Fatal = func(str string) {
......@@ -14,6 +15,7 @@ var Fatal = func(str string) {
}
var initCb []func()
var ExitCode = 0
func OnInit(cb func()) {
initCb = append(initCb, cb)
......@@ -32,18 +34,25 @@ func OnClose(cb func()) {
}
func DoClose() {
if closeCb == nil {
return
}
for _, cb := range closeCb {
cb()
}
closeCb = nil
if runtime.GOOS == "darwin" {
syscall.Kill(os.Getpid(), syscall.SIGKILL)
}
os.Exit(ExitCode)
}
func Reboot() {
if runtime.GOOS == "windows" {
ExitCode = 2
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
ioutil.WriteFile(DataPath("reboot"), []byte("true"), 0664)
}
DoClose()
os.Exit(2)
//os.Exit(2)
}
var NotifyQml = func(event string, data map[string]interface{}) {
......
......@@ -7,7 +7,6 @@ import (
"github.com/peterq/pan-light/pc/server-api"
"github.com/peterq/pan-light/pc/storage"
"log"
"os"
)
func init() {
......@@ -41,7 +40,7 @@ var baseSyncRoutes = map[string]syncHandler{
// 退出
"exit": func(p map[string]interface{}) (result interface{}) {
dep.DoClose()
os.Exit(0)
//os.Exit(0)
return
},
// config
......
......@@ -3,6 +3,7 @@
package gui
import (
"github.com/peterq/pan-light/pc/dep"
_ "github.com/peterq/pan-light/pc/functions"
_ "github.com/peterq/pan-light/pc/gui/bridge"
_ "github.com/peterq/pan-light/pc/gui/comp"
......@@ -11,6 +12,7 @@ import (
"github.com/peterq/pan-light/qt/bindings/gui"
"github.com/peterq/pan-light/qt/bindings/qml"
"github.com/peterq/pan-light/qt/bindings/quick"
"log"
"os"
)
......@@ -41,5 +43,9 @@ func StartGui() {
engine := qml.NewQQmlApplicationEngine(nil)
engine.Load(core.NewQUrl3("qrc:/main.qml", 0))
dep.OnClose(func() {
log.Println("will exit ui")
app.Exit(dep.ExitCode)
})
app.Exec()
}
import QtQuick 2.0
import "../comps"
Item {
id: root
property var tabWapper
property var tasbs: Object.keys(tasbsMap)
property var tasbsMap: {
"newest": '最新',
"hottest": '最热',
"official": '官方'
}
property string currentTab: 'newest'
onCurrentTabChanged: {
listRepeater.itemAt(tasbs.indexOf(currentTab)).active()
}
Connections {
target: tabWapper
onActive: {
listRepeater.itemAt(tasbs.indexOf(currentTab)).active()
}
}
DataSaver {
$key: 'page-explorer'
property alias showTip: tip.showTip
}
Column {
anchors.fill: parent
Rectangle {
id: tip
property string showTip: 'show'
visible: showTip === 'show'
color: '#409EFF'
width: parent.width
height: visible ? textTip.implicitHeight + 20 : 0
Text {
id: textTip
color: 'white'
width: parent.width - 40
anchors.centerIn: parent
wrapMode: Text.WrapAnywhere
text: '开放型的资源广场, 突破版权文件分享限制(被和谐的违规文件除外).实验性功能, 暂只支持分享大于256k的文件.'
}
IconButton {
iconType: 'close'
color: 'red'
anchors.right: parent.right
anchors.rightMargin: 10
anchors.verticalCenter: parent.verticalCenter
onClicked: {
tip.showTip = ''
}
}
}
Rectangle {
id: tabsBar
width: parent.width
height: 60
Rectangle {
width: parent.width
height: 1
color: '#ddd'
anchors.bottom: parent.bottom
}
Item {
id: typeTab
property int padding: 4
property int tabWidth: 80
width: tabWidth * tabs.length + 2 * padding
height: parent.height * 0.7
anchors.verticalCenter: parent.verticalCenter
x: 10
Rectangle {
anchors.fill: parent
radius: 3
color: '#eee'
}
Rectangle {
radius: 3
width: typeTab.tabWidth
height: typeTab.height - 2 * typeTab.padding
color: '#fff'
anchors.verticalCenter: parent.verticalCenter
x: typeTab.padding + root.tasbs.indexOf(
root.currentTab) * typeTab.tabWidth
Behavior on x {
PropertyAnimation {
duration: 400
easing.type: Easing.OutCubic
}
}
}
Repeater {
model: root.tasbs
delegate: Item {
width: typeTab.tabWidth
height: typeTab.height - 2 * typeTab.padding
anchors.verticalCenter: parent.verticalCenter
x: typeTab.padding + index * typeTab.tabWidth
Text {
text: root.tasbsMap[modelData]
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
root.currentTab = modelData
}
}
}
}
}
}
Repeater {
id: listRepeater
model: root.tasbs
ShareList {
id: shareList
type: modelData
height: parent.height - tip.height - tabsBar.height
width: parent.width
visible: root.currentTab == type
}
}
}
}
import QtQuick 2.4
import "../pan"
import "../transfer"
import "../explore"
import "../js/util.js" as Util
Item {
id: mainLayout
property var tabsUrl: {'我的网盘': 'pan', '传输列表': 'transfer', '探索': 'explore'}
property var tabsMap: {'我的网盘': pan, '传输列表': transfer, '探索': explore}
property var tabs: ['我的网盘', '传输列表', '探索']
property var colors: ['blue', 'red', 'green']
property string activeTab: '我的网盘'
......@@ -17,10 +20,7 @@ Item {
}
}
function notiActive() {
var idx = mainLayout.tabs.findIndex(function (tab) {
return tab === mainLayout.activeTab
})
tabRepeater.itemAt(idx).active()
tabsMap[mainLayout.activeTab].active()
}
onActiveTabChanged: {
notiActive()
......@@ -112,48 +112,34 @@ Item {
}
}
transform: Scale {
id: tabsConScale
property real scale: 1
xScale: scale
yScale: scale
origin.x: -tabsCon.x + tabsViewport.width / 2
// origin.x: tabsCon.width / 2
origin.y: parent.height /2
}
Repeater {
id: tabRepeater
model: tabs
Rectangle {
id: tabWapper
width: tabsViewport.width
height: tabsViewport.height
signal active
Pan {
id: pan
width: tabsViewport.width
height: tabsViewport.height
}
// color: mainLayout.colors[index]
Rectangle {
visible: false
property real borderWidth: 10
width: parent.width + 2 * borderWidth
height: parent.height + 2 * borderWidth
x: -borderWidth
y: -borderWidth
border.color: 'red'
border.width: borderWidth
}
Loader {
id: tabLoader
focus: true
width: tabWapper.width
height: tabWapper.height
Component.onCompleted: {
tabLoader.setSource('../' + tabsUrl[modelData] + '/' + tabsUrl[modelData] + '.qml', {tabWapper: tabWapper})
}
}
}
Transfer {
id: transfer
width: tabsViewport.width
height: tabsViewport.height
}
Explore {
id: explore
width: tabsViewport.width
height: tabsViewport.height
}
}
}
......
......@@ -18,8 +18,7 @@ Window {
minimumWidth: 900
title: "pan-light"
signal customerEvent(string event, var data)
flags: Qt.WA_TranslucentBackground | Qt.WA_TransparentForMouseEvents
| Qt.FramelessWindowHint | Qt.MSWindowsFixedSizeDialogHint
flags: Qt.FramelessWindowHint
color: 'transparent'
visibility: Window.Windowed
......
import QtQuick 2.0
import '../videoPlayer'
import '../js/app.js' as App
import '../js/util.js' as Util
import '../comps'
import './left-panel'
Rectangle {
id: root
// 左侧信息栏
LeftPanel {
id: leftPanel
height: parent.height
width: 250
// 右侧border
Rectangle {
color: 'gray'
width: 2
height: parent.height
anchors.right: parent.right
}
}
// 头部加列表
Rectangle {
anchors.left: leftPanel.right
width: root.width - leftPanel.width
height: parent.height
PathNav {
id: pathNav
width: parent.width
height: 40
// 下侧border
Rectangle {
color: 'gray'
width: parent.width
height: 2
anchors.bottom: parent.bottom
}
}
FileList {
width: parent.width
height: parent.height - pathNav.height
anchors.top: pathNav.bottom
color: "#fff"
Rectangle {
id: loading
anchors.fill: parent
visible: false
color: Qt.rgba(1,1,1,.6)
Component {
id: iconComp
IconFont {
type: 'loading'
width: Math.min(loading.width, loading.height) * 0.3
}
}
Loader {
id: iconLoader
focus: true
anchors.centerIn: parent
}
Component.onCompleted: {
// 监听进入path, 延时500ms显示加载动画
App.appState.enterPathPromiseChanged.connect(function() {
if (!App.appState.enterPathPromise) {
loading.visible = false
iconLoader.sourceComponent = null
return
}
var p = App.appState.enterPathPromise
Util.sleep(500)
.then(function(){
if (App.appState.enterPathPromise === p) {
iconLoader.sourceComponent = iconComp
loading.visible = true
}
})
})
}
}
LoadDirError{}
}
}
}
......@@ -12,9 +12,9 @@
<file>comps/desktop-widget_copy.qml</file>
<file>comps/bridge.qml</file>
<file>assets/images/pan-light-1.png</file>
<file>pan/pan.qml</file>
<file>explore/explore.qml</file>
<file>transfer/transfer.qml</file>
<file>pan/Pan.qml</file>
<file>explore/Explore.qml</file>
<file>transfer/Transfer.qml</file>
<file>login/Login.qml</file>
<file>comps/IconFont.qml</file>
<file>assets/images/icons/wx.svg</file>
......
import QtQuick 2.0
import "../js/app.js" as App
import "../js/util.js" as Util
Item {
id: root
signal sumSpeed(var data)
HeaderBar {
id: headerBar
}
Rectangle {
width: parent.width
height: 2
color: 'gray'
anchors.bottom: headerBar.bottom
}
DownloadList {
id: downloadingList
visible: headerBar.currentTab == '下载中'
isFinish: false
anchors.top: headerBar.bottom
width: parent.width
height: parent.height - headerBar.height
}
DownloadList {
id: downloadedList
visible: headerBar.currentTab == '已完成'
isFinish: true
anchors.top: headerBar.bottom
width: parent.width
height: parent.height - headerBar.height
}
Component.onCompleted: {
App.appState.transferComp = root
}
function addDownload(meta, useVip) {
return Util.Promise.resolve().then(function () {
var evt = {
"fid": meta.fs_id + '',
"exist": false
}
downloadingList.checkFid(evt)
if (evt.exist)
return Util.confirm()
return true
}).then(function () {
if (App.appState.settings.defaultDownloadPath)
return App.appState.settings.defaultDownloadPath
return Util.pickSavePath({
"fileName": meta.server_filename,
"defaultFolder": App.appState.settings.lastDownloadPath
})
}).then(function (savePath) {
savePath = savePath.toString()
var newFid = (useVip ? 'vip' : 'direct') + '.' + meta.fs_id
var id = Util.callGoSync('download.new', {
"fid": newFid,
"savePath": savePath
})
var obj = JSON.parse(JSON.stringify(meta))
obj.downloadId = id
var sep = Qt.platform.os == "windows" ? '\\' : '/'
var t = String.prototype.split.call(savePath, sep)
obj.newFid = newFid
obj.saveName = t.pop()
obj.savePath = savePath
obj.useVip = !!useVip
downloadingList.add(obj)
})
}
function addDownloadShare(md5, sliceMd5, fileSize, fileName) {
var fid = ['share', md5, sliceMd5, fileSize].join('.')
return Util.Promise.resolve().then(function () {
return Util.pickSavePath({
"fileName": fileName,
"defaultFolder": App.appState.settings.lastDownloadPath
})
}).then(function (savePath) {
var id = Util.callGoSync('download.new', {
"fid": fid,
"savePath": savePath
})
var obj = {
"size": fileSize,
"downloadId": id,
"newFid": fid,
"savePath": savePath,
"useVip": true,
"fileName": fileName,
"isShare": true
}
var sep = Qt.platform.os == "windows" ? '\\' : '/'
var t = String.prototype.split.call(savePath, sep)
obj.saveName = t.pop()
downloadingList.add(obj)
})
}
function deleteItem(idx, isFinish) {
var c = isFinish ? downloadedList : downloadingList
c.remove(idx)
}
function itemCompleted(idx) {
var data = JSON.parse(JSON.stringify(downloadingList.get(idx)))
downloadingList.remove(idx)
downloadedList.add(data)
}
}
......@@ -32,7 +32,7 @@ const startCmd = "pan_light_start"
func master() {
if runtime.GOOS == "windows" {
if runtime.GOOS != "linux" {
windosMaster()
return
}
......@@ -55,7 +55,8 @@ START_PAN:
}
}
}
log.Fatal(err)
log.Println(err)
os.Exit(0)
}
func windosMaster() {
......@@ -85,5 +86,6 @@ START_PAN:
if string(bin) == "true" {
goto START_PAN
}
log.Fatal(err)
log.Println(err)
os.Exit(0)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册