Add restart action to the settings dialog
This commit is contained in:
parent
0041c385bc
commit
eb13504648
|
@ -1,16 +1,40 @@
|
||||||
let angApp = require(__dirname+'/../init')
|
let angApp = require(__dirname+'/../init')
|
||||||
|
|
||||||
angApp.controller('SettingsController', function ($scope, AppStateService, SettingsService) {
|
angApp.controller('SettingsController', function ($scope, $rootScope, AppStateService, SettingsService) {
|
||||||
|
|
||||||
|
let formInitialized = false
|
||||||
|
$scope.settingsChanged = false
|
||||||
|
$scope.settingsSaved = false
|
||||||
|
|
||||||
|
const settingsSetPristine = () => {
|
||||||
|
$scope.settingsChanged = false
|
||||||
|
formInitialized = false
|
||||||
|
}
|
||||||
|
|
||||||
$scope.closeSettings = () => {
|
$scope.closeSettings = () => {
|
||||||
AppStateService.set(AppStateService.previousState)
|
$scope.settings = SettingsService.loadAll()
|
||||||
|
settingsSetPristine()
|
||||||
|
AppStateService.set(AppStateService.APP_STATE_DEFAULT)
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.saveSettings = () => {
|
$scope.saveSettings = () => {
|
||||||
|
$scope.settingsSaved = true
|
||||||
SettingsService.saveAll($scope.settings)
|
SettingsService.saveAll($scope.settings)
|
||||||
$scope.closeSettings()
|
settingsSetPristine()
|
||||||
|
}
|
||||||
|
|
||||||
|
$scope.restartApp = () => {
|
||||||
|
$rootScope.$broadcast('app:restart')
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.settings = SettingsService.loadAll()
|
$scope.settings = SettingsService.loadAll()
|
||||||
|
|
||||||
|
$scope.$watch("settings", () => {
|
||||||
|
if (!formInitialized) {
|
||||||
|
formInitialized = true
|
||||||
|
} else {
|
||||||
|
$scope.settingsChanged = true
|
||||||
|
}
|
||||||
|
}, true)
|
||||||
|
|
||||||
})
|
})
|
|
@ -14,8 +14,13 @@
|
||||||
</label>
|
</label>
|
||||||
<div class="form-item__hint">{{item.hint}}</div>
|
<div class="form-item__hint">{{item.hint}}</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-item" ng-show="settingsSaved">
|
||||||
|
<a href="#" ng-click="restartApp()" class="form-item__restart-app">
|
||||||
|
Click here to restart the app and apply your changes
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<button class="form-item__save-button" ng-click="saveSettings()">Save</button>
|
<button class="form-item__save-button" ng-class="{'active': settingsChanged == true}" ng-click="saveSettings()">Save</button>
|
||||||
<button class="form-item__cancel-button" ng-click="closeSettings()">Cancel</button>
|
<button class="form-item__cancel-button" ng-click="closeSettings()">Cancel</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
29
main.js
29
main.js
|
@ -1,5 +1,5 @@
|
||||||
// Modules to control application life and create native browser window
|
// Modules to control application life and create native browser window
|
||||||
const { app, BrowserWindow, shell } = require('electron')
|
const { app, BrowserWindow, ipcMain, shell } = require('electron')
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// Keep a global reference of the window object, if you don't, the window will
|
||||||
// be closed automatically when the JavaScript object is garbage collected.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
|
@ -80,16 +80,6 @@ function createWindow () {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle shutdown event on Mac with minimizeOnClose
|
|
||||||
// to prevent shutdown interrupt
|
|
||||||
if (isMac && minimizeOnClose) {
|
|
||||||
const { powerMonitor } = require('electron')
|
|
||||||
powerMonitor.on('shutdown', () => {
|
|
||||||
app.isQuitting = true
|
|
||||||
app.quit()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save window size
|
// Save window size
|
||||||
if (preserveWindowSize) {
|
if (preserveWindowSize) {
|
||||||
mainWindow.on('resize', (e) => {
|
mainWindow.on('resize', (e) => {
|
||||||
|
@ -112,6 +102,23 @@ function createWindow () {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle shutdown event on Mac with minimizeOnClose
|
||||||
|
// to prevent shutdown interrupt
|
||||||
|
if (isMac && minimizeOnClose) {
|
||||||
|
const { powerMonitor } = require('electron')
|
||||||
|
powerMonitor.on('shutdown', () => {
|
||||||
|
app.isQuitting = true
|
||||||
|
app.quit()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle restart
|
||||||
|
ipcMain.on('app-restart', (evt, arg) => {
|
||||||
|
app.isQuitting = true
|
||||||
|
app.relaunch()
|
||||||
|
app.exit()
|
||||||
|
})
|
||||||
|
|
||||||
// Emitted when the window is closed.
|
// Emitted when the window is closed.
|
||||||
mainWindow.on('closed', function () {
|
mainWindow.on('closed', function () {
|
||||||
// Dereference the window object, usually you would store windows
|
// Dereference the window object, usually you would store windows
|
||||||
|
|
|
@ -52,6 +52,10 @@ angApp.controller('AppController', function ($scope, $timeout, ChimeVerseService
|
||||||
}, 0)
|
}, 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$scope.$on('app:restart', (event, data) => {
|
||||||
|
ipcRenderer.send('app-restart')
|
||||||
|
})
|
||||||
|
|
||||||
SettingsService.initDefaults()
|
SettingsService.initDefaults()
|
||||||
|
|
||||||
ChimeVerseService.getCredentialsAndLogin()
|
ChimeVerseService.getCredentialsAndLogin()
|
||||||
|
|
|
@ -9,4 +9,8 @@
|
||||||
.form-item__hint {
|
.form-item__hint {
|
||||||
color: #777;
|
color: #777;
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-item__save-button.active {
|
||||||
|
color: blue;
|
||||||
}
|
}
|
Loading…
Reference in New Issue