Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
Squash all and push
Browse files Browse the repository at this point in the history
  • Loading branch information
likeadragonmaid committed May 23, 2021
0 parents commit c888e95
Show file tree
Hide file tree
Showing 22 changed files with 542 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# Final packages
RPMS/*

# Binaries are created in the project folder (Sailfish SDK doesn't support shadow building yet)
Switch-My-Slot

# Something Qt Creator generates
debugsources.list
documentation.list
debugfiles.list
debuglinks.list

# object files, makefiles, environment-specific Creator settings
*.o
Makefile
*.pro.user
*.pro.user.*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 - 2021 Shou

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Switch My Slot
Switch My Slot is a SailfishOS app that helps you switch between android system A & system B slots if you are dualbooting with Android OS on an Android A/B device. This app saves you from the hassle of needing to use ssh/terminal/twrp while wanting to switch to another Android slot.

Library used: [bootctl](https://android.googlesource.com/platform/system/extras/+/master/bootctl)

What is A/B partitioning?

https://source.android.com/devices/tech/ota/ab

https://www.xda-developers.com/how-a-b-partitions-and-seamless-updates-affect-custom-development-on-xda/

## Requirements
1. Device with A/B partitions
2. Android rom should be compiled along with bootctl module

[Checkout Android version](https://github.com/shoukolate/Switch-My-Slot-Android)

[Checkout Ubuntu Touch version](https://github.com/ubports-xiaomi-sdm660/Switch-My-Slot-Ubuntu-Touch)

<p align="center">
<img src="https://github.com/SailfishOS-MI-A2/Switch-My-Slot-SailfishOS/raw/master/Screenshots/1.png">
</p>
Binary file added Screenshots/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions Switch-My-Slot.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Desktop Entry]
Type=Application
X-Nemo-Application-Type=silica-qt5
Icon=Switch-My-Slot
Exec=Switch-My-Slot
Name=Switch My Slot
# translation example:
# your app name in German locale (de)
#
# Remember to comment out the following line, if you do not want to use
# a different app name in German locale (de).
Name[de]=Switch My Slot
40 changes: 40 additions & 0 deletions Switch-My-Slot.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# NOTICE:
#
# Application name defined in TARGET has a corresponding QML filename.
# If name defined in TARGET is changed, the following needs to be done
# to match new name:
# - corresponding QML filename must be changed
# - desktop icon filename must be changed
# - desktop filename must be changed
# - icon definition filename in desktop file must be changed
# - translation filenames have to be changed

# The name of your application
TARGET = Switch-My-Slot

CONFIG += sailfishapp

SOURCES += src/Switch-My-Slot.cpp

DISTFILES += qml/Switch-My-Slot.qml \
qml/cover/CoverPage.qml \
qml/pages/FirstPage.qml \
qml/pages/logic.py \
rpm/Switch-My-Slot.changes.in \
rpm/Switch-My-Slot.changes.run.in \
rpm/Switch-My-Slot.spec \
rpm/Switch-My-Slot.yaml \
translations/*.ts \
Switch-My-Slot.desktop

SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172

# to disable building translations every time, comment out the
# following CONFIG line
CONFIG += sailfishapp_i18n

# German translation is enabled as an example. If you aren't
# planning to localize your app, remember to comment out the
# following TRANSLATIONS line. And also do not forget to
# modify the localized app name in the the .desktop file.
TRANSLATIONS += translations/Switch-My-Slot-de.ts
Binary file added icons/108x108/Switch-My-Slot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/128x128/Switch-My-Slot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/172x172/Switch-My-Slot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/86x86/Switch-My-Slot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions qml/Switch-My-Slot.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import "pages"

ApplicationWindow
{
initialPage: Component { FirstPage { } }
cover: Qt.resolvedUrl("cover/CoverPage.qml")
}
10 changes: 10 additions & 0 deletions qml/cover/CoverPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import QtQuick 2.0
import Sailfish.Silica 1.0

CoverBackground {
Label {
id: label
anchors.centerIn: parent
text: qsTr("Switch My Slot")
}
}
116 changes: 116 additions & 0 deletions qml/pages/FirstPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import io.thp.pyotherside 1.5

Page {
id: page

SilicaFlickable {
anchors.fill: parent
contentHeight: column.height
Column {
id: column

width: page.width
spacing: Theme.paddingSmall
PageHeader {
title: qsTr("Switch My Slot")
}
Label {
id: halVersionLabel
x: Theme.horizontalPageMargin
text: qsTr("HAL Version: ")
color: Theme.secondaryHighlightColor
font.pixelSize: 45
}
Label {
text: qsTr("App Version: v0.3")
x: Theme.horizontalPageMargin
color: Theme.secondaryHighlightColor
}
Label {
id: noOfSlotsLabel
x: Theme.horizontalPageMargin
text: qsTr("Number of slots: ")
color: Theme.secondaryHighlightColor
}

Label {
id: currentSlotSuffixLabel
x: Theme.horizontalPageMargin
text: qsTr("Current slot suffix: ")
color: Theme.secondaryHighlightColor
}

Button {
id: switchSlotButton
x: Theme.horizontalPageMargin
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Switch slot")
color: Theme.secondaryHighlightColor
onClicked: {
python.switchSlotFunc();
}
}

Label {
id: currentSlotLabel
x: Theme.horizontalPageMargin
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Current slot: ")
color: Theme.secondaryHighlightColor
}
Label {
x: Theme.horizontalPageMargin
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Developed by Shou")
color: Theme.secondaryHighlightColor
font.pixelSize: 45
}
Label {
id: openRepo
x: Theme.horizontalPageMargin
anchors.horizontalCenter: parent.horizontalCenter
color: Theme.secondaryHighlightColor
font.pixelSize: 45
text: "<a href='https://github.com/SailfishOS-MI-A2/Switch-My-Slot-SailfishOS'>Licensed under MIT</a>"
onLinkActivated: Qt.openUrlExternally(link)
}

Python {
id: python

Component.onCompleted: {
addImportPath(Qt.resolvedUrl('.'));
setHandler('halVersion', function(halVersion) {
halVersionLabel.text = halVersion;
});
setHandler('noOfSlots', function(noOfSlots) {
noOfSlotsLabel.text = "Number of slots: " + noOfSlots;
});
setHandler('currentSlotSuffix', function(currentSlotSuffix) {
currentSlotSuffixLabel.text = "Current slot suffix: " + currentSlotSuffix;
});
setHandler('currentSlot', function(currentSlot) {
currentSlotLabel.text = "Current slot: " + currentSlot;
});
importModule('logic', function () {});
}

function switchSlotFunc() {
switchSlotButton.enabled = false
currentSlotLabel.text = "Please reboot/ turn off your phone now";
call('logic.switchSlotFunc', function() {});
}

onError: {
console.log('python error: ' + traceback);
}

onReceived: {
console.log('got message from python: ' + data);
}
}
}
}
}
29 changes: 29 additions & 0 deletions qml/pages/logic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pyotherside
import os

stream = os.popen('/bin/bootctl hal-info')
output = stream.read()
pyotherside.send('halVersion', output)

stream = os.popen('/bin/bootctl get-number-slots')
output = stream.read()
pyotherside.send('noOfSlots', output)

stream = os.popen('/bin/bootctl get-current-slot')
output = stream.read()
temp = output

if temp.__eq__(0):
pyotherside.send('currentSlot', "A")
elif s1.__eq__(1):
pyotherside.send('currentSlot', "B")

stream = os.popen('/bin/bootctl get-suffix ' + temp)
output = stream.read()
pyotherside.send('currentSlotSuffix', output)

def switchSlotFunc():
if temp.__eq__(0):
os.system("/bin/bootctl set-active-boot-slot " + "1")
elif temp.__eq__(1):
os.system("/bin/bootctl set-active-boot-slot " + "0")
18 changes: 18 additions & 0 deletions rpm/Switch-My-Slot.changes.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Rename this file as Switch-My-Slot.changes to include changelog
# entries in your RPM file.
#
# Add new changelog entries following the format below.
# Add newest entries to the top of the list.
# Separate entries from eachother with a blank line.
#
# Alternatively, if your changelog is automatically generated (e.g. with
# the git-change-log command provided with Sailfish OS SDK), create a
# Switch-My-Slot.changes.run script to let mb2 run the required commands for you.

# * date Author's Name <author's email> version-release
# - Summary of changes

* Sun Apr 13 2014 Jack Tar <jack.tar@example.com> 0.0.1-1
- Scrubbed the deck
- Hoisted the sails

25 changes: 25 additions & 0 deletions rpm/Switch-My-Slot.changes.run.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
#
# Rename this file as Switch-My-Slot.changes.run to let mb2 automatically
# generate changelog from well formatted Git commit messages and tag
# annotations.

git-change-log

# Here are some basic examples how to change from the default behavior. Run
# git-change-log --help inside the Sailfish OS SDK chroot or build engine to
# learn all the options git-change-log accepts.

# Use a subset of tags
#git-change-log --tags refs/tags/my-prefix/*

# Group entries by minor revision, suppress headlines for patch-level revisions
#git-change-log --dense '/[0-9]+.[0-9+$'

# Trim very old changes
#git-change-log --since 2014-04-01
#echo '[ Some changelog entries trimmed for brevity ]'

# Use the subjects (first lines) of tag annotations when no entry would be
# included for a revision otherwise
#git-change-log --auto-add-annotations
68 changes: 68 additions & 0 deletions rpm/Switch-My-Slot.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#
# Do NOT Edit the Auto-generated Part!
# Generated by: spectacle version 0.27
#

Name: Switch-My-Slot

# >> macros
# << macros

Summary: Switch My Slot
Version: 0.3
Release: 3
Group: Qt/Qt
License: MIT
URL: https://github.com/SailfishOS-MI-A2/Switch-My-Slot-SailfishOS
Source0: %{name}-%{version}.tar.bz2
Source100: Switch-My-Slot.yaml
Requires: sailfishsilica-qt5 >= 0.10.9
Requires: pyotherside-qml-plugin-python3-qt5
BuildRequires: pkgconfig(sailfishapp) >= 1.0.2
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(Qt5Quick)
BuildRequires: desktop-file-utils

%description
Switch My Slot is a SailfishOS app that helps you switch between android system A & system B slots if you are dualbooting with Android OS on an Android A/B device. This app saves you from the hassle of needing to use ssh/terminal/twrp while wanting to switch to another Android slot.


%prep
%setup -q -n %{name}-%{version}

# >> setup
# << setup

%build
# >> build pre
# << build pre

%qmake5

make %{?_smp_mflags}

# >> build post
# << build post

%install
rm -rf %{buildroot}
# >> install pre
# << install pre
%qmake5_install

# >> install post
# << install post

desktop-file-install --delete-original \
--dir %{buildroot}%{_datadir}/applications \
%{buildroot}%{_datadir}/applications/*.desktop

%files
%defattr(-,root,root,-)
%{_bindir}
%{_datadir}/%{name}
%{_datadir}/applications/%{name}.desktop
%{_datadir}/icons/hicolor/*/apps/%{name}.png
# >> files
# << files
Loading

0 comments on commit c888e95

Please sign in to comment.