Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings Sync #2684

Open
1208nn opened this issue May 2, 2024 · 20 comments
Open

Settings Sync #2684

1208nn opened this issue May 2, 2024 · 20 comments
Labels
enhancement New feature or request keep-fresh

Comments

@1208nn
Copy link

1208nn commented May 2, 2024

Setting up sync is a good feature to use Flow between devices, which make our experience better.

If flowlaunchher has no plans to create an account system or buy a server, syncing through OneDrive, GoogleDrive, WebDav is also acceptable and a good solution. For example, tampermonkey, violentmonkey use these methods.

I think we can sync the settings folder, themes folder, and a list of plugins.
It's a ok to sync like vscode, only a json file with the list of plugins.

@1208nn 1208nn added the enhancement New feature or request label May 2, 2024
@Garulf
Copy link
Member

Garulf commented May 2, 2024

Flow Launcher can be used in portable mode allowing the use of cloud drives, git, syncthing, etc.

@1208nn
Copy link
Author

1208nn commented May 3, 2024

It's true but it really costs my space and time. Sync the whole app in cloud might have some problem for too many files.

Flowlauncher was packed with runtime. Can they be deleted if I installed .net?

I think just sync a folder wasn't difficult. In C#,we can use Microsoft.Graph.

This is an example (bad code):

using Microsoft.Graph;
using Microsoft.Identity.Client;
using System;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace OneDriveAppFolderExample{
    class Program{
        private static GraphServiceClient graphClient;
        private static string clientId = "*#*#*#*#*";
        private static string[] scopes = new string[] { "Files.ReadWrite.AppFolder" };

        static async Task Main(string[] args){
            var authProvider = new InteractiveAuthenticationProvider(clientId, scopes);
            graphClient = new GraphServiceClient(authProvider);
            var appFolder = await CreateAppFolder();
            await UploadFileToAppFolder(appFolder, @"UserData/settings");
            //This need keep flow's working directory not change
            //In file search plugin, if user use the position of the executable file as the working directory, it will not work. We need not change the working directory of the main process.
        }

        private static async Task<DriveItem> CreateAppFolder(){
            try{
                var appFolder = await graphClient.Me.Drive.Special.AppRoot
                    .Request()
                    .GetAsync();

                return appFolder;
            }
            catch (ServiceException ex){
                if (ex.StatusCode == System.Net.HttpStatusCode.NotFound){
                    var folderToCreate = new DriveItem{
                        Name = "Flow.Launcher",
                        Folder = new Folder()
                    };

                    var appFolder = await graphClient.Me.Drive.Special.AppRoot
                        .Children
                        .Request()
                        .AddAsync(folderToCreate);

                    return appFolder;
                }
                else{
                    throw;
                }
            }
        }

        private static async Task UploadFileToAppFolder(DriveItem appFolder, string localFilePath){
            using (var fileStream = System.IO.File.OpenRead(localFilePath)){
                var uploadedFile = await graphClient.Me.Drive.Items[appFolder.Id]
                    .ItemWithPath(System.IO.Path.GetFileName(localFilePath))
                    .Content
                    .Request()
                    .PutAsync<DriveItem>(fileStream);

                Console.WriteLine("Uploaded file ID: " + uploadedFile.Id);
            }
        }
    }

    public class InteractiveAuthenticationProvider : IAuthenticationProvider    {
        private IPublicClientApplication _msalClient;
        private string[] _scopes;

        public InteractiveAuthenticationProvider(string clientId, string[] scopes){
            _msalClient = PublicClientApplicationBuilder.Create(clientId).Build();
            _scopes = scopes;
        }

        public async Task AuthenticateRequestAsync(HttpRequestMessage request){
            var authResult = await _msalClient.AcquireTokenInteractive(_scopes).ExecuteAsync();
            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authResult.AccessToken);
        }
    }
}

@onesounds
Copy link
Contributor

We want to create this feature, but we don't have anyone to work on it now.
(Sadly, The simple setting backup/restore feature too.)

If you know how to write code, please make a PR.

@jjw24
Copy link
Member

jjw24 commented Jul 3, 2024

We definitely won't be hosting this solution ourselves. It will have to be a third-party solution but everyone's got their own preferred sync platform, e.g. OneDrive, GoogleDrive or etc.

Maybe should consider allowing the UserData folder be relocated to a separate location so only that folder gets synced, and user data is also loaded from the new location.

@DRYN07
Copy link

DRYN07 commented Jul 30, 2024

The aText program uses two quite good solutions:

  • Sync folder → makes a daily backup to a selected folder → similarly, if this backup is updated due to aText from another machine, it loads it immediately.

  • Simple daily backup → creates a daily backup in a folder (max 100 items), from which it can be easily imported if needed. For me, this second solution would also be suitable, it doesn't have to be completely automatic, but at least such a "semi-automatic" solution would be great, I think.

