Skip to content

Commit

Permalink
Add quit app functionality for desktop.
Browse files Browse the repository at this point in the history
  • Loading branch information
UtkarshSiddhpura committed Aug 20, 2024
1 parent 00f812a commit 2f57265
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
8 changes: 7 additions & 1 deletion v2/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1020,8 +1020,14 @@ a {
.loginscreen_help, .firstscreen_help {
position: fixed;
top: 60px;
left: 30px;
left: 10%;
width: 80%;
margin-inline: auto;
}
.firstscreen_help {
display: flex;
justify-content: space-between;
}

/* listview */
.listview {
Expand Down
18 changes: 18 additions & 0 deletions v2/js/screens/firstscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ const FirstScreen = {
:color="256"
isNative="true"
></icon>
<icon
id="stop-icon"
v-if="isDesktop()"
svgfile="./lib/sugar-web/graphics/icons/actions/activity-stop.svg"
:size="50"
:x="0"
:y="0"
:color="512"
isNative="true"
@click="quitApp"
></icon>
</div>
<div class="firstscreen_login" v-show="showLoginScreen" >
<login-screen
Expand Down Expand Up @@ -146,6 +157,13 @@ const FirstScreen = {
},
setIsFirstScreen2(value) {
this.isFirstScreen = value;
},

isDesktop() {
return sugarizer.getClientPlatform() === sugarizer.constant.desktopAppType;
},
quitApp() {
sugarizer.quitApp();
}
}
}
Expand Down
17 changes: 13 additions & 4 deletions v2/js/screens/homescreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ const HomeScreen = {

setupBuddyPopup() {
this.popupIcon = this.$refs["buddyIcon"];
const itemList = [
{ icon: { id: 'preferences', iconData: "icons/preferences-system.svg", color: 256, size: this.constant.iconSizeFavorite }, name: this.$t("MySettings") },
{ icon: { id: 'shutdown', iconData: "icons/system-shutdown.svg", color: 256, size: this.constant.iconSizeFavorite, isNative: "true" }, name: this.$t("Logoff") },
];
if (sugarizer.getClientPlatform() === sugarizer.constant.desktopAppType)
itemList.push({ icon: { id: "quit", iconData: "./lib/sugar-web/graphics/icons/actions/activity-stop.svg", color: 256, size: this.constant.iconSizeFavorite, isNative: "true" }, name: this.$t("Quit") })
return {
id: "buddy",
directory: "icons",
Expand All @@ -352,10 +358,7 @@ const HomeScreen = {
},
name: this.username,
title: null,
itemList: [
{ icon: { id: 'preferences', iconData: "icons/preferences-system.svg", color: 256, size: this.constant.iconSizeFavorite }, name: this.$t("MySettings") },
{ icon: { id: 'shutdown', iconData: "icons/system-shutdown.svg", color: 256, size: this.constant.iconSizeFavorite, isNative: "true" }, name: this.$t("Logoff") },
],
itemList,
};
},

Expand Down Expand Up @@ -400,6 +403,8 @@ const HomeScreen = {
this.logout();
else
this.$refs.warningPrompt.show()
} else if (item == "buddy_quit") {
this.quitApp();
} else {
this.launchActivity(this.popup, item);
}
Expand Down Expand Up @@ -580,6 +585,10 @@ const HomeScreen = {
}
this.restrictedModeInfo.start = newStart;
this.restrictedModeInfo.activities = activities.slice(this.restrictedModeInfo.start, this.restrictedModeInfo.start + this.restrictedModeInfo.count - 2);
},

quitApp() {
sugarizer.quitApp();
}
},
};
Expand Down
18 changes: 18 additions & 0 deletions v2/js/sugarizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,22 @@ let sugarizer = {
});
this.modules.stats.clean(true);
},

// Quit Desktop app
quitApp: function () {
if (typeof chrome != 'undefined' && chrome.app && chrome.app.runtime) {
window.top.postMessage("", '*');
}
window.close();
if (!/Edge/.test(navigator.userAgent)) {
window.open('', '_self', ''); // HACK: Not allowed on all browsers
window.close();
}
if (navigator) {
if (navigator.app)
navigator.app.exitApp();
else if (navigator.device)
navigator.device.exitApp();
}
},
};

0 comments on commit 2f57265

Please sign in to comment.