Skip to content

Commit ebd6083

Browse files
committed
* Disallow installer version to use new setting
1 parent 1fa1cf3 commit ebd6083

File tree

8 files changed

+42
-39
lines changed

8 files changed

+42
-39
lines changed

_scripts/ebuilder.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,5 @@ export default {
9494
nsis: {
9595
allowToChangeInstallationDirectory: true,
9696
oneClick: false,
97-
include: '_scripts/ebuilder.nsis.installer.nsh',
9897
},
9998
}

_scripts/ebuilder.nsis.installer.nsh

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// IPC Channels
2+
23
const IpcChannels = {
34
ENABLE_PROXY: 'enable-proxy',
45
DISABLE_PROXY: 'disable-proxy',
@@ -46,7 +47,8 @@ const IpcChannels = {
4647
CHOOSE_DEFAULT_FOLDER: 'choose-default-folder',
4748
WRITE_TO_DEFAULT_FOLDER: 'write-to-default-folder',
4849

49-
GET_STORE_USER_DATA_IN_APP_FOLDER: 'get-store-user-data-in-app-folder',
50+
GET_STORE_USER_DATA_IN_APP_FOLDER_ALLOWED: 'get-store-user-data-in-app-folder-allowed',
51+
GET_STORE_USER_DATA_IN_APP_FOLDER_ENABLED: 'get-store-user-data-in-app-folder-enabled',
5052
TOGGLE_STORE_USER_DATA_IN_APP_FOLDER: 'toggle-store-user-data-in-app-folder',
5153
}
5254

src/datastores/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ if (process.env.IS_ELECTRON_MAIN) {
77
// this code only runs in the electron main process, so hopefully using sync fs code here should be fine 😬
88
const { statSync, realpathSync } = require('fs')
99

10-
const { getUserDataPath } = require('../main/userDataFolder')
11-
const userDataPath = getUserDataPath()
10+
const { USER_DATA_PATH } = require('../main/userDataFolder')
1211
dbPath = (dbName) => {
13-
let path = join(userDataPath, `${dbName}.db`)
12+
let path = join(USER_DATA_PATH, `${dbName}.db`)
1413

1514
// returns undefined if the path doesn't exist
1615
if (statSync(path, { throwIfNoEntry: false })?.isSymbolicLink) {

src/main/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ import contextMenu from 'electron-context-menu'
2727
import packageDetails from '../../package.json'
2828
import { generatePoToken } from './poTokenGenerator'
2929
import {
30-
getStoreUserDataInAppFolderEnabled,
31-
getUserDataPath,
30+
STORE_USER_DATA_IN_APP_FOLDER_ALLOWED,
31+
STORE_USER_DATA_IN_APP_FOLDER_ENABLED,
32+
USER_DATA_PATH,
3233
toggleStoreUserDataInAppFolderEnabledAndMigrateFiles,
3334
} from './userDataFolder'
3435

@@ -279,13 +280,10 @@ function runApp() {
279280
let mainWindow
280281
let startupUrl
281282

282-
const userDataPath = getUserDataPath()
283-
const storeUserDataInAppFolderEnabled = getStoreUserDataInAppFolderEnabled()
284-
285283
// command line switches need to be added before the app ready event first
286284
// that means we can't use the normal settings system as that is asynchronous,
287285
// doing it synchronously ensures that we add it before the event fires
288-
const REPLACE_HTTP_CACHE_PATH = `${userDataPath}/experiment-replace-http-cache`
286+
const REPLACE_HTTP_CACHE_PATH = `${USER_DATA_PATH}/experiment-replace-http-cache`
289287
const replaceHttpCache = existsSync(REPLACE_HTTP_CACHE_PATH)
290288
if (replaceHttpCache) {
291289
// the http cache causes excessive disk usage during video playback
@@ -1263,8 +1261,12 @@ function runApp() {
12631261
relaunch()
12641262
})
12651263

1266-
ipcMain.handle(IpcChannels.GET_STORE_USER_DATA_IN_APP_FOLDER, () => {
1267-
return storeUserDataInAppFolderEnabled
1264+
ipcMain.handle(IpcChannels.GET_STORE_USER_DATA_IN_APP_FOLDER_ALLOWED, () => {
1265+
return STORE_USER_DATA_IN_APP_FOLDER_ALLOWED
1266+
})
1267+
1268+
ipcMain.handle(IpcChannels.GET_STORE_USER_DATA_IN_APP_FOLDER_ENABLED, () => {
1269+
return STORE_USER_DATA_IN_APP_FOLDER_ENABLED
12681270
})
12691271

12701272
ipcMain.once(IpcChannels.TOGGLE_STORE_USER_DATA_IN_APP_FOLDER, async () => {

src/main/userDataFolder.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ const TO_BE_MIGRATED_FILES = [
2222
'subscription-cache.db',
2323
'experiment-replace-http-cache',
2424
]
25-
26-
export function getUserDataPath() {
27-
return getStoreUserDataInAppFolderEnabled() ? APP_FOLDER_USER_DATA_PATH : DEFAULT_USER_DATA_PATH
28-
}
29-
30-
export function getStoreUserDataInAppFolderEnabled() {
31-
return process.platform === 'win32' && existsSync(USER_DATA_IN_APP_FOLDER_SWITCH_FILE_PATH)
32-
}
25+
// Windows & NOT installer version & flag file exists
26+
export const STORE_USER_DATA_IN_APP_FOLDER_ALLOWED =
27+
process.platform === 'win32' &&
28+
!existsSync(path.join(path.dirname(process.execPath), 'Uninstall FreeTube.exe'))
29+
export const STORE_USER_DATA_IN_APP_FOLDER_ENABLED =
30+
STORE_USER_DATA_IN_APP_FOLDER_ALLOWED &&
31+
existsSync(USER_DATA_IN_APP_FOLDER_SWITCH_FILE_PATH)
32+
export const USER_DATA_PATH = STORE_USER_DATA_IN_APP_FOLDER_ENABLED ? APP_FOLDER_USER_DATA_PATH : DEFAULT_USER_DATA_PATH
3333

3434
export async function toggleStoreUserDataInAppFolderEnabledAndMigrateFiles() {
3535
// Migrate files first, only toggle setting when migration successful
36-
if (getStoreUserDataInAppFolderEnabled()) {
36+
if (STORE_USER_DATA_IN_APP_FOLDER_ENABLED) {
3737
await migrateFilesFromHereToThere(APP_FOLDER_USER_DATA_PATH, DEFAULT_USER_DATA_PATH)
3838
await asyncFs.rm(USER_DATA_IN_APP_FOLDER_SWITCH_FILE_PATH)
3939
} else {

src/preload/interface.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,15 @@ export default {
7373
/**
7474
* @returns {Promise<boolean>}
7575
*/
76-
getStoreUserDataInAppFolder: () => {
77-
return ipcRenderer.invoke(IpcChannels.GET_STORE_USER_DATA_IN_APP_FOLDER)
76+
getStoreUserDataInAppFolderAllowed: () => {
77+
return ipcRenderer.invoke(IpcChannels.GET_STORE_USER_DATA_IN_APP_FOLDER_ALLOWED)
78+
},
79+
80+
/**
81+
* @returns {Promise<boolean>}
82+
*/
83+
getStoreUserDataInAppFolderEnabled: () => {
84+
return ipcRenderer.invoke(IpcChannels.GET_STORE_USER_DATA_IN_APP_FOLDER_ENABLED)
7885
},
7986

8087
toggleStoreUserDataInAppFolder: () => {

src/renderer/components/ExperimentalSettings/ExperimentalSettings.vue

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
@change="handleReplaceHttpCacheChange"
1717
/>
1818
</FtFlexBox>
19-
<FtFlexBox v-if="storeUserDataInAppFolderAllowedOnPlatform">
19+
<FtFlexBox v-if="storeUserDataInAppFolderAllowed">
2020
<FtToggleSwitch
2121
tooltip-position="top"
2222
:label="$t('Settings.Experimental Settings.Store User Data In App Folder.Label')"
2323
compact
24-
:default-value="storeUserDataInAppFolder"
24+
:default-value="storeUserDataInAppFolderEnabled"
2525
:disabled="settingValuesLoading"
2626
:tooltip="$t('Settings.Experimental Settings.Store User Data In App Folder.Tooltip')"
2727
@change="handleStoreUserDataInAppFolderChange"
@@ -47,10 +47,10 @@ import FtPrompt from '../FtPrompt/FtPrompt.vue'
4747
4848
const settingValuesLoading = ref(true)
4949
const replaceHttpCache = ref(false)
50-
const storeUserDataInAppFolder = ref(false)
50+
const storeUserDataInAppFolderEnabled = ref(false)
5151
const showRestartPrompt = ref(false)
5252
53-
const storeUserDataInAppFolderAllowedOnPlatform = process.platform === 'win32'
53+
const storeUserDataInAppFolderAllowed = ref(false)
5454
5555
const NextActions = {
5656
// Simply use 1-N unique values
@@ -64,8 +64,9 @@ let nextAction = NextActions.NOTHING
6464
onMounted(async () => {
6565
if (process.env.IS_ELECTRON) {
6666
replaceHttpCache.value = await window.ftElectron.getReplaceHttpCache()
67-
if (storeUserDataInAppFolderAllowedOnPlatform) {
68-
storeUserDataInAppFolder.value = await window.ftElectron.getStoreUserDataInAppFolder()
67+
storeUserDataInAppFolderAllowed.value = await window.ftElectron.getStoreUserDataInAppFolderAllowed()
68+
if (storeUserDataInAppFolderAllowed.value) {
69+
storeUserDataInAppFolderEnabled.value = await window.ftElectron.getStoreUserDataInAppFolderEnabled()
6970
}
7071
}
7172
@@ -85,7 +86,7 @@ function handleReplaceHttpCacheChange(value) {
8586
* @param {boolean} value
8687
*/
8788
function handleStoreUserDataInAppFolderChange(value) {
88-
storeUserDataInAppFolder.value = value
89+
storeUserDataInAppFolderEnabled.value = value
8990
nextAction = NextActions.TOGGLE_STORE_USER_DATA_IN_APP_FOLDER
9091
showRestartPrompt.value = true
9192
}
@@ -110,7 +111,7 @@ function handleRestartPromptClick(value) {
110111
}
111112
case NextActions.TOGGLE_STORE_USER_DATA_IN_APP_FOLDER: {
112113
if (value === null || value === 'cancel') {
113-
storeUserDataInAppFolder.value = !storeUserDataInAppFolder.value
114+
storeUserDataInAppFolderEnabled.value = !storeUserDataInAppFolderEnabled.value
114115
return
115116
}
116117

0 commit comments

Comments
 (0)