@taooceros
Copy link
Member

The problem with that is how to handle a conflict if modified by both side?

This comment has been minimized.

@github-actions github-actions bot added the Stale label Sep 29, 2024
@jjw24 jjw24 removed the Stale label Sep 30, 2024

This comment has been minimized.

@github-actions github-actions bot added the Stale label Nov 30, 2024
@EnigmaSolved
Copy link

@Garulf (or anyone), if I use Everything Search on each local machine for powering the search indexes, and switched over to running Flow in portable mode, located on Microsoft OneDrive, is there anything that could go wrong, any downsides? I should add I frequently Remote Desktop into the other machines, so I could easily be activating Flow on my local machine and a few moments later be activating Flow on a remote machine, and all of these would be the same Flow (if I were to do the portable mode on OneDrive). I'm in the midst of setting up a third machine, so am just thinking about this (and the desire for Settings Sync) as I am about to install and configure Flow again.

@github-actions github-actions bot removed the Stale label Dec 2, 2024
@1208nn
Copy link
Author

1208nn commented Dec 6, 2024

I place them in onedrive, too.

It works fine if in the same directory, different directory isn't tested.

@EnigmaSolved
Copy link

I place them in onedrive, too.

It works fine if in the same directory, different directory isn't tested.

Thanks much for the reply! Pardon me for being obtuse, but what would be a "different directory" vs "same directory" example? I would probably do something like OneDrive>Apps>FlowLauncher and then each computer would be using that Flow. This is obviously a different directory than the normal install path, but I think you must mean something else. Just want to be sure I'm understand the parameters/constraints. :)

@1208nn
Copy link
Author

1208nn commented Dec 7, 2024

As for me:

PC A: Win10 LTSC19 D:\OneDrive\

PC B: Win11 24H2 D:\OneDrive\

PC C: Win10 23H2 C:\Users\1208nn\OneDrive\

A & B works well.

C is not tested.

@EnigmaSolved
Copy link

Ah, I understand! Yes, I will be doing something like C:\Users\Me\OneDrive\Software\Flow\ and using the same path on all machines, which in theory should work fine (based on what you've shared).

@EnigmaSolved
Copy link

How do you avoid getting your settings overwritten by the various installations? I'm under the impression that Flow saves various user settings when it exits (I notice this when I am manually editing a settings file), so I would think that if you changed a setting via Flow on Computer A, and then go to Computer B (already on and running Flow) and shutdown Computer B, that Computer B's Flow will save its settings when it closes, overwriting the shared settings between the two (on OneDrive). Does that not happen for you and/or how do you mitigate this?

I Remote Desktop regularly into the computers that will all be sharing the same Flow portable installation, so I'm just trying to think through how this will work. I just posted #3113 as one route I am looking into.

@EnigmaSolved
Copy link

@1208nn, how do you handle the Program plugin when using portable Flow across multiple computers (since the data is specific to each machine), or do you just not use that plugin? Is there a command line way to tell that plugin to Reindex (because if so, I could script that for each time I login to a given computer)?

@EnigmaSolved
Copy link

Sharing just for the sake of others who may attempt this in the future: I have ended up writing a little script that runs when I unlock my computer and which deletes UWP.cache and Win32.cache before reloading Flow, which then results in Flow reindexing Programs for the local machine (to rebuild those caches).

It is a bit of a clunky solution, but it works -- now when I unlock each computer it runs this script and thus searching for Programs in Flow gives me local results. I suspect this method/approach is not foolproof and that I'll still run into some instances of not getting the results I'm looking for, but it is an improvement over what was happening previously.

@1208nn
Copy link
Author

1208nn commented Dec 13, 2024

I'm sorry. In fact I use my computers mostly not at the same time.

For programs, there is few difference on my two computers(they are just for different places to use), and .exe files are indexed by Everything(settings is in OneDrive and database is in %PROGRAMDATA%), so it's enough.

@EnigmaSolved
Copy link

Ah sure. Well, at the very least, hopefully our conversation here will be useful to future people considering going the portable syncing route, as well as be informative for whenever true settings sync support is added.

This comment has been minimized.

@github-actions github-actions bot added the Stale label Feb 13, 2025
@jjw24 jjw24 added keep-fresh and removed Stale labels Feb 14, 2025
@tho-myr
Copy link

tho-myr commented Mar 2, 2025

i would love to see that feature :)

maybe similar to home assistant where you can setup regular backups of settings to different cloud/local storages and then import those settings if you are setting up flow launcher on another pc would be a first step towards actually syncing settings.

a full automatic sync would also be nice to have

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request keep-fresh
Projects
None yet
Development

No branches or pull requests

8 participants