Skip to content

Commit

Permalink
Improve autostart
Browse files Browse the repository at this point in the history
  • Loading branch information
hovancik committed May 9, 2024
1 parent e684682 commit 19b5bd2
Show file tree
Hide file tree
Showing 7 changed files with 341 additions and 297 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ jobs:
steps:
- name: run on mac
if: matrix.os == 'macos-14'
run: |
sudo xcode-select -s "/Applications/Xcode_15.4.app"
echo "==> Build environment"
xcode-select -p
xcrun --show-sdk-version
run: sudo xcode-select -s /Library/Developer/CommandLineTools
- name: Setup DBUS environment
if: matrix.os == 'ubuntu-latest'
run: |
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Estonia and Belarus translations
- Updated flag of Belarus to White-Red-White
- advanced option to show break options (Skip, Pause, Reset) in Strict mode
- add autostart option for Linux

### Changed
- updated many translations
Expand All @@ -20,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- multiple RTL UI issues
- RPM installer conflicts with other Electron apps
- improve break window loading to fix blank window
- autostart option for Windows Store

## [1.15.1] - 2023-11-19
### Fixed
Expand Down
27 changes: 13 additions & 14 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ const IdeasLoader = require('./utils/ideasLoader')
const BreaksPlanner = require('./breaksPlanner')
const AppIcon = require('./utils/appIcon')
const { UntilMorning } = require('./utils/untilMorning')
const AutostartManager = require('./utils/autostartManager')

Check warning on line 40 in app/main.js

View check run for this annotation

Codecov / codecov/patch

app/main.js#L40

Added line #L40 was not covered by tests
const Command = require('./utils/commands')

let microbreakIdeas
let breakIdeas
let breakPlanner
let appIcon = null
let autostartManager = null

Check warning on line 47 in app/main.js

View check run for this annotation

Codecov / codecov/patch

app/main.js#L47

Added line #L47 was not covered by tests
let processWin = null
let microbreakWins = null
let breakWins = null
Expand Down Expand Up @@ -223,6 +225,12 @@ function initialize (isAppStart = true) {
breakPlanner.nextBreak()
}

autostartManager = new AutostartManager({

Check warning on line 228 in app/main.js

View check run for this annotation

Codecov / codecov/patch

app/main.js#L228

Added line #L228 was not covered by tests
platform: process.platform,
windowsStore: process.windowsStore,
app
})

startI18next()
startProcessWin()
createWelcomeWindow()
Expand Down Expand Up @@ -1458,14 +1466,7 @@ ipcMain.on('save-setting', function (event, key, value) {
}

if (key === 'openAtLogin') {
if (process.platform === 'win32' && process.windowsStore) {
app.setLoginItemSettings({
openAtLogin: value,
path: 'start shell:appsFolder\\33881JanHovancik.stretchly_24fg4m0zq65je!Stretchly'
})
} else {
app.setLoginItemSettings({ openAtLogin: value })
}
autostartManager.autostartEnabled = value

Check warning on line 1469 in app/main.js

View check run for this annotation

Codecov / codecov/patch

app/main.js#L1469

Added line #L1469 was not covered by tests
} else {
settings.set(key, value)
}
Expand Down Expand Up @@ -1494,14 +1495,12 @@ ipcMain.on('restore-defaults', (event) => {
})
})

ipcMain.on('send-settings', function (event) {
event.sender.send('renderSettings', settingsToSend())
ipcMain.on('send-settings', async function (event) {
event.sender.send('renderSettings', await settingsToSend())

Check warning on line 1499 in app/main.js

View check run for this annotation

Codecov / codecov/patch

app/main.js#L1498-L1499

Added lines #L1498 - L1499 were not covered by tests
})

function settingsToSend () {
const loginItemSettings = app.getLoginItemSettings()
const openAtLogin = loginItemSettings.openAtLogin
return Object.assign({}, settings.store, { openAtLogin })
async function settingsToSend () {
return Object.assign({}, settings.store, { openAtLogin: await autostartManager.autoLaunchStatus() })

Check warning on line 1503 in app/main.js

View check run for this annotation

Codecov / codecov/patch

app/main.js#L1503

Added line #L1503 was not covered by tests
}

ipcMain.on('play-sound', function (event, sound) {
Expand Down
2 changes: 1 addition & 1 deletion app/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</a>
</nav>
<div class="settings">
<div class="linux-hidden store-hidden">
<div>
<input type="checkbox" value="openAtLogin" id="openAtLogin">
<label data-i18next="preferences.settings.openAtLogin" for="openAtLogin"></label>
</div>
Expand Down
70 changes: 70 additions & 0 deletions app/utils/autostartManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const log = require('electron-log/main')

Check warning on line 1 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L1

Added line #L1 was not covered by tests

class AutostartManager {
constructor ({
platform,
windowsStore,
app
}) {
this.platform = platform
this.windowsStore = windowsStore
this.app = app

Check warning on line 11 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L9-L11

Added lines #L9 - L11 were not covered by tests
}

get autostartEnabled () {
if (this.platform === 'win32') {
if (this.windowsStore) {
return false

Check warning on line 17 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L15-L17

Added lines #L15 - L17 were not covered by tests
} else {
return true

Check warning on line 19 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L19

Added line #L19 was not covered by tests
}
} else if (this.platform === 'darwin') {
return true
} else if (this.platform === 'linux') {
return this.autoLaunchStatus()

Check warning on line 24 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L21-L24

Added lines #L21 - L24 were not covered by tests
} else {
return false

Check warning on line 26 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L26

Added line #L26 was not covered by tests
}
}

set autostartEnabled (value) {
if (this.platform === 'linux') {
value ? this._linuxAutoLaunch.enable() : this._linuxAutoLaunch.disable()
} else if (process.platform === 'win32' && process.windowsStore) {
value ? this._windowsStoreAutoLaunch.enable() : this._windowsStoreAutoLaunch.disable()

Check warning on line 34 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L31-L34

Added lines #L31 - L34 were not covered by tests
} else {
this.app.setLoginItemSettings({ openAtLogin: value })

Check warning on line 36 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L36

Added line #L36 was not covered by tests
}
log.info(`Stretchly: setting autostart to ${value} on ${this.platform}${this.platform === 'win32' && this.windowsStore ? ' (Windows Store)' : ''}`)

Check warning on line 38 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L38

Added line #L38 was not covered by tests
}

async autoLaunchStatus () {
if (this.platform === 'linux') {
return await this._linuxAutoLaunch.isEnabled()
} else if (this.platform === 'win32' && this.windowsStore) {
return await this._windowsStoreAutoLaunch.isEnabled()

Check warning on line 45 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L42-L45

Added lines #L42 - L45 were not covered by tests
} else {
return Promise.resolve(this.app.getLoginItemSettings().openAtLogin)

Check warning on line 47 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L47

Added line #L47 was not covered by tests
}
}

get _linuxAutoLaunch () {
const AutoLaunch = require('auto-launch')
const stretchlyAutoLaunch = new AutoLaunch({

Check warning on line 53 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L52-L53

Added lines #L52 - L53 were not covered by tests
name: 'stretchly'
})
return stretchlyAutoLaunch

Check warning on line 56 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L56

Added line #L56 was not covered by tests
}

get _windowsStoreAutoLaunch () {
const AutoLaunch = require('auto-launch')
const stretchlyAutoLaunch = new AutoLaunch({

Check warning on line 61 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L60-L61

Added lines #L60 - L61 were not covered by tests
name: 'Stretchly',
path: '33881JanHovancik.stretchly_24fg4m0zq65je!Stretchly',
isHidden: true
})
return stretchlyAutoLaunch

Check warning on line 66 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L66

Added line #L66 was not covered by tests
}
}

module.exports = AutostartManager

Check warning on line 70 in app/utils/autostartManager.js

View check run for this annotation

Codecov / codecov/patch

app/utils/autostartManager.js#L70

Added line #L70 was not covered by tests
Loading

0 comments on commit 19b5bd2

Please sign in to comment.