mirror of
https://github.com/kbumsik/VirtScreen.git
synced 2025-02-15 04:41:50 +00:00
Added: Saving auto-start
This commit is contained in:
parent
35b61fc74a
commit
807371a69c
3 changed files with 58 additions and 27 deletions
14
config.default.json
Normal file
14
config.default.json
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
{
|
||||||
|
"virt": {
|
||||||
|
"device": "VIRTUAL1",
|
||||||
|
"width": 1368,
|
||||||
|
"height": 1024,
|
||||||
|
"portrait": false,
|
||||||
|
"hidpi": false
|
||||||
|
},
|
||||||
|
"vnc": {
|
||||||
|
"port": 5900,
|
||||||
|
"autostart": false
|
||||||
|
},
|
||||||
|
"presets": []
|
||||||
|
}
|
55
main.qml
55
main.qml
|
@ -35,25 +35,30 @@ ApplicationWindow {
|
||||||
// virtscreen.py backend.
|
// virtscreen.py backend.
|
||||||
Backend {
|
Backend {
|
||||||
id: backend
|
id: backend
|
||||||
}
|
|
||||||
property bool vncAutoStart: false
|
function switchVNC () {
|
||||||
|
if ((backend.vncState == Backend.OFF) && backend.virtScreenCreated) {
|
||||||
|
backend.startVNC();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function switchVNC () {
|
onVncAutoStartChanged: {
|
||||||
if ((backend.vncState == Backend.OFF) && backend.virtScreenCreated) {
|
if (vncAutoStart) {
|
||||||
backend.startVNC();
|
onVirtScreenCreatedChanged.connect(switchVNC);
|
||||||
}
|
onVncStateChanged.connect(switchVNC);
|
||||||
}
|
} else {
|
||||||
|
onVirtScreenCreatedChanged.disconnect(switchVNC);
|
||||||
onVncAutoStartChanged: {
|
onVncStateChanged.disconnect(switchVNC);
|
||||||
if (vncAutoStart) {
|
}
|
||||||
backend.onVirtScreenCreatedChanged.connect(switchVNC);
|
}
|
||||||
backend.onVncStateChanged.connect(switchVNC);
|
|
||||||
} else {
|
Component.onCompleted: {
|
||||||
backend.onVirtScreenCreatedChanged.disconnect(switchVNC);
|
// force emit signal on load
|
||||||
backend.onVncStateChanged.disconnect(switchVNC);
|
vncAutoStart = vncAutoStart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Timer object and function
|
// Timer object and function
|
||||||
Timer {
|
Timer {
|
||||||
id: timer
|
id: timer
|
||||||
|
@ -247,7 +252,7 @@ ApplicationWindow {
|
||||||
// Material.accent: Material.Teal
|
// Material.accent: Material.Teal
|
||||||
// Material.theme: Material.Dark
|
// Material.theme: Material.Dark
|
||||||
|
|
||||||
enabled: window.vncAutoStart ? true :
|
enabled: backend.vncAutoStart ? true :
|
||||||
backend.vncState == Backend.OFF ? true : false
|
backend.vncState == Backend.OFF ? true : false
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
@ -262,12 +267,12 @@ ApplicationWindow {
|
||||||
if (backend.vncState == Backend.OFF) {
|
if (backend.vncState == Backend.OFF) {
|
||||||
console.log("Yes. Delete it");
|
console.log("Yes. Delete it");
|
||||||
backend.deleteVirtScreen();
|
backend.deleteVirtScreen();
|
||||||
window.vncAutoStart = true;
|
backend.vncAutoStart = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.vncAutoStart && (backend.vncState != Backend.OFF)) {
|
if (backend.vncAutoStart && (backend.vncState != Backend.OFF)) {
|
||||||
window.vncAutoStart = false;
|
backend.vncAutoStart = false;
|
||||||
backend.onVncStateChanged.connect(autoOff);
|
backend.onVncStateChanged.connect(autoOff);
|
||||||
backend.onVncStateChanged.connect(function() {
|
backend.onVncStateChanged.connect(function() {
|
||||||
backend.onVncStateChanged.disconnect(autoOff);
|
backend.onVncStateChanged.disconnect(autoOff);
|
||||||
|
@ -346,9 +351,9 @@ ApplicationWindow {
|
||||||
anchors.bottomMargin: 0
|
anchors.bottomMargin: 0
|
||||||
highlighted: true
|
highlighted: true
|
||||||
|
|
||||||
text: window.vncAutoStart ? "Auto start enabled" :
|
text: backend.vncAutoStart ? "Auto start enabled" :
|
||||||
backend.vncState == Backend.OFF ? "Start VNC Server" : "Stop VNC Server"
|
backend.vncState == Backend.OFF ? "Start VNC Server" : "Stop VNC Server"
|
||||||
enabled: window.vncAutoStart ? false :
|
enabled: backend.vncAutoStart ? false :
|
||||||
backend.virtScreenCreated ? true : false
|
backend.virtScreenCreated ? true : false
|
||||||
// Material.background: Material.Teal
|
// Material.background: Material.Teal
|
||||||
// Material.foreground: Material.Grey
|
// Material.foreground: Material.Grey
|
||||||
|
@ -362,13 +367,13 @@ ApplicationWindow {
|
||||||
|
|
||||||
Label { text: "Auto start"; }
|
Label { text: "Auto start"; }
|
||||||
Switch {
|
Switch {
|
||||||
checked: window.vncAutoStart
|
checked: backend.vncAutoStart
|
||||||
onCheckedChanged: {
|
onToggled: {
|
||||||
if ((checked == true) && (backend.vncState == Backend.OFF) &&
|
if ((checked == true) && (backend.vncState == Backend.OFF) &&
|
||||||
backend.virtScreenCreated) {
|
backend.virtScreenCreated) {
|
||||||
backend.startVNC();
|
backend.startVNC();
|
||||||
}
|
}
|
||||||
window.vncAutoStart = checked;
|
backend.vncAutoStart = checked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -441,8 +446,6 @@ ApplicationWindow {
|
||||||
Labs.MenuItem {
|
Labs.MenuItem {
|
||||||
text: qsTr("&Quit")
|
text: qsTr("&Quit")
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
backend.onVirtScreenCreatedChanged.disconnect(window.switchVNC);
|
|
||||||
backend.onVncStateChanged.disconnect(window.switchVNC);
|
|
||||||
backend.quitProgram();
|
backend.quitProgram();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -340,6 +340,7 @@ class Backend(QObject):
|
||||||
_vncPort: int
|
_vncPort: int
|
||||||
_vncPassword: str = ""
|
_vncPassword: str = ""
|
||||||
_vncState: int
|
_vncState: int
|
||||||
|
_vncAutoStart: bool
|
||||||
_ipAddresses: List[str] = []
|
_ipAddresses: List[str] = []
|
||||||
# Primary screen and mouse posistion
|
# Primary screen and mouse posistion
|
||||||
_primary: DisplayProperty()
|
_primary: DisplayProperty()
|
||||||
|
@ -358,6 +359,7 @@ class Backend(QObject):
|
||||||
onVirtScreenCreatedChanged = pyqtSignal(bool)
|
onVirtScreenCreatedChanged = pyqtSignal(bool)
|
||||||
onVirtScreenIndexChanged = pyqtSignal(int)
|
onVirtScreenIndexChanged = pyqtSignal(int)
|
||||||
onVncStateChanged = pyqtSignal(VNCState)
|
onVncStateChanged = pyqtSignal(VNCState)
|
||||||
|
onVncAutoStartChanged = pyqtSignal(bool)
|
||||||
onIPAddressesChanged = pyqtSignal()
|
onIPAddressesChanged = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
|
@ -371,6 +373,7 @@ class Backend(QObject):
|
||||||
self._portrait = self.settings['virt']['portrait']
|
self._portrait = self.settings['virt']['portrait']
|
||||||
self._hidpi = self.settings['virt']['hidpi']
|
self._hidpi = self.settings['virt']['hidpi']
|
||||||
self._vncPort = self.settings['vnc']['port']
|
self._vncPort = self.settings['vnc']['port']
|
||||||
|
self._vncAutoStart = self.settings['vnc']['autostart']
|
||||||
except (FileNotFoundError, json.JSONDecodeError, KeyError):
|
except (FileNotFoundError, json.JSONDecodeError, KeyError):
|
||||||
print("Default Setting used.")
|
print("Default Setting used.")
|
||||||
with open(DEFAULT_CONFIG_PATH, "r") as f:
|
with open(DEFAULT_CONFIG_PATH, "r") as f:
|
||||||
|
@ -380,6 +383,7 @@ class Backend(QObject):
|
||||||
self._portrait = self.settings['virt']['portrait']
|
self._portrait = self.settings['virt']['portrait']
|
||||||
self._hidpi = self.settings['virt']['hidpi']
|
self._hidpi = self.settings['virt']['hidpi']
|
||||||
self._vncPort = self.settings['vnc']['port']
|
self._vncPort = self.settings['vnc']['port']
|
||||||
|
self._vncAutoStart = self.settings['vnc']['autostart']
|
||||||
# create objects
|
# create objects
|
||||||
self._vncState: Backend.VNCState = Backend.VNCState.OFF
|
self._vncState: Backend.VNCState = Backend.VNCState.OFF
|
||||||
self.xrandr = XRandR()
|
self.xrandr = XRandR()
|
||||||
|
@ -417,7 +421,7 @@ class Backend(QObject):
|
||||||
def virtScreenCreated(self, value):
|
def virtScreenCreated(self, value):
|
||||||
self._virtScreenCreated = value
|
self._virtScreenCreated = value
|
||||||
self.onVirtScreenCreatedChanged.emit(value)
|
self.onVirtScreenCreatedChanged.emit(value)
|
||||||
|
|
||||||
@pyqtProperty(QQmlListProperty)
|
@pyqtProperty(QQmlListProperty)
|
||||||
def screens(self):
|
def screens(self):
|
||||||
return QQmlListProperty(DisplayProperty, self, self._screens)
|
return QQmlListProperty(DisplayProperty, self, self._screens)
|
||||||
|
@ -453,6 +457,14 @@ class Backend(QObject):
|
||||||
def vncState(self, state):
|
def vncState(self, state):
|
||||||
self._vncState = state
|
self._vncState = state
|
||||||
self.onVncStateChanged.emit(self._vncState)
|
self.onVncStateChanged.emit(self._vncState)
|
||||||
|
|
||||||
|
@pyqtProperty(bool, notify=onVncAutoStartChanged)
|
||||||
|
def vncAutoStart(self):
|
||||||
|
return self._vncAutoStart
|
||||||
|
@vncAutoStart.setter
|
||||||
|
def vncAutoStart(self, vncAutoStart):
|
||||||
|
self._vncAutoStart = vncAutoStart
|
||||||
|
self.onVncAutoStartChanged.emit(vncAutoStart)
|
||||||
|
|
||||||
@pyqtProperty('QStringList', notify=onIPAddressesChanged)
|
@pyqtProperty('QStringList', notify=onIPAddressesChanged)
|
||||||
def ipAddresses(self):
|
def ipAddresses(self):
|
||||||
|
@ -572,7 +584,9 @@ class Backend(QObject):
|
||||||
self.settings['virt']['portrait'] = self._portrait
|
self.settings['virt']['portrait'] = self._portrait
|
||||||
self.settings['virt']['hidpi'] = self._hidpi
|
self.settings['virt']['hidpi'] = self._hidpi
|
||||||
self.settings['vnc']['port'] = self._vncPort
|
self.settings['vnc']['port'] = self._vncPort
|
||||||
|
self.settings['vnc']['autostart'] = self._vncAutoStart
|
||||||
json.dump(self.settings, f, sort_keys=True, indent=4)
|
json.dump(self.settings, f, sort_keys=True, indent=4)
|
||||||
|
self.blockSignals(True) # This will prevent invoking auto-restart or etc.
|
||||||
QApplication.instance().quit()
|
QApplication.instance().quit()
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue