Skip to content

Commit

Permalink
Add setting for disabling automatic file copy on directory move
Browse files Browse the repository at this point in the history
  • Loading branch information
MarmadileManteater committed Mar 4, 2024
1 parent 2ac1f56 commit e5c92ae
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,14 @@ class FreeTubeJavaScriptInterface {
context.wakeLock.release()
}

@JavascriptInterface
fun restart() {
context.finish()
context.startActivity(Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_LAUNCHER)
.setClass(context, MainActivity::class.java))
}

/**
* @return the id of a promise on the window
*/
Expand Down
43 changes: 29 additions & 14 deletions src/renderer/components/data-settings/data-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import { invidiousAPICall } from '../../helpers/api/invidious'
import { getLocalChannel } from '../../helpers/api/local'
import { handleAmbigiousContent, initalizeDatabasesInDirectory, readFile, requestDirectory, writeFile } from '../../helpers/android'
import android from 'android'

export default defineComponent({
name: 'DataSettings',
Expand All @@ -44,6 +45,7 @@ export default defineComponent({
],

shouldExportPlaylistForOlderVersions: false,
shouldCopyDataFilesWhenMoving: true
}
},
computed: {
Expand Down Expand Up @@ -98,12 +100,18 @@ export default defineComponent({
locationMap = locationInfo.files.map((file) => { return [file.fileName, file.uri] })
}
if (locationMap.length !== 0) {
for (const [key, value] of locationMap) {
writeFile('data://', key, readFile(value))
if (this.shouldCopyDataFilesWhenMoving) {
for (const [key, value] of locationMap) {
writeFile('data://', key, readFile(value))
}
}
// clear out data-location.json
writeFile('data://', 'data-location.json', '')
showToast(this.$t('Data Settings.Your data directory has been moved successfully'))
if (!this.shouldCopyDataFilesWhenMoving) {
// the application must restart in order to refresh the dbs
android.restart()
}
} else {
showToast(this.$t('Data Settings.Nothing to change'))
}
Expand All @@ -117,28 +125,35 @@ export default defineComponent({
const directory = await requestDirectory()
const files = await initalizeDatabasesInDirectory(directory)
if (files.length > 0) {
const locationData = readFile('data://', 'data-location.json')
let locationInfo = { directory: 'data://', files: [] }
let locationMap = {}
if (locationData !== '') {
locationInfo = JSON.parse(locationData)
locationMap = Object.fromEntries(locationInfo.files.map((file) => { return [file.fileName, file.uri] }))
}
for (let i = 0; i < files.length; i++) {
const data = locationInfo.files.length === 0
? readFile('data://', files[i].fileName)
: readFile(locationMap[files[i].fileName], '')
writeFile(files[i].uri, '', data)
if (this.shouldCopyDataFilesWhenMoving) {
const locationData = readFile('data://', 'data-location.json')
let locationInfo = { directory: 'data://', files: [] }
let locationMap = {}
if (locationData !== '') {
locationInfo = JSON.parse(locationData)
locationMap = Object.fromEntries(locationInfo.files.map((file) => { return [file.fileName, file.uri] }))
}
for (let i = 0; i < files.length; i++) {
const data = locationInfo.files.length === 0
? readFile('data://', files[i].fileName)
: readFile(locationMap[files[i].fileName], '')
writeFile(files[i].uri, '', data)
}
}
// update the data files
writeFile('data://', 'data-location.json', JSON.stringify({
directory: directory.uri,
files
}))
showToast(this.$t('Data Settings.Your data directory has been moved successfully'))
if (!this.shouldCopyDataFilesWhenMoving) {
// the application must restart in order to refresh the dbs
android.restart()
}
}
} catch (exception) {
showToast(this.$t('Data Settings.Error moving data directory'))
console.error(exception)
}
},

Expand Down
7 changes: 7 additions & 0 deletions src/renderer/components/data-settings/data-settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
:label="$t('Data Settings.Reset Data Directory')"
@click="resetDataDirectory"
/>
<ft-toggle-switch
:label="$t('Data Settings.Copy Data Files When Moving')"
:compact="true"
:default-value="shouldCopyDataFilesWhenMoving"
:tooltip="$t('Data Settings.Copy Data Files When Moving Tooltip')"
@change="shouldCopyDataFilesWhenMoving = !shouldCopyDataFilesWhenMoving"
/>
</ft-flex-box>
</template>
<h4 class="groupTitle">
Expand Down
2 changes: 2 additions & 0 deletions static/locales-android/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ Data Settings:
Your data directory has been moved successfully: Your data directory has been moved successfully
Error moving data directory: Error occured while moving data directory
Nothing to change: Nothing to change
Copy Data Files When Moving: Copy data files when moving directories
Copy Data Files When Moving Tooltip: This option overwrites the db files present in the directory you have selected with the current db files. Disabling this option will force the app to restart immediately after the directory has been moved.

0 comments on commit e5c92ae

Please sign in to comment.