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